public ActionResult FetchEditAutoOrderOrderModule(int autoorderid)
        {
            var autoorder = Exigo.GetCustomerAutoOrder(Identity.Customer.CustomerID, autoorderid);

            var configuration = Identity.Customer.Market.Configuration.AutoOrders;
            var products      = Exigo.GetItems(new ExigoService.GetItemsRequest
            {
                Configuration          = configuration,
                IncludeChildCategories = true
            }).ToList();

            var orderItems   = autoorder.Details.ToList();
            var itemCodeList = orderItems.Select(c => c.ItemCode).ToList();

            products.Where(p => itemCodeList.Contains(p.ItemCode)).ToList().ForEach(p => products.Remove(p));


            // Populate our model with the products and the Auto Order
            var model = new AutoOrderAddEditCartViewModel();

            model.AutoOrder    = autoorder;
            model.ProductsList = products;


            string html = RenderPartialViewToString("displaytemplates/autoordereditorder", model);

            return(new JsonNetResult(new
            {
                success = true,
                module = html
            }));
        }
        public JsonNetResult UpdateAutoOrderItems(AutoOrderAddEditCartViewModel model)
        {
            try
            {
                Exigo.UpdateCustomerAutoOrderItems(Identity.Customer.CustomerID, model.AutoOrder.AutoOrderID, model.ProductsList);

                return(new JsonNetResult(new
                {
                    success = true
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    message = ex.Message
                }));
            }
        }
        public JsonNetResult GetAutoOrderModal(int orderid)
        {
            var model = new AutoOrderAddEditCartViewModel();

            var autoorder = (ExigoService.AutoOrder)Exigo.OData().AutoOrders.Expand("Details")
                            .Where(a => a.CustomerID == Identity.Customer.CustomerID)
                            .Where(a => a.AutoOrderID == orderid)
                            .First();

            model.AutoOrder = autoorder;

            var configuration = Identity.Customer.Market.Configuration.BackOfficeAutoOrders;

            //Get the available products
            var products = Exigo.GetItems(new ExigoService.GetItemsRequest
            {
                Configuration          = configuration,
                IncludeChildCategories = true
            }).ToList();

            products = products
                       .Where(c => c.AllowOnAutoOrder == true)
                       .Where(c => c.Price != 0).ToList();

            foreach (var product in products)
            {
                var autoOrderDetail = autoorder.Details.Where(c => c.ItemCode == product.ItemCode).FirstOrDefault();

                product.Quantity = (autoOrderDetail != null) ? autoOrderDetail.Quantity : 0;
            }

            model.ProductsList = products;

            var html = this.RenderPartialViewToString("../AutoOrders/DisplayTemplates/AutoOrderEditOrder", model);

            return(new JsonNetResult(new
            {
                html = html
            }));
        }