public async Task <ActionResult> UpdateOrder(PurchaseOrderViewModel order)
        {
            var updateOrder = await db.PurchaseOrders.FindAsync(order.ID);

            if (updateOrder == null)
            {
                return(HttpNotFound());
            }

            var Products = await db.PurchaseOrderProducts.Where(p => p.PurchaseOrderId == order.ID).ToListAsync();

            db.PurchaseOrderProducts.RemoveRange(Products);

            foreach (var p in order.Products)
            {
                PurchaseOrderProduct orderProduct = new PurchaseOrderProduct
                {
                    PurchaseOrderId = int.Parse(order.ID.ToString()),
                    ProductId       = p.ProductId,
                    Qty             = p.Qty
                };
                db.PurchaseOrderProducts.Add(orderProduct);
                await db.SaveChangesAsync();
            }
            return(Json(new { updateOrder.PurchaseOrderId, updateOrder.Date }));
        }
        public async Task <ActionResult> SaveOrder(PurchaseOrderViewModel order)
        {
            var newOrder = new PurchaseOrder
            {
                VendorID = order.VendorId,
                Status   = "Pending",
                Date     = DateTime.Now
            };

            db.PurchaseOrders.Add(newOrder);
            await db.SaveChangesAsync();

            foreach (var p in order.Products)
            {
                PurchaseOrderProduct orderProduct = new PurchaseOrderProduct
                {
                    PurchaseOrderId = newOrder.PurchaseOrderId,
                    ProductId       = p.ProductId,
                    Qty             = p.Qty
                };
                db.PurchaseOrderProducts.Add(orderProduct);
                await db.SaveChangesAsync();
            }
            return(Json(new { Id = newOrder.PurchaseOrderId, Date = newOrder.Date }));
        }