public ActionResult DeleteConfirmed(detailsEventViewModel model) { var @event = db.Events.FirstOrDefault(x => x.Id == model.Id); if (ModelState.IsValid) { @event.Title = model.Title; @event.StartDate = model.StartDate; @event.Description = model.Description; @event.Address.Street = model.Street; @event.Address.City = model.City; @event.Address.State = model.State; @event.Address.ZipCode = model.ZipCode; if (User.Identity.GetUserId() == @event.ApplicationUserId) { db.Entry(@event).State = EntityState.Deleted; db.SaveChanges(); // create message telling user changes have been saved } else { ViewBag.noDelete = "Only the event organizer can delete the event."; } } return RedirectToAction("home", "Dashboard", "Dashboard"); }
// GET: Events/Delete/5 public ActionResult Delete(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var @event = db.Events.Include(x => x.Address).SingleOrDefault(x => x.Id == id.Value); if (@event == null) { return HttpNotFound(); } var myViewModel = new detailsEventViewModel { Id = @event.Id, StartDate = @event.StartDate, Title = @event.Title, Description = @event.Description, ApplicationUserId = User.Identity.GetUserId(), AddressId = @event.Address.Id, Street = @event.Address.Street, City = @event.Address.City, State = @event.Address.State, ZipCode = @event.Address.ZipCode }; return View(myViewModel); }