Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var service = CreateWeekService();
            var detail  = service.GetWeekById(id);
            var model   =
                new WeekEdit
            {
                WeekId       = detail.WeekId,
                SeasonNumber = detail.SeasonNumber,
                SeasonWeek   = detail.SeasonWeek,
                StadiumName  = detail.StadiumName,
                PlayerId     = detail.PlayerId,
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public bool UpdateWeek(WeekEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Weeks
                    .Single(e => e.WeekId == model.WeekId && e.OwnerId == _userId);

                entity.SeasonNumber = model.SeasonNumber;
                entity.SeasonWeek   = model.SeasonWeek;
                entity.StadiumName  = model.StadiumName;
                entity.PlayerId     = model.PlayerId;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id, WeekEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.WeekId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateWeekService();

            if (service.UpdateWeek(model))
            {
                TempData["SaveResult"] = "Your week was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your week could not be updated.");
            return(View(model));
        }