public ActionResult Create(ManufacturerProductViewModel manufacturerProductVM) { using (GoodSupplyEntities db = new GoodSupplyEntities()) { var manufacturerProducts = new ManufacturerProducts { Name = manufacturerProductVM.ManufacturerProducts.Name, CatalogNumber = manufacturerProductVM.ManufacturerProducts.CatalogNumber, ImageUrl = manufacturerProductVM.ManufacturerProducts.ImageUrl, PackageQuantity = manufacturerProductVM.ManufacturerProducts.PackageQuantity, Width = manufacturerProductVM.ManufacturerProducts.Width, Length = manufacturerProductVM.ManufacturerProducts.Length, Height = manufacturerProductVM.ManufacturerProducts.Height, Manufacturers = manufacturerProductVM.ManufacturerProducts.Manufacturers, ManufacturerId = manufacturerProductVM.ManufacturerProducts.ManufacturerId, Products = manufacturerProductVM.ManufacturerProducts.Products, ProductId = manufacturerProductVM.ManufacturerProducts.ProductId }; if (ModelState.IsValid) { db.ManufacturerProducts.Add(manufacturerProducts); db.SaveChanges(); return(RedirectToAction("Index")); } manufacturerProductVM.Manufacturers = db.Manufacturers.ToList(); manufacturerProductVM.Products = db.Products.ToList(); return(View(manufacturerProductVM)); } }
// GET: Details public ActionResult Details(int?id) { using (GoodSupplyEntities db = new GoodSupplyEntities()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ManufacturerProducts manufacturerProducts = db.ManufacturerProducts.Find(id); if (manufacturerProducts == null) { return(HttpNotFound()); } var model = new ManufacturerProductViewModel { ManufacturerProducts = manufacturerProducts, Manufacturers = db.Manufacturers.ToList(), Products = db.Products.ToList() }; return(View(model)); } }
// GET: Create public ActionResult Create() { using (GoodSupplyEntities db = new GoodSupplyEntities()) { var manufacturers = db.Manufacturers.ToList(); var products = db.Products.ToList(); var model = new ManufacturerProductViewModel { Manufacturers = manufacturers, Products = products }; return(View(model)); } }