Ejemplo n.º 1
0
        public Task <Game> SaveGame(GameCreationRequest game)
        {
            return(gamestakDb.Use(async conn =>
            {
                var query = @$ "
                    IF NOT EXISTS (SELECT GameID FROM {DbTables.Games} WHERE Title = @Title)
                    BEGIN
	                    INSERT INTO {DbTables.Games} (Title, Publisher, [Description], Price, DiscountRate, ReleaseDate, ThumbnailUrl)
	                    VALUES (@Title, @Publisher, @Description, @Price, @DiscountRate, @ReleaseDate, @ThumbnailUrl)
                    END
                ";

                var selectQuery = $@"SELECT * FROM {DbTables.Games} WHERE Title = @Title";

                var rowsAffected = await conn.ExecuteAsync(query, game);

                if (rowsAffected < 0)
                {
                    throw new ArgumentException("Game object already exists or is invalid");
                }

                var result = (await conn.QueryAsync <Game>(selectQuery, game)).FirstOrDefault();

                return result;
            }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SaveGame(GameCreationRequest game)
        {
            try
            {
                var result = await gameService.SaveGame(game);

                return(Ok(result));
            }
            catch (ArgumentException e)
            {
                return(new BadRequestResult());
            }
            catch (Exception e)
            {
                return(new StatusCodeResult(500));
            }
        }
Ejemplo n.º 3
0
        public async Task <Game> SaveGame(GameCreationRequest game)
        {
            try
            {
                var savedGame = await gameRepository.SaveGame(game);

                var savedImages = await gameRepository.SaveGameImages(savedGame.GameID, game.ImageCollection);

                var savedCategories = await gameRepository.AssignGameCategories(savedGame.GameID, game.Categories);

                var savedFeatures = await gameRepository.AssignGameFeatures(savedGame.GameID, game.Features);

                savedGame.ImageCollection = savedImages;
                savedGame.Categories      = savedCategories;
                savedGame.Features        = savedFeatures;

                return(savedGame);
            }
            catch (Exception e)
            {
                logger.LogError(e, "Error Saving a Game to the DB");
                throw e;
            }
        }