public ActionResult Edit(int id, TitleEdit model) { if (!ModelState.IsValid) { var wrestlerList = new WrestlerRepo(); model.Wrestlers = wrestlerList.GetWrestlers(); return(View(model)); } if (model.TitleId != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateTitleService(); if (service.UpdateTitle(model)) { TempData["SaveResult"] = "The title has been updated!"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The title could not be updated."); return(View(model)); }
public bool UpdateTitle(TitleEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Titles.Single(e => e.Id == model.TitleId && e.OwnerId == _userId); entity.Id = model.TitleId; entity.TitleName = model.TitleName; //entity.IsStarred = model.IsStarred; entity.DateEstablished = model.DateEstablished; entity.WrestlerId = model.WrestlerId; return(ctx.SaveChanges() == 1); } }
//GET: Edit public ActionResult Edit(int id) { var service = CreateTitleService(); var detail = service.GetTitleById(id); var wrestlerList = new WrestlerRepo(); var model = new TitleEdit { TitleId = detail.TitleId, TitleName = detail.TitleName, //IsStarred = detail.IsStarred, DateEstablished = detail.DateEstablished, WrestlerId = detail.WrestlerId }; model.Wrestlers = wrestlerList.GetWrestlers(); return(View(model)); }
private bool SetStarState(int titleId, bool newState) { //Create the Service var userId = Guid.Parse(User.Identity.GetUserId()); var service = new TitleService(userId); //Get the Title var detail = service.GetTitleById(titleId); //Creat the TitleEdit model instance with the new state var updatedTitle = new TitleEdit { TitleId = detail.TitleId, TitleName = detail.TitleName, //IsStarred = newState, DateEstablished = detail.DateEstablished, WrestlerId = detail.WrestlerId }; //Return a value indicating whether the update succeeded or not return(service.UpdateTitle(updatedTitle)); }