public ActionResult DeleteProperty(int id) { using (var db = new ApplicationDbContext()) { var property = db.Properties.FirstOrDefault(x => x.Id == id); if (property == null) { return(HttpNotFound()); } var model = new PropertyDeleteModel { Id = property.Id, Address = property.Address }; return(View(nameof(DeleteProperty), model)); } }
public ActionResult DeleteProperty(int id, PropertyDeleteModel model) { if (ModelState.IsValid) { using (var db = new ApplicationDbContext()) { var property = db.Properties.FirstOrDefault(x => x.Id == model.Id); if (property == null) { return(HttpNotFound()); } db.Properties.Remove(property); db.SaveChanges(); } return(RedirectToAction(nameof(ListProperties))); } return(View(nameof(DeleteProperty), model)); }