Exemplo n.º 1
0
        public IActionResult Create(BoardGameEdit boardGameEdit)
        {
            BoardGame newBoardGame = new BoardGame
            {
                Name        = boardGameEdit.Name,
                Genre       = boardGameEdit.Genre,
                Description = boardGameEdit.Description,
                MinPlayers  = boardGameEdit.MinPlayers,
                MaxPlayers  = boardGameEdit.MaxPlayers,
            };

            newBoardGame = _boardGameData.CreateBoardGame(newBoardGame);

            return(View("BoardGameDetails", newBoardGame));
        }
        }//end of method get by id

        //edit existing boardGaem in database

        public IHttpActionResult Put(BoardGameEdit boardGame)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }//end of if model is not valid

            var service = new BoardGameService();

            if (!service.UpdateBoardGame(boardGame))
            {
                return(InternalServerError());
            }//end of if unable to update the boardGame

            //if we get here... good!
            return(Ok());
        }//end of method put to change existing boardGame
Exemplo n.º 3
0
        }//end of get board game by id

        //method to edit existing BoardGame in database
        public bool UpdateBoardGame(BoardGameEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx.BoardGames
                    .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.AveragePlayTimeMin = model.AveragePlayTimeMin;
                entity.GameBoardType      = model.GameBoardType;
                entity.StorageId          = model.StorageId;

                return(ctx.SaveChanges() == 1);
            } //end of using
        }     //end of method UpdateBoardGame