Пример #1
0
        public async Task <IActionResult> Put(long id, CreateTovelundGameRequest request)
        {
            try
            {
                var game = await _context.TovelundGames.FindAsync(id);

                if (game == null)
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, new { title = "game not found" }));
                }

                game.Design = request.Design;
                game.Title  = request.Title;

                await _context.SaveChangesAsync();

                return(StatusCode(StatusCodes.Status200OK));
            }
            catch (Exception exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { title = exception.Message }));
            }
        }
Пример #2
0
        public async Task <IActionResult> Post(CreateTovelundGameRequest request)
        {
            try
            {
                var game = new TovelundGame
                {
                    Title  = request.Title,
                    Design = request.Design
                };

                _context.Add(game);

                await _context.SaveChangesAsync();

                return(StatusCode(StatusCodes.Status200OK, new
                {
                    GameId = game.Id
                }));
            }
            catch (Exception exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { title = exception.Message }));
            }
        }