public ActionResult AddNewProduct(ProductRequestModel product, HttpPostedFileBase image) { var path = Request.MapPath("~/Content/" + product.categoryId); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var filePath = Path.Combine(path, Path.GetFileName(image.FileName)); try { image.SaveAs(filePath); } catch { throw new Exception(); } string imgPath = filePath.Substring(path.IndexOf("\\Content")); string RealPath = imgPath.Replace("\\", "/"); Product p = new Product() { CategoryId = product.categoryId, IsOnSale = false, ProductionDate = product.productionTime, ProviderId = product.provider, Url = RealPath, KeepDate = product.keepTime, Price = product.price, ProductName = product.productName }; long productId = _productRepository.AddProduct(p); //Add to ProductInFactory table ProductInFactory productInFactory = new ProductInFactory() { Amount = product.productCount, InDate = DateTime.UtcNow, Price = Convert.ToString(p.Price), }; long productInFactoryId = _inventoryRepository.AddProductInFactory(productInFactory); //Add to Inventory table Inventory inventory = new Inventory() { Amount = product.productCount, ProductId = productId, WarehouseId = product.warehouse, }; long inventoryId = _inventoryRepository.AddInventory(inventory); //Add InventoryAction InventoryAction inventoryAction = new InventoryAction() { InventoryId = inventoryId, ProductInFactoryId = productInFactoryId }; _inventoryRepository.AddInventoryAction(inventoryAction); //Add to Discount table Discount discount = new Discount() { Discounts = Constants.DEFAULTDISCOUNT, IsUsed = false, ProductId = productId, StartTime = DateTime.UtcNow, EndTime = DateTime.UtcNow }; _discountRepository.AddProductDiscount(discount); //InventoryProductListViewModel productViewModel = GetInventoryProducts(null,null); return(RedirectToAction("GetAllInventoryProduct", "Inventory")); }