Exemple #1
0
 public bool UpdateVideoGame(VideoGameEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity = ctx.VideoGames.Single(e => e.VideoGameID == model.VideoGameID && e.OwnerID == _vgUserID);
         entity.VideoGameName  = model.VideoGameName;
         entity.VideoGameGenre = model.VideoGameGenre;
         entity.VideoGameNotes = model.VideoGameNotes;
         entity.TimesBeat      = model.TimesBeat;
         return(ctx.SaveChanges() == 1);
     }
 }
        public ActionResult VideoGameEdit(int id)
        {
            var service = CreateVideoGameService();
            var detail  = service.VideoGameDetails(id);
            var model   = new VideoGameEdit
            {
                VideoGameID    = detail.VideoGameID,
                VideoGameName  = detail.VideoGameName,
                VideoGameGenre = detail.VideoGameGenre,
                VideoGameNotes = detail.VideoGameNotes,
                TimesBeat      = detail.TimesBeat
            };

            return(View(model));
        }
Exemple #3
0
        public IHttpActionResult Put(VideoGameEdit videoGame)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateVideoGameService();

            if (!service.UpdateVideoGame(videoGame))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        }// End GetVideoGames by Id

        public bool UpdateVideoGame(VideoGameEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .VideoGames
                    .Single(e => e.GameId == model.GameId);

                entity.GameName           = model.GameName;
                entity.PublishYear        = model.PublishYear;
                entity.AgeRating          = model.AgeRating;
                entity.MaxNumberOfPlayers = model.MaxNumberOfPlayers;
                entity.MinNumberOfPlayers = model.MinNumberOfPlayers;
                entity.TeamGame           = model.TeamGame;
                entity.Genre          = model.Genre;
                entity.ConsoleType    = model.ConsoleType;
                entity.OnlineGamePlay = model.OnlineGamePlay;
                entity.StorageId      = model.StorageId;

                return(ctx.SaveChanges() == 1);
            }
        }// End UpdateVideoGame
        public ActionResult VideoGameEdit(int id, VideoGameEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateVideoGameService();

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

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