public ActionResult Edit(string id) { var product = _context.WarehouseProducts.SingleOrDefault(p => p.PId == id); var stock = _context.WarehouseStocks.SingleOrDefault(s => s.ProductID == id); if (product == null) { return(HttpNotFound()); } var warehouseProductJoin = new WarehouseProductJoin(); if (stock == null) { int quantity = 0; warehouseProductJoin.Wproducts = product; WarehouseStock warehouseStock = new WarehouseStock(); warehouseStock.Quantity = quantity; warehouseStock.ShelveNo = "N/A"; warehouseProductJoin.WStock = warehouseStock; } else { warehouseProductJoin.Wproducts = product; warehouseProductJoin.WStock = stock; } return(View(warehouseProductJoin)); }
public ActionResult AddProduct(WarehouseProductJoin warehouseProductJoin) { var products = new WarehouseProduct(); var stock = new WarehouseStock(); products.PId = warehouseProductJoin.Wproducts.PId.ToUpper(); products.Name = warehouseProductJoin.Wproducts.Name; products.Price = warehouseProductJoin.Wproducts.Price; products.Type = Request.Form["PType"]; products.Category = Request.Form["PCategory"]; products.Description = warehouseProductJoin.Wproducts.Description; stock.ProductID = warehouseProductJoin.Wproducts.PId; stock.Quantity = warehouseProductJoin.WStock.Quantity; stock.ShelveNo = warehouseProductJoin.WStock.ShelveNo; try { _context.WarehouseProducts.Add(products); _context.WarehouseStocks.Add(stock); _context.SaveChanges(); } catch { return(View()); } return(Redirect("~/Warehouse/Index")); }
public ActionResult Update(WarehouseProductJoin warehouseProductJoin) { var productInDb = _context.WarehouseProducts.Single(p => p.PId == warehouseProductJoin.Wproducts.PId); var stockInDb = _context.WarehouseStocks.Single(s => s.ProductID == warehouseProductJoin.Wproducts.PId); productInDb.PId = warehouseProductJoin.Wproducts.PId; productInDb.Name = warehouseProductJoin.Wproducts.Name; productInDb.Price = warehouseProductJoin.Wproducts.Price; productInDb.Type = Request.Form["PType"]; productInDb.Category = Request.Form["PCategory"]; productInDb.Description = warehouseProductJoin.Wproducts.Description; stockInDb.Quantity = warehouseProductJoin.WStock.Quantity; stockInDb.ShelveNo = warehouseProductJoin.WStock.ShelveNo; _context.SaveChanges(); return(Redirect("~/Warehouse/Index")); }