public ActionResult Edit(int id, WrestlerEdit model) { if (!ModelState.IsValid) { var promotionList = new PromotionRepo(); model.Promotions = promotionList.GetPromotions(); return(View(model)); } if (model.WrestlerId != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateWrestlerService(); if (service.UpdateWrestler(model)) { TempData["SaveResult"] = "The wrestler has been updated!"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The wrestler could not be updated."); return(View(model)); }
private bool SetStarState(int wrestlerId, bool newState) { //Create the Service var userId = Guid.Parse(User.Identity.GetUserId()); var service = new WrestlerService(userId); //Get the Wrestler var detail = service.GetWrestlerById(wrestlerId); //Create the WrestlerEdit model instance with the new star state var updatedWrestler = new WrestlerEdit { WrestlerId = detail.WrestlerId, RingName = detail.RingName, IsStarred = newState, Gender = detail.Gender, PromotionId = detail.PromotionId, PromotionName = detail.PromotionName, Promotions = detail.Promotions, Wins = detail.Wins, Losses = detail.Losses }; //Return a value indicating whether the update succeeded or not return(service.UpdateWrestler(updatedWrestler)); }
public bool UpdateWrestler(WrestlerEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Wrestlers.Single(e => e.WrestlerId == model.WrestlerId && e.OwnerId == _userId); entity.RingName = model.RingName; entity.IsStarred = model.IsStarred; entity.Gender = model.Gender; entity.PromotionId = model.PromotionId; entity.Wins = model.Wins; entity.Losses = model.Losses; return(ctx.SaveChanges() == 1); } }
//GET: Edit //Possible error on Promo ID public ActionResult Edit(int id) { var service = CreateWrestlerService(); var detail = service.GetWrestlerById(id); var promotionList = new PromotionRepo(); var model = new WrestlerEdit { WrestlerId = detail.WrestlerId, RingName = detail.RingName, Gender = detail.Gender, PromotionId = detail.PromotionId, Wins = detail.Wins, Losses = detail.Losses, }; model.Promotions = promotionList.GetPromotions(); return(View(model)); }