public ActionResult Edit(TelephoneEditModel model) { if (ModelState.IsValid) { Telephone _telephone = db.Telephones.Find(model.TelephoneId); _telephone.ApplicationUser = um.FindById(model.ApplicationUserId); _telephone.Discarded = model.Discarded; _telephone.EquipmentName = model.EquipmentName; _telephone.LostOrStolen = model.LostOrStolen; _telephone.PurchasePrice = model.PurchasePrice; _telephone.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(); _telephone.Sale = _sale; } db.Entry(_telephone).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); } Telephone _telephone = db.Telephones.Find(id); if (_telephone == null) { return HttpNotFound(); } TelephoneEditModel model = new TelephoneEditModel(_telephone); string selectId = _telephone.ApplicationUser.Id; model.Users = FullNameUserList(db, selectId); return View(model); }