public ActionResult OrderReceipt(String id)
        {
            if (id == null)
            {
                return(View("PrintOrderReceipt"));
            }

            //List<WarehouseOrder> allOrders = _context.WarehouseOrders.ToList();
            //List<WarehouseOrderType> allOrderstype = _context.WarehouseOrderTypes.ToList();
            //List<WarehouseOrderDetail> allOrdersdetail = _context.WarehouseOrderDetails.ToList();

            //var ordersProducts = (from o in allOrders
            //    join ot in allOrderstype on o.OId equals ot.OId
            //    join od in allOrdersdetail on o.OId equals od.OrderID
            //    select new WarehouseOrderJoin()
            //    {
            //        WarehouseOrderj = o,
            //        WarehouseOrderTypej = ot,
            //        WarehouseOrderDetailj = od
            //    }).ToList();

            List <WarehouseOrder> orders  = _context.WarehouseOrders.ToList();
            WarehouseOrderDetail  details = _context.WarehouseOrderDetails.SingleOrDefault(o => o.OrderID == id);
            WarehouseOrderType    type    = _context.WarehouseOrderTypes.SingleOrDefault(o => o.OId == id);
            var OrderList = (from o in orders
                             where o.OId.Contains(id)
                             select new WarehouseOrderJoin()
            {
                WarehouseOrderj = o,
                WarehouseOrderDetailj = details,
                WarehouseOrderTypej = type
            }).ToList();

            ViewBag.ID = id;
            return(View(OrderList));
        }
        public ActionResult AddOrder(WarehouseOrderJoin warehouseOrderJoin)
        {
            var  OrderId       = Request.Form["OrderID"];
            var  date          = Request.Form["date"];
            var  orderType     = Int32.Parse(Request.Form["OrderType"]);
            var  orderSender   = Request.Form["OrderSender"];
            var  OrderReciever = Request.Form["OrderReciever"];
            bool condition     = false;

            int    NoOfProducts = Int32.Parse(Request.Form["length"]);
            double price        = 0;

            for (int i = 0; i <= NoOfProducts; i++)
            {
                var product     = Request.Form["PID[" + i + "]"];
                var quatity     = Int32.Parse(Request.Form["PQ[" + i + "]"]);
                var stockInDb   = _context.WarehouseStocks.SingleOrDefault(p => p.ProductID == product);
                var productInDb = _context.WarehouseProducts.SingleOrDefault(p => p.PId == product);
                if (stockInDb != null)
                {
                    if (stockInDb.Quantity >= quatity)
                    {
                        condition = true;
                    }
                    else
                    {
                        condition = false;
                        break;
                    }
                }
                else if (productInDb != null)
                {
                    condition = false;
                    break;
                }
                else
                {
                    condition = false;
                    break;
                }
            }

            if (condition == true)
            {
                for (int i = 0; i <= NoOfProducts; i++)
                {
                    var product = Request.Form["PID[" + i + "]"];
                    var quatity = Int32.Parse(Request.Form["PQ[" + i + "]"]);

                    if (product == null || product == "")
                    {
                    }
                    else
                    {
                        var Order       = new WarehouseOrder();
                        var OrderDetail = new WarehouseOrderDetail();
                        var OrderType   = new WarehouseOrderType();
                        var stockInDb   = _context.WarehouseStocks.SingleOrDefault(p => p.ProductID == product);

                        try
                        {
                            //Calculating price for each product w.r.t to quantity
                            var productPrice =
                                _context.WarehouseProducts.SingleOrDefault(p => p.PId == product);
                            var tprice = quatity * productPrice.Price;

                            Order.TotalPrice = tprice;
                        }
                        catch (Exception e)
                        {
                            continue;
                        }


                        //Setting Id to all of them
                        Order.OId           = OrderId;
                        Order.Notification  = 0;
                        OrderDetail.OrderID = OrderId;
                        OrderType.OId       = OrderId;

                        //Setting remaining instances
                        Order.PId            = Request.Form["PID[" + i + "]"];
                        Order.PQuantity      = Int32.Parse(Request.Form["PQ[" + i + "]"]);
                        Order.Date           = DateTime.Parse(date);
                        OrderDetail.Receiver = OrderReciever;
                        OrderDetail.Sender   = orderSender;


                        if (i == 0)
                        {
                            OrderType.type = orderType;
                            _context.WarehouseOrderDetails.Add(OrderDetail);
                            _context.WarehouseOrderTypes.Add(OrderType);
                        }

                        try
                        {
                            _context.WarehouseOrders.Add(Order);
                            _context.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.ToString());
                        }
                    }
                }
            }
            else
            {
                return(Redirect("~/Warehouse/OrderError"));
            }

            return(Redirect("~/Warehouse/Orders"));
        }