public ActionResult DeleteConfirmed(int supplierId, int partId) { SupplierPart supplierpart = db.SupplierParts.Where(sp => sp.partId == partId && sp.supplierId == supplierId).FirstOrDefault(); db.SupplierParts.Remove(supplierpart); db.SaveChanges(); //Find the Part var part = db.Parts.Find(supplierpart.partId); //Obtain the average price var average = (decimal?)db.SupplierParts.Where(sp => sp.partId == supplierpart.partId && sp.supplierId != CarPartReconstructionId).Average(sp => (decimal?)sp.price); if (average != null) { //Verify if the difference between reference price and the average of the suppliers prices exceed the five percent var twoPercent = (decimal)(part.partPrice * 0.02m); if (Math.Abs((decimal)(part.partPrice - average)) > twoPercent) { var referencePrice = part.partPrice; part.partPrice = Math.Round((decimal)average, 2); return(RedirectToAction("UpdatePartPrice", new { partId = part.partId, supplierId = supplierpart.supplierId, averagePrice = average })); } } return(RedirectToAction("Index", new { SupplierId = supplierpart.supplierId })); }
// // GET: /SupplierPart/Details/5 public ActionResult Details(int supplierId, int partId) { SupplierPart supplierpart = db.SupplierParts.Where(sp => sp.partId == partId && sp.supplierId == supplierId).FirstOrDefault(); if (supplierpart == null) { return(HttpNotFound()); } return(View(supplierpart)); }
// // GET: /SupplierPart/Create public ActionResult Create(int supplierId) { var model = new SupplierPart() { supplierId = supplierId }; ViewBag.partId = new SelectList( db.Parts.Where(pa => !db.SupplierParts.Any(sp => sp.supplierId == supplierId && sp.partId == pa.partId)) , "partId", "partName"); ViewBag.supplierId = new SelectList( db.Suppliers.Where(su => su.supplierId == supplierId), "supplierId", "supplierName", supplierId); return(View(model)); }
// // GET: /SupplierPart/Edit/5 public ActionResult Edit(int supplierId, int partId) { SupplierPart supplierpart = db.SupplierParts.Where(sp => sp.partId == partId && sp.supplierId == supplierId).FirstOrDefault(); if (supplierpart == null) { return(HttpNotFound()); } ViewBag.partId = new SelectList( db.Parts.Where(pa => pa.partId == partId || !db.SupplierParts.Any(sp => sp.supplierId == supplierpart.supplierId && sp.partId == pa.partId)) , "partId", "partName", supplierpart.partId); ViewBag.supplierId = new SelectList( db.Suppliers.Where(su => su.supplierId == supplierpart.supplierId), "supplierId", "supplierName", supplierpart.supplierId); return(View(supplierpart)); }
//----------------------------------------------------------------------------------------------------- private bool CheckSuppliersExists(SupplierPart supplierpart) { //check to find out a supplier exists for all parts in the list foreach (PartsInTheOrder2 item in partList2) { supplierpart.PartId = item.PartID; supplierpart.SupplierId = item.SupplierID; DataTable dt = supplierpart.GetSupplierPartsId().Tables[0]; if (dt.Rows.Count == 0) { DialogResult dlgResult = MessageBox.Show ("Please choose a supplier for all the parts in the order", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } return(true); }
public ActionResult Edit(SupplierPart supplierpart) { if (ModelState.IsValid) { db.Entry(supplierpart).State = EntityState.Modified; db.SaveChanges(); //Find the Part var part = db.Parts.Find(supplierpart.partId); //Obtain the average price var average = (decimal?)db.SupplierParts.Where(sp => sp.partId == supplierpart.partId && sp.supplierId != CarPartReconstructionId).Average(sp => (decimal?)sp.price); if (average != null) { //Verify if the difference between reference price and the average of the suppliers prices exceed the five percent var twoPercent = (decimal)(part.partPrice * 0.02m); if (Math.Abs((decimal)(part.partPrice - average)) > twoPercent) { var referencePrice = part.partPrice; part.partPrice = Math.Round((decimal)average, 2); return(RedirectToAction("UpdatePartPrice", new { partId = part.partId, supplierId = supplierpart.supplierId, averagePrice = average })); } } return(RedirectToAction("Index", new { SupplierId = supplierpart.supplierId })); } ViewBag.partId = new SelectList( db.Parts.Where(pa => pa.partId == supplierpart.partId || !db.SupplierParts.Any(sp => sp.supplierId == supplierpart.supplierId && sp.partId == pa.partId)) , "partId", "partName", supplierpart.partId); ViewBag.supplierId = new SelectList( db.Suppliers.Where(su => su.supplierId == supplierpart.supplierId), "supplierId", "supplierName", supplierpart.supplierId); return(View(supplierpart)); }
public void SeedDatabase() { _db.Database.EnsureCreated(); // Check if the database was already seeded if (_db.Suppliers.Any()) { return; } var suppliers = new Supplier[] { new Supplier { Name = "Acme" }, new Supplier { Name = "Zappo" }, new Supplier { Name = "Creepy" } }; _db.Suppliers.AddRange(suppliers); _db.SaveChanges(); var parts = new Part[] { new Part { Name = "Catapult" }, new Part { Name = "Zipper" }, new Part { Name = "Nail" }, new Part { Name = "Screw" } }; _db.Parts.AddRange(parts); _db.SaveChanges(); var supplier = _db.Suppliers.First(s => s.Name == "Acme"); var part = _db.Parts.First(p => p.Name == "Catapult"); var supplierPart = new SupplierPart { SupplierId = supplier.Id, PartId = part.Id, Price = 200.0m }; _db.SupplierParts.Add(supplierPart); part = _db.Parts.First(p => p.Name == "Nail"); supplierPart = new SupplierPart { SupplierId = supplier.Id, PartId = part.Id, Price = 12.0m }; _db.SupplierParts.Add(supplierPart); supplier = _db.Suppliers.First(s => s.Name == "Zappo"); part = _db.Parts.First(p => p.Name == "Zipper"); supplierPart = new SupplierPart { SupplierId = supplier.Id, PartId = part.Id, Price = 2.0m }; _db.SupplierParts.Add(supplierPart); part = _db.Parts.First(p => p.Name == "Nail"); supplierPart = new SupplierPart { SupplierId = supplier.Id, PartId = part.Id, Price = 8.0m }; _db.SupplierParts.Add(supplierPart); part = _db.Parts.First(p => p.Name == "Screw"); supplierPart = new SupplierPart { SupplierId = supplier.Id, PartId = part.Id, Price = 8.0m }; _db.SupplierParts.Add(supplierPart); _db.SaveChanges(); }