public PagedResult <ProvinceViewModel> GetAllPaging(string startDate, string endDate, string keyword, int pageIndex, int pageSize) { var query = _provinceRepository.FindAll(); if (!string.IsNullOrEmpty(startDate)) { DateTime start = DateTime.ParseExact(startDate, "dd/MM/yyyy", CultureInfo.GetCultureInfo("vi-VN")); query = query.Where(x => x.DateCreated >= start); } if (!string.IsNullOrEmpty(endDate)) { DateTime end = DateTime.ParseExact(endDate, "dd/MM/yyyy", CultureInfo.GetCultureInfo("vi-VN")); query = query.Where(x => x.DateCreated <= end); } if (!string.IsNullOrEmpty(keyword)) { query = query.Where(x => x.Name.Contains(keyword)); } var totalRow = query.Count(); var data = query.OrderByDescending(x => x.DateCreated).Skip((pageIndex - 1) * pageSize).Take(pageSize) .ProjectTo <ProvinceViewModel>().ToList(); return(new PagedResult <ProvinceViewModel>() { CurrentPage = pageIndex, PageSize = pageSize, Results = data, RowCount = totalRow }); }
public GetGeneralResponse <IEnumerable <ProvinceView> > GetProvinces() { GetGeneralResponse <IEnumerable <ProvinceView> > response = new GetGeneralResponse <IEnumerable <ProvinceView> >(); try { IEnumerable <ProvinceView> provinces = _provinceRepository.FindAll().ConvertToProvinceViews(); response.data = provinces; } catch (Exception ex) { } return(response); }