예제 #1
0
        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));
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        public IHttpActionResult Put(LeagueEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            LeagueService service = CreateLeagueService();

            if (service.UpdateExistingLeague(model))
            {
                return(Ok());
            }

            return(InternalServerError());
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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());
        }