public ActionResult ConfirmDelete(string Id) { Customer customerToDelete = customerContext.Find(Id); if (customerToDelete == null) { return(HttpNotFound()); } else { IPOSSaleService possaleService = new POSSaleService(possaleContext, possaleItemContext); possaleService.GetPOSSales(customerToDelete); bool canDelete = customerToDelete.CustomerNotes.Count() == 0 && customerToDelete.Layaways.Count() == 0 && customerToDelete.Invoices.Count() == 0 && customerToDelete.OnlineOrders.Count() == 00 && customerToDelete.POSSales.Count() == 0; if (!canDelete) { return(RedirectToAction("Error")); } customerContext.Delete(Id); customerContext.Commit(); return(RedirectToAction("Index")); } }
// GET: Customers public ActionResult Index() { IPOSSaleService possaleService = new POSSaleService(possaleContext, possaleItemContext); List <Customer> customers = customerContext.Collection().ToList(); foreach (Customer customer in customers) { possaleService.GetPOSSales(customer); } return(View(customers)); }
public ActionResult Edit(string Id) { Customer customer = customerContext.Find(Id); if (customer == null) { return(HttpNotFound()); } else { // get ProductList IProductRetrieveService productService = new ProductRetrieveService(); customer.ProductList = productService.GetProducts(); // get Invoices // related Invoice records added by EF // sort Invoices and InvoicesItems ICollection <Invoice> invoices = customer.Invoices; customer.Invoices = invoices.OrderByDescending(i => i.ModifiedAt).ToList(); foreach (Invoice invoice in customer.Invoices) { ICollection <InvoiceItem> invoiceItems = invoice.InvoiceItems; invoice.InvoiceItems = invoiceItems.OrderByDescending(i => i.ModifiedAt).ToList(); } // get OnlineOrders // related OnlineOrder and OnlineOrderItem records added by EF // sort OnlineOrders and OnlineOrderItems ICollection <OnlineOrder> onlineorders = customer.OnlineOrders; customer.OnlineOrders = onlineorders.OrderByDescending(i => i.ModifiedAt).ToList(); foreach (OnlineOrder onlineorder in customer.OnlineOrders) { ICollection <OnlineOrderItem> onlineorderItems = onlineorder.OnlineOrderItems; onlineorder.OnlineOrderItems = onlineorderItems.OrderByDescending(i => i.ModifiedAt).ToList(); } // get Layaways // related Layaway and LayawayItem records added by EF // sort Layaways and LayawayItems ICollection <Layaway> layaways = customer.Layaways; customer.Layaways = layaways.OrderByDescending(i => i.ModifiedAt).ToList(); foreach (Layaway layaway in customer.Layaways) { ICollection <LayawayItem> layawayItems = layaway.LayawayItems; layaway.LayawayItems = layawayItems.OrderByDescending(i => i.ModifiedAt).ToList(); } // load (sorted) Invoice POSSales IPOSSaleService posSaleService = new POSSaleService(possaleContext, possaleItemContext); posSaleService.GetPOSSales(customer); // sort Invoice POSSaleItems ICollection <POSSale> possales = customer.POSSales; foreach (POSSale possale in customer.POSSales) { ICollection <POSSaleItem> possaleItems = possale.POSSaleItems; possale.POSSaleItems = possaleItems.OrderByDescending(i => i.ModifiedAt).ToList(); } // sort and load Invoice Payments IPaymentService paymentService = new PaymentService(); paymentService.GetPayments(customer); // sort CustomerNotes customer.CustomerNotes = customer.CustomerNotes.OrderBy(n => n.CreatedAt).ToList(); //customer.CustomerNotes.ToList().ForEach(n => { n.NoteBody = n.NoteBody.Replace("\n", "<br>"); }); return(View(customer)); } }