public ActionResult Edit(string id)
        {
            var orderInDb = new ProductionAddOrder();

            var order = _context.ProductionOrders.SingleOrDefault(o => o.Id == id);

            var orderrawInDb = _context.ProductionRawMaterial.Where(or => or.OId == id).ToList();
            List <ProductionRawMaterial> list = new List <ProductionRawMaterial>();

            list = orderrawInDb;

            string products = "";
            string quantity = "";

            foreach (var item in list)
            {
                products = products + item.PId + ",";
                quantity = quantity + item.Quantity + ",";
            }

            ProductionRawMaterial prm = new ProductionRawMaterial();

            prm.Quantity = quantity;
            prm.PId      = products;
            prm.OId      = id;
            prm.SNO      = 0;
            orderInDb.productionOrder       = order;
            orderInDb.productionRawMaterial = prm;

            return(View(orderInDb));
        }
        public ActionResult addOrder(ProductionAddOrder Item)
        {
            var order = new ProductionOrder();
            var raw   = new ProductionRawMaterial();

            order = Item.productionOrder;
            _context.ProductionOrders.Add(order);
            List <string> listRaw     = (Item.productionRawMaterial.PId).Split(',').ToList <string>();
            List <string> quantityRaw = (Item.productionRawMaterial.Quantity).Split(',').ToList <string>();

            for (var x = 0; x < listRaw.Count(); x++)
            {
                raw.OId      = Item.productionOrder.Id;
                raw.PId      = listRaw[x];
                raw.Quantity = quantityRaw[x];
                _context.ProductionRawMaterial.Add(raw);
                raw = new ProductionRawMaterial();
            }

            _context.SaveChanges();
            return(Redirect("Index"));
        }
        public ActionResult UpdateOrder(ProductionAddOrder production)
        {
            var orderrawInDb = _context.ProductionRawMaterial.Where(or => or.OId == production.productionOrder.Id).ToList();

            _context.ProductionRawMaterial.RemoveRange(orderrawInDb);
            var order = _context.ProductionOrders.SingleOrDefault(o => o.Id == production.productionOrder.Id);

            order.PId          = production.productionOrder.PId;
            order.ExpectedDate = production.productionOrder.ExpectedDate;
            order.StartDate    = production.productionOrder.StartDate;
            order.Status       = production.productionOrder.Status;
            order.Title        = production.productionOrder.Title;
            _context.SaveChanges();
            try
            {
                var           raw         = new ProductionRawMaterial();
                List <string> listRaw     = (production.productionRawMaterial.PId).Split(',').ToList <string>();
                List <string> quantityRaw = (production.productionRawMaterial.Quantity).Split(',').ToList <string>();
                for (var x = 0; x < listRaw.Count(); x++)
                {
                    if (listRaw[x] != null)
                    {
                        raw.OId      = production.productionOrder.Id;
                        raw.PId      = listRaw[x];
                        raw.Quantity = quantityRaw[x];
                        _context.ProductionRawMaterial.Add(raw);
                        _context.SaveChanges();
                        raw = new ProductionRawMaterial();
                    }
                }
            }
            catch (Exception e)
            {
                return(Redirect("~/Production/Index"));
            }

            return(Redirect("~/Production/Index"));
        }