public ActionResult OrderRawMaterial(OrderRawMaterial orderRawMaterial, int id)
        {
            var concernId = Convert.ToInt32(Session["ConcernId"]);
            var userId    = Convert.ToInt32(Session["UserId"]);

            if (concernId > 0 && userId > 0)
            {
                var     code     = orderRawMaterial.ProductId + "" + orderRawMaterial.ArticleId + "" + orderRawMaterial.WidthId + "" + orderRawMaterial.ConstructionId + "" + orderRawMaterial.SoftnessId + "" + orderRawMaterial.SourceId + "" + orderRawMaterial.ColorId;
                var     quantity = _stock.GeneralStocks();
                decimal value    = 0;
                foreach (var item in quantity)
                {
                    if (item.ProductCode == code)
                    {
                        value = item.Quantity;
                    }
                }
                if (value >= orderRawMaterial.Quantity)
                {
                    _production.AddOrderRawMaterial(orderRawMaterial, concernId, userId, id);
                    _production.ProductionChange(id);
                    return(RedirectToAction(nameof(ProductionProces)));
                }
                else
                {
                    TempData["sort"] = "your stock is short";
                    return(RedirectToAction(nameof(ProductionOrder)));
                }
            }
            return(RedirectToAction("LogIn", "GlobalData", new { Area = "Global" }));
        }
        public void AddOrderRawMaterial(OrderRawMaterial orderRawMaterial, int concernId, int userId, int orderId)
        {
            var code        = orderRawMaterial.ProductId + "" + orderRawMaterial.ArticleId + "" + orderRawMaterial.WidthId + "" + orderRawMaterial.ConstructionId + "" + orderRawMaterial.SoftnessId + "" + orderRawMaterial.SourceId + "" + orderRawMaterial.ColorId;
            var productCode = _context.ProductNames.FirstOrDefault(m => m.ProductCode == code);

            using (DbContextTransaction transaction = _context.Database.BeginTransaction())
            {
                if (productCode == null)
                {
                    ProductName product = new ProductName();
                    product.ProductCode    = code;
                    product.ProductId      = orderRawMaterial.ProductId;
                    product.ArticleId      = orderRawMaterial.ArticleId;
                    product.WidthId        = orderRawMaterial.WidthId;
                    product.ConstructionId = orderRawMaterial.ConstructionId;
                    product.SoftnessId     = orderRawMaterial.SoftnessId;
                    product.SourceId       = orderRawMaterial.SourceId;
                    product.ColorId        = orderRawMaterial.ColorId;
                    _context.ProductNames.Add(product);
                    _context.SaveChanges();

                    orderRawMaterial.ConcernId    = concernId;
                    orderRawMaterial.ProductCode  = code;
                    orderRawMaterial.Creator      = userId;
                    orderRawMaterial.CreationDate = DateTime.Now;
                    orderRawMaterial.OrderId      = orderId;
                    _context.OrderRawMaterials.Add(orderRawMaterial);
                    _context.SaveChanges();

                    transaction.Commit();
                }
                else
                {
                    orderRawMaterial.ConcernId    = concernId;
                    orderRawMaterial.ProductCode  = code;
                    orderRawMaterial.Creator      = userId;
                    orderRawMaterial.CreationDate = DateTime.Now;
                    orderRawMaterial.OrderId      = orderId;
                    _context.OrderRawMaterials.Add(orderRawMaterial);
                    _context.SaveChanges();

                    transaction.Commit();
                }
            }
        }