public async Task <PagedList <ServiceRequestModel> > GetAll(SearchServiceRequestModel model) { var query = _context.ServiceRequest.Where(t => (t.DelFlg == false) && (model.StudentUsername == null || t.User.Username.Contains(model.StudentUsername)) && (model.Status == null || t.Status == model.Status) && (model.DepartmentId == null || t.Service.DepartmentId == model.DepartmentId) && (model.ServiceId == null || t.ServiceId == model.ServiceId) && (model.StaffUsername == null || t.Staff.StaffNavigation.Username == model.StaffUsername) ) .Select(t => new ServiceRequestModel { TicketId = t.TicketId, UserId = t.UserId, Username = t.User.Username, FullName = t.User.FullName, StudentPhoto = t.User.Photo, Content = t.Content, ServiceId = t.ServiceId, ServiceNm = t.Service.ServiceNm, JsonInformation = t.JsonInformation, StaffId = t.StaffId, StaffNm = t.Staff.StaffNavigation.FullName, StaffUsername = t.Staff.StaffNavigation.Username, DepartmentId = t.Service.Department.DepartmentId, DepartmentNm = t.Service.Department.DepartmentNm, Status = t.Status, DueDateTime = t.DueDateTime, DelFlg = t.DelFlg, InsBy = t.InsBy, InsDatetime = t.InsDatetime, UpdBy = t.UpdBy, UpdDatetime = t.UpdDatetime }); //var totalCount = await _context.ServiceRequest.CountAsync(); List <ServiceRequestModel> result = null; query = query.OrderByDescending(t => t.InsDatetime); if (model.SortBy == Constants.SortBy.SORT_NAME_ASC) { query = query.OrderBy(t => t.ServiceNm); } else if (model.SortBy == Constants.SortBy.SORT_NAME_DES) { query = query.OrderByDescending(t => t.ServiceNm); } result = await query.Skip(model.Size *(model.Page - 1)) .Take(model.Size) .ToListAsync(); var totalCount = result.Count; return(PagedList <ServiceRequestModel> .ToPagedList(result, totalCount, model.Page, model.Size)); }
public async Task <object> GetAllServiceRequest(SearchServiceRequestModel model) { var serviceRequests = await _unitOfWork.ServiceRequestRepository.GetAll(model); dynamic result; List <Dictionary <string, object> > listModel = new List <Dictionary <string, object> >(); if (!string.IsNullOrEmpty(model.Fields)) { string[] filter = model.Fields.Split(","); foreach (var s in serviceRequests) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); for (int i = 0; i < filter.Length; i++) { switch (filter[i].Trim()) { case "TicketId": dictionary.Add("TicketId", s.TicketId); break; case "Username": dictionary.Add("Username", s.Username); break; case "FullName": dictionary.Add("FullName", s.FullName); break; case "StudentPhoto": dictionary.Add("Photo", s.StudentPhoto); break; case "UserId": dictionary.Add("UserId", s.UserId); break; case "ServiceId": dictionary.Add("ServiceId", s.ServiceId); break; case "ServiceNm": dictionary.Add("ServiceNm", s.ServiceNm); break; case "DepartmentId": dictionary.Add("Department", s.DepartmentId); break; case "DepartmentNm": dictionary.Add("Department", s.DepartmentNm); break; case "StaffId": dictionary.Add("StaffId", s.StaffId); break; case "StaffNm": dictionary.Add("StaffNm", s.StaffNm); break; case "StaffUsername": dictionary.Add("StaffUsername", s.StaffUsername); break; case "Content": dictionary.Add("Content", s.Content); break; case "DueDateTime": dictionary.Add("DueDateTime", s.DueDateTime); break; case "Status": dictionary.Add("Status", s.Status); break; } } listModel.Add(dictionary); } result = listModel; } else { result = serviceRequests; } return(new { data = result, totalCount = serviceRequests.TotalCount, totalPages = serviceRequests.TotalPages }); }
public async Task <IActionResult> GetAllServiceRequest([FromQuery] SearchServiceRequestModel model) { var result = await _serviceRequestService.GetAllServiceRequest(model); return(Ok(result)); }