Exemplo n.º 1
0
        private CustomerManagementViewModel getCustomers(bool onlyShowParents = false, string SearchCriteria = "")
        {
            IEnumerable<Customer> customers = QuickSearchCustomers(User.Identity.Name,
                                                                   new QuickSearchCustomersRequest
                                                                       {SearchString = SearchCriteria});
            if (onlyShowParents)
            {
                customers = customers.Where(c => c.ParentCustomerId == 0);
            }
            var customerManagementViewModel = new CustomerManagementViewModel();
            foreach (
                Customer customer in
                    customers.OrderBy(c => c.ParentName).ThenBy(c => c.ParentCustomerId).ThenBy(c => c.Name))
            {
                CustomerViewModel customerViewModel = Mapper.Map<Customer, CustomerViewModel>(customer);

                if (customer.Contacts.Count() > 0)
                {
                    customerViewModel.ContactFirstName = customer.Contacts.First().FirstName;
                    customerViewModel.ContactLastName = customer.Contacts.First().LastName;
                    customerViewModel.ContactPhone = customer.Contacts.First().Phone;
                }

                customerManagementViewModel.AddCustomer(customerViewModel);
            }
            return customerManagementViewModel;
        }
Exemplo n.º 2
0
        public ActionResult ProcessQuickSearchCustomersInput(string searchString)
        {
            return TryThis(() =>
                               {
                                   IEnumerable<Customer> customers = QuickSearchCustomers(User.Identity.Name,
                                                                                          new QuickSearchCustomersRequest
                                                                                              {
                                                                                                  SearchString =
                                                                                                      searchString,
                                                                                              });

                                   var viewModel = new CustomerManagementViewModel();
                                   customers.ToList().ForEach(
                                       c => viewModel.AddCustomer(Mapper.Map<Customer, CustomerViewModel>(c)));

                                   return View("CustomerManagement", viewModel);
                               });
        }