public ActionResult CustomerList(CustomerListModel model) { model = initCustomerListModel(model.SelectedSeller, model.SelectedCustomerStatus, model.Search); return View(model); }
private CustomerListModel initCustomerListModel(int selectedUser = Constant.ALL_VALUE, int seletedStatus = Constant.ALL_VALUE, string searchKey = "") { var model = new CustomerListModel(); var uService = new UserService(); var cService = new CustomerService(); var sellers = uService.GetAllUser().Where(c => c.ReferUserId == AccessFactory.CurrentUser.Id).ToList(); sellers.Insert(0, new User() { Id = Constant.ALL_VALUE, Name = Constant.ALL }); model.Sellers = sellers; var statuses = cService.GetAllCustomerStatus(); statuses.Insert(0, new CustomerStatus() { Name = Constant.ALL, Type = Constant.ALL_VALUE }); model.Status = statuses; var allcustomer = new List<Customer>(); var sellersfilter = sellers; if (selectedUser != Constant.ALL_VALUE) sellersfilter = sellersfilter.Where(c => c.Id == selectedUser).ToList(); searchKey = searchKey != null ? searchKey.Trim().ToLower() : ""; foreach (var seller in sellersfilter) { allcustomer.AddRange(cService.GetAllCustomer().Where(c => c.ReferUserId == seller.Id).ToList()); } if (seletedStatus != Constant.ALL_VALUE) allcustomer = allcustomer.Where(c => c.Status == seletedStatus).ToList(); if (searchKey != "") //allcustomer = (from c in allcustomer // where c.Name.ToLower().Contains(searchKey) // select c).OrderBy(c => c.Name).ToList(); allcustomer = allcustomer.Where(c => (c.Name != null && c.Name.ToLower().Contains(searchKey)) || (c.PhoneNumber1 != null && c.PhoneNumber1.ToLower().Contains(searchKey)) || (c.PhoneNumber2 != null && c.PhoneNumber2.ToLower().Contains(searchKey)) || (c.Email != null && c.Email.Contains(searchKey)) ).ToList(); model.Customers = allcustomer; model.SelectedSeller = Constant.ALL_VALUE; model.SelectedCustomerStatus = Constant.ALL_VALUE; model.Search = ""; return model; }