问题描述
用于检索数据的逻辑
public IQueryable< visitordm> GetCheckInVisitorList(int cityId,int page)
{
// DateTime todayDate = DateTime.Today;
using(VMSDBContext context = DAL.Instance .NewDefaultDbContext())
{
var lstVistorDetails =(来自上下文中的objVisitors.Visitors
加入objVisits in context.Visits on objVisitors.ID equals objVisits.Visitor_id
加入objVisitorLocation in context.VisitorLocations on objVisits.Visitor_location_id equals objVisitorLocation.ID
join objEmployee in context.Employees on objVisits.Employee_to_visit equals objEmployee.ID
在上下文中加入objprogram.obr上的objEmployee.Program_id等于objprogram.ID
在context.IdentificationProofs中加入objIdProof on objVisits.Identification_proof_id等于objIdProof.ID
在context.Locations.Where中加入objLocation(objlocations => Objlocations.City_id == cityId)on objVisits.Location_id等于objLocation.ID
加入objVisitorPurpose in context.VisitPurposes on objVisits.Visit_purpose_id equals objVisitorPurpose.ID
where(objVisits.Office_out_time == null)
//&& objVisits.Office_in_time.Value.Day == todayDate.Day
//&& objVisits.Office_in_time.Value.Month == todayDate.Month
//&& objVisits.Office_in_time.Value.Year == todayDate.Year)
orderby objVisits.ID降序
选择新的VisitorDM
{
Visit_id = objVisits.ID,
Name = objVisitors.Name,
Mobile_number = objVisitors.Mobile_number,
Visitor_location = objVisitorLocation。姓名,
EmployeeName_to_visit = objEmployee.First_name ++ objEmployee.Last_name +(+ objEmployee.Employee_code +),
IdProof = objIdProof.ID_proof,
OfficeLocation = objLocation.Name,
VisitorPurpose = objVisitorPurpose.Name,
Office_in_time = objVisits.Office_in_time,
Office_in_entry_by = objVisits.Office_in_entry_by,
Office_in_system_name = objVisits.Office_in_system_name,
Office_out_time = objVisits.Office_out_time,
Office_out_entry_by = objVisits.Office_out_entry_by,
Office_out_system_name = objVisits.Office_out_system_name,
Modified_on = objVisits.Modified_on,
Modified_by = objVisits.Office_in_system_name,
ID = objVisitors.ID
}。ToList()。AsQueryable();
返回lstVistorDetails;
}
}
在另一个函数中调用此函数
Logic used to retrieve a data
public IQueryable<visitordm> GetCheckInVisitorList(int cityId, int page)
{
// DateTime todayDate = DateTime.Today;
using (VMSDBContext context = DAL.Instance.NewDefaultDbContext())
{
var lstVistorDetails = (from objVisitors in context.Visitors
join objVisits in context.Visits on objVisitors.ID equals objVisits.Visitor_id
join objVisitorLocation in context.VisitorLocations on objVisits.Visitor_location_id equals objVisitorLocation.ID
join objEmployee in context.Employees on objVisits.Employee_to_visit equals objEmployee.ID
join objprogram in context.Programs on objEmployee.Program_id equals objprogram.ID
join objIdProof in context.IdentificationProofs on objVisits.Identification_proof_id equals objIdProof.ID
join objLocation in context.Locations.Where(objlocations => objlocations.City_id == cityId) on objVisits.Location_id equals objLocation.ID
join objVisitorPurpose in context.VisitPurposes on objVisits.Visit_purpose_id equals objVisitorPurpose.ID
where (objVisits.Office_out_time == null)
// && objVisits.Office_in_time.Value.Day == todayDate.Day
// && objVisits.Office_in_time.Value.Month == todayDate.Month
// && objVisits.Office_in_time.Value.Year == todayDate.Year)
orderby objVisits.ID descending
select new VisitorDM
{
Visit_id = objVisits.ID,
Name = objVisitors.Name,
Mobile_number = objVisitors.Mobile_number,
Visitor_location = objVisitorLocation.Name,
EmployeeName_to_visit = objEmployee.First_name + " " + objEmployee.Last_name + "(" + objEmployee.Employee_code + ")",
IdProof = objIdProof.ID_proof,
OfficeLocation = objLocation.Name,
VisitorPurpose = objVisitorPurpose.Name,
Office_in_time = objVisits.Office_in_time,
Office_in_entry_by = objVisits.Office_in_entry_by,
Office_in_system_name = objVisits.Office_in_system_name,
Office_out_time = objVisits.Office_out_time,
Office_out_entry_by = objVisits.Office_out_entry_by,
Office_out_system_name = objVisits.Office_out_system_name,
Modified_on = objVisits.Modified_on,
Modified_by = objVisits.Office_in_system_name,
ID = objVisitors.ID
}).ToList().AsQueryable();
return lstVistorDetails;
}
}
Calls this function in another function
public IQueryable<VisitorDM> GetTypeVisitorDetails(string searchText, string searchType, int cityId, int page, [Optional] string columnName, [Optional]string sortType)
{
List<VisitorDM> lstVistorDetails = new List<VisitorDM>();
using (VMSDBContext context = DAL.Instance.NewDefaultDbContext())
{
if (!string.IsNullOrEmpty(columnName) && !string.IsNullOrEmpty(sortType))
{
switch (columnName)
{
case "Visit Id":
IEnumerable<VisitorDM> CheckInVisitID = (sortType == "ASC" ?
GetCheckInVisitorList(cityId, page).OrderBy(objCheckInlist => objCheckInlist.Visit_id) :
GetCheckInVisitorList(cityId, page).OrderByDescending(objCheckInlist => objCheckInlist.Visit_id));
lstVistorDetails = CheckInVisitID.ToList();
break;
case "Office Location":
IEnumerable<VisitorDM> CheckInOfficeLocation = (sortType == "ASC" ?
GetCheckInVisitorList(cityId, page).OrderBy(objCheckInlist => objCheckInlist.OfficeLocation) :
GetCheckInVisitorList(cityId, page).OrderByDescending(objCheckInlist => objCheckInlist.OfficeLocation));
lstVistorDetails = CheckInOfficeLocation.ToList();
break;
case "Visitor Name":
IEnumerable<VisitorDM> CheckInVisitorName = (sortType == "ASC" ?
GetCheckInVisitorList(cityId, page).OrderBy(objCheckInlist => objCheckInlist.Name) :
GetCheckInVisitorList(cityId, page).OrderByDescending(objCheckInlist => objCheckInlist.Name));
lstVistorDetails = CheckInVisitorName.ToList();
break;
case "Visitor Mobile Number":
IEnumerable<VisitorDM> CheckInVisitorMobileNumber = (sortType == "ASC" ?
GetCheckInVisitorList(cityId, page).OrderBy(objCheckInlist => objCheckInlist.Mobile_number) :
GetCheckInVisitorList(cityId, page).OrderByDescending(objCheckInlist => objCheckInlist.Mobile_number));
lstVistorDetails = CheckInVisitorMobileNumber.ToList();
break;
case "Person To Meet":
IEnumerable<VisitorDM> CheckInPersonToMeet = (sortType == "ASC" ?
GetCheckInVisitorList(cityId, page).OrderBy(objCheckInlist => objCheckInlist.EmployeeName_to_visit) :
GetCheckInVisitorList(cityId, page).OrderByDescending(objCheckInlist => objCheckInlist.EmployeeName_to_visit));
lstVistorDetails = CheckInPersonToMeet.ToList();
break;
case "In Time":
IEnumerable<VisitorDM> CheckInInTime = (sortType == "ASC" ?
GetCheckInVisitorList(cityId, page).OrderBy(objCheckInlist => objCheckInlist.EmployeeName_to_visit) :
GetCheckInVisitorList(cityId, page).OrderByDescending(objCheckInlist => objCheckInlist.EmployeeName_to_visit));
lstVistorDetails = CheckInInTime.ToList();
break;
}
}
else
{
if (Convert.ToString(VisitorListType.CurrentCheckInVisitor) == searchType)
{
IEnumerable<VisitorDM> CheckInVisitorList = GetCheckInVisitorList(cityId, page).Where(
objCheckInlist =>
(!string.IsNullOrEmpty(searchText) ? objCheckInlist.Mobile_number.Contains(searchText) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.Name.ToLower().Contains(searchText.ToLower()) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.EmployeeName_to_visit.ToLower().Contains(searchText.ToLower()) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.OfficeLocation.ToLower().Contains(searchText.ToLower()) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.Visit_id.ToString().Contains(searchText) : true)
);
lstVistorDetails = CheckInVisitorList.ToList();
}
}
if (!string.IsNullOrEmpty(columnName) && !string.IsNullOrEmpty(sortType))
{
}
else
{
if (Convert.ToString(VisitorListType.TodayAllInVisitor) == searchType)
{
IEnumerable<VisitorDM> TodayVisitorList = GetTodayVisitorList(cityId, page).Where(
objCheckInlist =>
(!string.IsNullOrEmpty(searchText) ? objCheckInlist.Mobile_number.Contains(searchText) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.Name.ToLower().Contains(searchText.ToLower()) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.EmployeeName_to_visit.ToLower().Contains(searchText.ToLower()) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.OfficeLocation.ToLower().Contains(searchText.ToLower()) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.Visit_id.ToString().Contains(searchText) : true)
);
lstVistorDetails = TodayVisitorList.ToList();
}
}
if (!string.IsNullOrEmpty(columnName) && !string.IsNullOrEmpty(sortType))
{
}
else
{
if (Convert.ToString(VisitorListType.VisitorHistory) == searchType)
{
IEnumerable<VisitorDM> AllVisitorHistoryList = GetVisitorHistoryList(cityId, page).Where(
objCheckInlist =>
(!string.IsNullOrEmpty(searchText) ? objCheckInlist.Mobile_number.ToLower().Contains(searchText.ToLower()) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.Name.ToLower().Contains(searchText.ToLower()) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.EmployeeName_to_visit.ToLower().Contains(searchText.ToLower()) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.OfficeLocation.ToLower().Contains(searchText.ToLower()) : true)
|| (!string.IsNullOrEmpty(searchText) ? objCheckInlist.Visit_id.ToString().Contains(searchText) : true)
);
lstVistorDetails = AllVisitorHistoryList.ToList<VisitorDM>();
}
}
}
return lstVistorDetails.ToList().AsQueryable();
}
另一个函数的调用
public VisitorListVM GetAllTypeVisitorDetails(string searchText,string searchType,int cityId,int page,int UserId,[Optional] string columnName,[Optional] string sortType)
{
UserBL userBL = new UserBL();
VisitorListVM visitorListVM = new VisitorListVM();
visitorListVM.DefaultLocations = userBL.GetLocationList(UserId);
if(!string.IsNullOrEmpty(columnName)&&!string.IsNullOrEmpty(sortType))
{
visitorListVM.Sort_Direction = sortType;
visitorListVM.PagedVisitorList = GetTypeVisitorDetails(searchText,searchType,cityId,page,columnName,sortType).ToPagedList(page);
}
else
{
visitorListVM.PagedVisit orList = GetTypeVisitorDetails(searchText,searchType,cityId,page).ToPagedList(page);
}
返回visitorListVM;
}
控制器
calls in another function
public VisitorListVM GetAllTypeVisitorDetails(string searchText, string searchType, int cityId, int page, int UserId, [Optional] string columnName, [Optional]string sortType)
{
UserBL userBL = new UserBL();
VisitorListVM visitorListVM = new VisitorListVM();
visitorListVM.DefaultLocations = userBL.GetLocationList(UserId);
if (!string.IsNullOrEmpty(columnName) && !string.IsNullOrEmpty(sortType))
{
visitorListVM.Sort_Direction = sortType;
visitorListVM.PagedVisitorList = GetTypeVisitorDetails(searchText, searchType, cityId, page, columnName, sortType).ToPagedList(page);
}
else
{
visitorListVM.PagedVisitorList = GetTypeVisitorDetails(searchText, searchType, cityId, page).ToPagedList(page);
}
return visitorListVM;
}
Controller
public ActionResult Sorting(string searchType, int cityId,int Id, string columnName, string sortType)
{
visitorListBL = new VisitorListBL();
VisitorListVM visitorListVM = new VisitorListVM();
visitorListVM = visitorListBL.GetAllTypeVisitorDetails(string.Empty, searchType, Convert.ToInt32(cityId), Id, UserId, columnName, sortType);
visitorListVM.Sort_Direction=sortType;
if (Convert.ToString(VisitorListType.CurrentCheckInVisitor) == searchType)
{
return PartialView("~/Views/VisitorList/_CheckInVisitorList.cshtml", visitorListVM);
}
if (Convert.ToString(VisitorListType.TodayAllInVisitor) == searchType)
{
return PartialView("~/Views/VisitorList/_VisitorList.cshtml", visitorListVM);
}
if (Convert.ToString(VisitorListType.VisitorHistory) == searchType)
{
return PartialView("~/Views/VisitorList/_VisitorList.cshtml", visitorListVM);
}
return View();
}
JQuery
函数排序(columnName,cityId,tabid){
if(sort ==ASC)
{
sort =DESC ;
}
其他
{
sort =ASC;
}
$ .ajax({
类型:GET,
contentType:'application / json',
url:/ VisitorList / Sorting,
data:{Id:currentPage,cityId:cityId,searchType:tabid,columnName:columnName,sortType:sort},
成功:函数(数据){
$('#divVisitorsList')。replaceWith(data)
sort = data.Sort_Direction;
}
});
}
$(文件).on('click','。sorting',function(){
var c olumnName = $(this).text();
var cityId = $('#ddlLocation')。val();
var tabid = $(。VisitorActiveTab ).find('。active')。attr('id');
排序(columnName,cityId,tabid)
});
JQuery
function Sorting(columnName, cityId, tabid) {
if (sort == "ASC")
{
sort = "DESC";
}
else
{
sort="ASC";
}
$.ajax({
type: "GET",
contentType: 'application/json',
url: "/VisitorList/Sorting",
data: { Id: currentPage, cityId: cityId, searchType: tabid, columnName: columnName, sortType: sort },
success: function (data) {
$('#divVisitorsList').replaceWith(data)
sort = data.Sort_Direction;
}
});
}
$(document).on('click', '.sorting', function(){
var columnName = $(this).text();
var cityId = $('#ddlLocation').val();
var tabid = $(".VisitorActiveTab").find('.active').attr('id');
Sorting(columnName, cityId, tabid)
});
推荐答案
这篇关于在没有页面刷新的情况下在mvc中的表(tr标签)中进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!