public ActionResult Edit(int id) { var service = CreateLeagueService(); var detail = service.GetLeagueById(id); var model = new LeagueEdit { LeagueId = detail.LeagueId, LeagueName = detail.LeagueName }; return(View(model)); }
public bool UpdateLeague(LeagueEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Leagues .Single(e => e.LeagueId == model.LeagueId); entity.LeagueName = model.LeagueName; return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Put(LeagueEdit model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } LeagueService service = CreateLeagueService(); if (service.UpdateExistingLeague(model)) { return(Ok()); } return(InternalServerError()); }
public bool UpdateExistingLeague(LeagueEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Leagues.FirstOrDefault(league => league.LeagueID == model.LeagueID && league.OwnerID == _userID); if (entity == null) { return(false); } entity.LeagueName = model.LeagueName; return(ctx.SaveChanges() == 1); } }
public bool UpdateLeague(LeagueEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Leagues .SingleOrDefault(e => e.LeagueId == model.LeagueId && e.OwnerId == _userId); entity.LeagueName = model.LeagueName; entity.ZipCode = model.LeagueZipCode; entity.PrivateOrPublic = model.IsPrivate; //Change password here? entity.LeaguePassword = model.Password; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, LeagueEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.LeagueId != id) { ModelState.AddModelError("", "ID mismatch"); return(View(model)); } var service = CreateLeagueService(); if (service.UpdateLeague(model)) { TempData["SaveResult"] = "Your league was updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your league could not be udpated."); return(View()); }