public ActionResult Contacts(int Projects, ContactsSearchViewModel search) { ViewBag.ProjectsName = Projectservice.GetnameProjects(Projects); var items = ContactsService.GetAll(Projects, search); ViewBag.Search = search; ViewBag.ProjectId = Projects; return(View("~/Views/Project/Contacts.cshtml", items)); }
public static List <ContactsViewModel> GetAll(int ProjectId, ContactsSearchViewModel search) { using (var db = new ShlekenEntities3()) { return(db.Contacts .Where(i => i.Projects.AccountId == Userservice.AccountId && i.ProjectId == ProjectId && (string.IsNullOrEmpty(search.Name) == true || i.Name.ToLower().Contains(search.Name.ToLower())) && (string.IsNullOrEmpty(search.Company) == true || i.Company.ToLower().Contains(search.Company.ToLower())) && (string.IsNullOrEmpty(search.Phone) == true || i.Phone.ToLower().Contains(search.Phone.ToLower())) ) .ToList() .Select(i => { var item = i.Map <Contacts, ContactsViewModel>(); return item; }) .ToList()); } }