Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var service          = CreateGameNightService();
            var detail           = service.GetGameNightById(id);
            var userId           = Guid.Parse(User.Identity.GetUserId());
            var gatheringService = new GameService(userId);
            var gameList         = gatheringService.GetGames();
            var gamerId          = Guid.Parse(User.Identity.GetUserId());
            var gettingService   = new GamerService(gamerId);
            var gamerList        = gettingService.GetGamers();
            var model            =
                new GameNightEdit
            {
                GameTimeId    = detail.GameTimeId,
                GameId        = detail.GameId,
                DateTime      = detail.DateTime,
                Location      = detail.Location,
                NoobsAllowed  = detail.NoobsAllowed,
                Description   = detail.Description,
                TutorialVideo = detail.TutorialVideo,
                GamerTag      = detail.GamerTag
            };

            ViewBag.GameId   = new SelectList(gameList, "GameId", "Title");
            ViewBag.GamerTag = new SelectList(gamerList, "GamerTag", "GamerTag");

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id, GameNightEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateGameNightService();

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

            ModelState.AddModelError("", "Your GameTime could not be updated. Try again.");

            return(View());
        }
Exemplo n.º 3
0
        public IHttpActionResult Put(GameNightEdit gameNight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateGameNightService();

            if (!service.UpdateGameNight(gameNight))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Exemplo n.º 4
0
        public bool UpdateGameNight(GameNightEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .GameTimes
                    .Single(e => e.GameTimeId == model.GameTimeId && e.OwnerId == _userId);

                entity.GameId        = model.GameId;
                entity.DateTime      = model.DateTime;
                entity.Location      = model.Location;
                entity.NoobsAllowed  = model.NoobsAllowed;
                entity.Description   = model.Description;
                entity.TutorialVideo = model.TutorialVideo;
                entity.GamerTag      = model.GamerTag;

                return(ctx.SaveChanges() == 1);
            }
        }