// GET: Contact public ActionResult Index() { SimpleMoldelFilter <ContactVM> model = new SimpleMoldelFilter <ContactVM>(); model = _service.GetFilter(model); return(View(model)); }
public SimpleMoldelFilter <ContactVM> GetFilter(SimpleMoldelFilter <ContactVM> filterModel) { IQueryable <Tbl_Contact> query = _unitOfWork.Contacts.Filter(x => x.ID > 0).OrderBy(x => x.FirstName); if (!String.IsNullOrEmpty(filterModel.field1)) { query = query.Where(x => x.FirstName.Contains(filterModel.field1) || x.LastName.Contains(filterModel.field1)); } if (!String.IsNullOrEmpty(filterModel.field2)) { query = query.Where(x => x.Department.Contains(filterModel.field2)); } if (filterModel.field3 > 0) { query = query.Where(x => x.ContractType.Equals(filterModel.field3)); } if (query.Any()) { filterModel.Pager.TotalRecords = query.Count(); query = PagingService.QueryRecordsForPage(query, filterModel.Pager.CurrentPage, filterModel.Pager.PageSize); filterModel.Pager.CalcululatePagesAndRecords(filterModel.Pager.TotalRecords ); List <ContactVM> list = new List <ContactVM>(); if (filterModel.Pager.TotalRecords > 0) { foreach (var dbStudent in query.ToList()) { list.Add(converter.ConvertToModel(dbStudent)); } } filterModel.ListOfItemsToShow = list.OrderBy(x => x.FullName); } else { filterModel.Pager = new Helper.Pager(); } return(filterModel); }
public ActionResult Filter(SimpleMoldelFilter <ContactVM> model) { return(View("Index", _service.GetFilter(model))); }