Ejemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var service = CreateGameReviewService();
            var detail  = service.GetGameReviewById(id);
            var model   =
                new GameReviewEdit
            {
                GameReviewId    = detail.GameReviewId,
                GameTitle       = detail.GameTitle,
                GameDeveloper   = detail.GameDeveloper,
                Platform        = detail.Platform,
                GameGenre       = detail.GameGenre,
                GameReleaseYear = detail.GameReleaseYear,
                GameMania       = detail.GameMania,
                GameRating      = detail.GameRating
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public bool UpdateGameReview(GameReviewEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .GameReviews
                    .Single(e => e.GameReviewId == model.GameReviewId && e.OwnerId == _userId);

                entity.GameTitle       = model.GameTitle;
                entity.GameDeveloper   = model.GameDeveloper;
                entity.Platform        = model.Platform;
                entity.GameGenre       = model.GameGenre;
                entity.GameReleaseYear = model.GameReleaseYear;
                entity.GameStance      = model.GameStance;
                entity.GameRating      = model.GameRating;

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

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

            var service = CreateGameReviewService();

            if (service.UpdateGameReview(model))
            {
                TempData["SaveResult"] = "Your review has been successfully updated";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your review could not be updated at this time");
            return(View(model));
        }