public async Task <IActionResult> GetAllServices([FromQuery] SearchServicModel model) { var isCache = _redisCacheRepository.isExist(Constants.KeyRedis.SERVICES); if (!isCache) { var listServices = await _serviceService.GetServices(); _redisCacheRepository.Add(Constants.KeyRedis.SERVICES, listServices); } var cacheResult = _redisCacheRepository.Get <IEnumerable <ServiceModel> >(Constants.KeyRedis.SERVICES); var result = _serviceService.GetAllService(model, cacheResult); return(Ok(result)); }
public PagedList <ServiceModel> GetAll(SearchServicModel model, IEnumerable <ServiceModel> listServices) { var query = listServices.Where(t => (model.ServiceNm == null || t.ServiceNm.Contains(model.ServiceNm)) && (model.DepartmentNm == null || t.DepartmentNm == model.DepartmentNm) && (model.DepartmentId == null || t.DepartmentId == model.DepartmentId)) .Select(t => new ServiceModel { ServiceId = t.ServiceId, ServiceNm = t.ServiceNm, DescriptionService = t.DescriptionService, DepartmentId = t.DepartmentId, DepartmentNm = t.DepartmentNm, FormLink = t.FormLink, SheetLink = t.SheetLink, ProcessMaxDay = t.ProcessMaxDay, DelFlg = t.DelFlg, InsBy = t.InsBy, InsDatetime = t.InsDatetime, UpdBy = t.UpdBy, UpdDatetime = t.UpdDatetime }); var totalCount = query.Count(); List <ServiceModel> result = null; 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 = query.Skip(model.Size * (model.Page - 1)) .Take(model.Size) .ToList(); return(PagedList <ServiceModel> .ToPagedList(result, totalCount, model.Page, model.Size)); }
public object GetAllService(SearchServicModel model, IEnumerable <ServiceModel> list) { var services = _unitOfWork.ServiceRepository.GetAll(model, list); 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 services) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); for (int i = 0; i < filter.Length; i++) { switch (filter[i].Trim()) { case "ServiceId": dictionary.Add("ServiceId", s.ServiceId); break; case "ServiceNm": dictionary.Add("ServiceNm", s.ServiceNm); break; case "DescriptionService": dictionary.Add("DescriptionService", s.DescriptionService); break; case "FormLink": dictionary.Add("FormLink", s.FormLink); break; case "SheetLink": dictionary.Add("RoomNum", s.SheetLink); break; case "ProcessMaxDay": dictionary.Add("ProcessMaxDay", s.ProcessMaxDay); break; case "DepartmentId": dictionary.Add("DepartmentId", s.DepartmentId); break; case "DepartmentNm": dictionary.Add("DepartmentNm", s.DepartmentNm); break; } } listModel.Add(dictionary); } result = listModel; } else { result = services; } return(new { data = result, totalCount = services.TotalCount, totalPages = services.TotalPages }); }