public ActionResult ViewCustomersDetails(int id = 0) { //Получаем покупателя с идентификатором равным id var data = CustomerProcessor.LoadCustomers().Where(c => c.CustomerId == id).FirstOrDefault(); if (data == null) { return(RedirectToAction("ViewCustomers")); } //Получаем из списка заказов все заказы данного покупателя var dataOrdersCustomers = CustomersOrdersProcessor.LoadCustomersOrders().Where(co => co.CustomerId == data.CustomerId) as List <DALCustomersOrdersModel>; //Теперь нужно найти по идентификаторам заказов сами заказы //OrderId - уникальные var DALorders = new List <DALOrdersModel>(); var orders = new List <OrderModel>(); CustomerModel customer; if (dataOrdersCustomers != null) { foreach (var item in dataOrdersCustomers) { DALorders.Add(OrderProcessor.LoadOrders().Where(oid => oid.OrderId == item.OrderId).FirstOrDefault()); } foreach (var dalOrder in DALorders) { orders.Add(new OrderModel { OrderID = dalOrder.OrderId, Date = dalOrder.Date }); } customer = new CustomerModel { CustomerID = data.CustomerId, Name = data.FullName, PhoneNumber = data.PhoneNumber, Email = data.EmailAddress, Orders = orders }; } else { customer = new CustomerModel { CustomerID = data.CustomerId, Name = data.FullName, PhoneNumber = data.PhoneNumber, Email = data.EmailAddress, }; } return(View(customer)); }
public ActionResult Filter(string status) // ajax options { var data = CustomerProcessor.LoadCustomers(); List <CustomerViewModel> customers = new List <CustomerViewModel>(); foreach (var row in data) { customers.Add(new CustomerViewModel { CustomerID = row.CustomerID, FirstName = row.FirstName, LastName = row.LastName, Address = row.Address, City = row.City, Province = row.Province, PostalCode = row.PostalCode, PhoneNumber = row.PhoneNumber, Email = row.Email, LeadSource = row.LeadSource, Status = row.Status, Notes = row.Notes, }); } // Process the status list and assign to Viewbag List <string> statusList = new List <String>(); foreach (var row in customers) { if (row.Status != null) { statusList.Add(row.Status.ToString()); } } ViewBag.status = new SelectList(statusList); if (!String.IsNullOrEmpty(status)) { customers = customers.Where(s => s.Status == status).ToList(); } return(PartialView("_Customers", customers)); }
// READ: list the customers public ActionResult Index(string status) { // 1. Get the data and put it into a list var data = CustomerProcessor.LoadCustomers(); // load all customers into var List <CustomerViewModel> customers = new List <CustomerViewModel>(); // create CustomerViewModel type list foreach (var row in data) // pass the data model list to the view model list. { customers.Add(new CustomerViewModel { CustomerID = row.CustomerID, FirstName = row.FirstName, LastName = row.LastName, Address = row.Address, City = row.City, Province = row.Province, PostalCode = row.PostalCode, PhoneNumber = row.PhoneNumber, Email = row.Email, LeadSource = row.LeadSource, Status = row.Status, Notes = row.Notes, }); } // 2. Create the status filter list and send to View Bag List <string> statusList = new List <String>(); foreach (var row in customers) { if (row.Status != null) { statusList.Add(row.Status.ToString()); } } var filteredStatusList = statusList.Distinct(); ViewBag.status = new SelectList(filteredStatusList); return(View(status)); }
public ActionResult ViewCustomers() { ViewBag.Message = "The List of Cutomers"; var data = CustomerProcessor.LoadCustomers(); List <CustomerModel> customers = new List <CustomerModel>(); foreach (var row in data) { customers.Add(new CustomerModel { CustomerID = row.CustomerId, Name = row.FullName, PhoneNumber = row.PhoneNumber, Email = row.EmailAddress }); } return(View(customers)); }
public ActionResult ViewCustomers() { ViewBag.Message = "View Customer page."; var data = CustomerProcessor.LoadCustomers(); List <CustomerModel> customers = new List <CustomerModel>(); foreach (var row in data) { customers.Add(new CustomerModel { CustomerID = row.CustomerID, FName = row.FName, LName = row.LName, Address = row.Address, Phone = row.Phone, StartDate = row.StartDate }); } return(View(customers)); }
public JsonResult GetCustomers() { ViewBag.Message = "Customer List"; var result = CustomerProcessor.LoadCustomers(); List <Customer> customer = new List <Customer>(); foreach (var row in result) { customer.Add(new Customer { FirstName = row.FirstName, LastName = row.LastName, Occupation = row.Occupation, City = row.City, State = row.State, Email = row.Email, ImageURL = row.ImageURL }); } return(Json(customer, JsonRequestBehavior.AllowGet)); }
public ActionResult GetCustomerData(string status) { // 1. Get the data and put it into a list var data = CustomerProcessor.LoadCustomers(); // load all customers into var List <CustomerViewModel> customers = new List <CustomerViewModel>(); // create CustomerViewModel type list foreach (var row in data) // pass the data model list to the view model list. { customers.Add(new CustomerViewModel { CustomerID = row.CustomerID, FirstName = row.FirstName, LastName = row.LastName, Address = row.Address, City = row.City, Province = row.Province, PostalCode = row.PostalCode, PhoneNumber = row.PhoneNumber, Email = row.Email, LeadSource = row.LeadSource, Status = row.Status, Notes = row.Notes, }); } // 2. Create the status filter list and send to View Bag List <string> statusList = new List <String>(); foreach (var row in customers) { if (row.Status != null) { statusList.Add(row.Status.ToString()); } } var filteredStatusList = statusList.Distinct(); ViewBag.status = new SelectList(filteredStatusList); // 3. Filter the list if needed if (!String.IsNullOrEmpty(status)) { customers = customers.Where(s => s.Status == status).ToList(); } // 4a. If this is an AJAX request, format the data, and return a JSON result object (for processing with JavaScript) if (Request.IsAjaxRequest()) { var formattedData = customers.Select(c => new { CustomerID = c.CustomerID, FirstName = c.FirstName, LastName = c.LastName, Address = c.Address, City = c.City, Province = c.Province, PostalCode = c.PostalCode, PhoneNumber = c.PhoneNumber, Email = c.Email, LeadSource = c.LeadSource, Status = c.Status, Notes = c.Notes }); return(Json(formattedData, JsonRequestBehavior.AllowGet)); } // 4b. If no filtering is needed, return full customer list. { return(PartialView(customers)); } }