//*******************************************************************************
        //                              Product Methods
        //*******************************************************************************
        public JsonResult GetProduct(string Id)
        {
            IProductRetrieveService productService = new ProductRetrieveService();
            Product product = productService.GetProduct(Id);

            return(Json(product, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(Customer customer, string Id)
        {
            Customer customerToEdit = customerContext.Find(Id);

            if (customerToEdit == null)
            {
                return(HttpNotFound());
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    // reload ProductList
                    IProductRetrieveService productService = new ProductRetrieveService();
                    customer.ProductList = productService.GetProducts();

                    // reload Layaways
                    ILayawayDataService layawayService = new LayawayDataService();
                    customer.Layaways = layawayService.GetLayaways(Id);

                    return(View(customer));
                }

                customerToEdit.FirstName   = customer.FirstName;
                customerToEdit.LastName    = customer.LastName;
                customerToEdit.Email       = customer.Email;
                customerToEdit.CompanyName = customer.CompanyName;
                customerToEdit.Street      = customer.Street;
                customerToEdit.City        = customer.City;
                customerToEdit.State       = customer.State;
                customerToEdit.ZipCode     = customer.ZipCode;
                customerToEdit.Phone       = customer.Phone;
                customerToEdit.Phone2      = customer.Phone2;
                customerToEdit.Website     = customer.Website;

                customerContext.Commit();
                return(RedirectToAction("Index"));
            }
        }
        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));
            }
        }