예제 #1
0
        public IHttpActionResult Update(int id, [FromBody] PCUpdateModel game)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _pcService = new PCGameService();
            _pcService.UpdatePCGame(id, game);

            return(Ok());
        }
예제 #2
0
        public void UpdatePCGame(int id, PCUpdateModel pcGameToUpdate)
        {
            using (var ctx = new ApplicationDbContext())
            {
                PCGame pcGameWeWantToUpdate = ctx.PCGames.Single(x => x.PCGameId == pcGameToUpdate.PCGameId);

                if (pcGameToUpdate != null)
                {
                    pcGameWeWantToUpdate.Title  = pcGameToUpdate.Title;
                    pcGameWeWantToUpdate.Price  = pcGameToUpdate.Price;
                    pcGameWeWantToUpdate.Rating = pcGameToUpdate.Rating;

                    ctx.SaveChanges();
                }
            }
        }
예제 #3
0
        public void UpdatePCGame(int id, PCUpdateModel pcGameToUpdate)
        {
            using (var ctx = new ApplicationDbContext())
            {
                PCGame pcGameWeWantToUpdate = ctx.PCGames.Find(pcGameToUpdate.Title);

                if (pcGameToUpdate != null)
                {
                    pcGameWeWantToUpdate.Title          = pcGameToUpdate.Title;
                    pcGameWeWantToUpdate.Price          = pcGameToUpdate.Price;
                    pcGameWeWantToUpdate.Genre          = pcGameToUpdate.Genre;
                    pcGameWeWantToUpdate.MaturityRating = pcGameToUpdate.MaturityRating;
                    pcGameWeWantToUpdate.Rating         = pcGameToUpdate.Rating;
                    pcGameWeWantToUpdate.Publisher      = pcGameToUpdate.Publisher;
                    pcGameWeWantToUpdate.Developer      = pcGameToUpdate.Developer;

                    ctx.SaveChanges();
                }
            }
        }