public ActionResult Edit(LaptopEditModel model) { if (ModelState.IsValid) { Laptop _laptop = db.Laptops.Find(model.LaptopId); _laptop.ApplicationUser = um.FindById(model.ApplicationUserId); _laptop.Discarded = model.Discarded; _laptop.EquipmentName = model.EquipmentName; _laptop.LostOrStolen = model.LostOrStolen; _laptop.PurchasePrice = model.PurchasePrice; _laptop.SerialNumber = model.SerialNumber; if (model.dtSold != null) { Sale _sale = new Sale { dtSold = (DateTime)model.dtSold, SalePrice = model.SalePrice ?? 0.0 }; db.Sales.Add(_sale); db.SaveChanges(); _laptop.Sale = _sale; } db.Entry(_laptop).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } // Validation failed, reassign the list without assigning anything string selectId = model.ApplicationUserId; model.Users = FullNameUserList(db, selectId); return View(model); }
public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Laptop _laptop = db.Laptops.Find(id); if (_laptop == null) { return HttpNotFound(); } LaptopEditModel model = new LaptopEditModel(_laptop); string selectId = _laptop.ApplicationUser.Id; model.Users = FullNameUserList(db, selectId); return View(model); }