public bool UpdateGameEvent(GameEventEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.GameEvents.Single(e => e.ID == model.ID && e.OwnerID == _userID); entity.TypeOfEvent = GetEventTypeFromString(model.TypeOfEvent); entity.Name = model.Name; entity.Description = model.Description; return(ctx.SaveChanges() == 1); } }
// GET: GameEvent/Edit/5 public ActionResult Edit(int id) { var service = CreateGameEventService(); var detail = service.GetGameEventByID(id, false); var model = new GameEventEdit { ID = detail.ID, BlockID = detail.BlockID, MapID = detail.MapID, Creator = detail.Creator, TypeOfEvent = detail.TypeOfEvent, Name = detail.Name, Description = detail.Description }; return(View(model)); }
public ActionResult Edit(int id, GameEventEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ID != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateGameEventService(); if (service.UpdateGameEvent(model)) { TempData["SaveResult"] = "The event was updated succesfully."; return(RedirectToAction("Details", "Block", new { id = model.BlockID })); } ModelState.AddModelError("", "Your event could not be updated."); return(View(model)); }