public IActionResult Create([Bind("OrderId,ProductId,Status,Quantity,Unit,Product,Order")] ProductOrderVM model)
        {
            // model.OrderNo =
            if (ModelState.IsValid)
            {
                var productOrder = _mapper.Map <ProductOrder>(model);


                bool isAdded = _productOrderManager.Add(productOrder);
                if (isAdded)
                {
                    ViewBag.SuccessMessage = "ProductOrder Saved Successfully!";
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Operation Failed!";
            }

            var productorders = _productOrderManager.GetAll();

            return(View("Index", productorders));
        }
        public IActionResult Create([Bind("Id,CustomerId,OrderNo,OrderDate,Products,Customer,Status,ShippingAddress,PaymentMethod,ProductList,Phone")] OrderCreateViewModel model)
        {
            //var cart = Ecommerce.Abstractions.Helper.SessionHelper.GetObjectFromJson<List<Item>>(HttpContext.Session, "cart");
            //if(model.ProductList == null)
            //{
            //    model.ProductList = cart;

            //}
            if (model.OrderNo == null || model.CustomerId == 0 || model.OrderDate == null)
            {
                model.OrderDate  = DateTime.Now;
                model.CustomerId = 10004;
                model.OrderNo    = DateTime.Now.ToString() + model.CustomerId;
            }
            // model.OrderNo =
            if (ModelState.IsValid)
            {
                var order = _mapper.Map <Order>(model);
                if (_orderManager.OrderExists(model.Id))
                {
                    ViewBag.ErrorMessage = "Order Exists Already";
                }
                else
                {
                    order.Status = "Pending";

                    bool isAdded = _orderManager.Add(order);
                    long id      = order.Id;

                    if (isAdded)
                    {
                        ProductOrder po   = new ProductOrder();
                        Order        o    = _orderManager.GetById(id);
                        var          cart = CRUDOperation.WebApp.Helper.SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");

                        foreach (var item in cart)
                        {
                            po.ProductId = item.Product.Id;
                            long pid = item.Product.Id;
                            po.Quantity = item.Quantity;
                            int qty = item.Quantity;
                            po.OrderId    = id;
                            po.Customer   = o.Customer;
                            po.CustomerId = o.CustomerId;
                            po.Status     = "Pending";
                            _productOrderManager.Add(po);
                            //var stock = _stockManager.check(pid);
                            //stock.Quantity = stock.Quantity - qty;
                            //_stockManager.Update(stock);
                        }
                        cart.Clear();
                        CRUDOperation.WebApp.Helper.SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
                        ViewBag.SuccessMessage = "Order Saved Successfully!";
                        //return nameof()
                    }
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Operation Failed!";
            }

            model.OrderList = _orderManager.GetAll().ToList();
            return(View(model));
        }