Exemplo n.º 1
0
        public async Task AddVideoAsync(VideoAddModel video)
        {
            var validator = DataValidatorHelper.Validate(video);

            if (validator.IsValid)
            {
                var videoDB = await _gamedbAccess.GetVideoByTitleAsync(video.Title, video.GameId);

                if (videoDB == null)
                {
                    if (video.MP4 != null)
                    {
                        video.MP4Id = await _gamedbAccess.AddVideoContentAsync(video.MP4);
                    }

                    if (video.Webm != null)
                    {
                        video.WebmId = await _gamedbAccess.AddVideoContentAsync(video.Webm);
                    }

                    await _gamedbAccess.AddVideoAsync(video);
                }
            }
            else
            {
                Console.WriteLine($"Invalid Data from {nameof(VideoAddModel)}");
                validator.Errors.ForEach(e => Console.WriteLine(e));

                throw new Exception("Some data are invalid");
            }
        }
Exemplo n.º 2
0
        public async Task <int> AddDLC(DLCAddModel dLC)
        {
            var validator = DataValidatorHelper.Validate(dLC);

            if (validator.IsValid)
            {
                var dlcDb = await _gamedbAccess.GetDLCBySteamAppIdAsync(dLC.SteamAppId);

                if (dlcDb == null)
                {
                    var dlcTitle = await _gamedbAccess.GetDLCTitleBySteamAppId(dLC.SteamAppId);

                    if (dlcTitle != null)
                    {
                        dLC.Title = dlcTitle;
                    }

                    return(await _gamedbAccess.AddDLCAsync(dLC));
                }

                return(dlcDb.DLCId);
            }

            Console.WriteLine($"Invalid Data from {nameof(DLCAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }
Exemplo n.º 3
0
        public async Task <int> AddFullGameAsync(FullGameAddModel game)
        {
            var validator = DataValidatorHelper.Validate(game);

            if (validator.IsValid)
            {
                var gameDB = await _gamedbAccess.GetGameByTitleAsync(game.Title);

                if (gameDB == null)
                {
                    Console.WriteLine($"{game.Title} has been added");

                    var releaseDateID = await AddReleaseDate(game.ReleaseDate);

                    var steamAppID = await AddSteamApp(game.steamApp);

                    game.SteamAppId    = steamAppID;
                    game.ReleaseDateId = releaseDateID;

                    return(await _gamedbAccess.AddFullGameAsync(game));
                }

                if (gameDB.ReleaseDateID == null || gameDB.ReleaseDateID == 0)
                {
                    var releaseDateID = await AddReleaseDate(game.ReleaseDate);

                    AddReleaseDateToGameAsync(new ReleaseDateToGameModel
                    {
                        GameId = gameDB.GameID, ReleaseDateId = releaseDateID
                    });
                }
                else
                {
                    // check if release date is correct
                    await ValidateReleaseDate(gameDB.ReleaseDateID, game.ReleaseDate);
                }

                if (gameDB.SteamAppId == null || gameDB.SteamAppId == 0)
                {
                    var steamAppId = await AddSteamApp(game.steamApp);

                    AddSteamAppToGameAsync(new SteamAppToGameModel
                    {
                        GameId = gameDB.GameID, SteamAppId = steamAppId
                    });
                }

                return(gameDB.GameID);
            }

            Console.WriteLine($"Invalid Data from {nameof(FullGameAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }
Exemplo n.º 4
0
        public async void AddReleaseDateToGameAsync(ReleaseDateToGameModel releaseDateToGameModel)
        {
            var validator = DataValidatorHelper.Validate(releaseDateToGameModel);

            if (validator.IsValid)
            {
                _gamedbAccess.AddReleaseDateToGameAsync(releaseDateToGameModel);
            }
            else
            {
                Console.WriteLine($"Invalid Data from {nameof(ReleaseDateToGameModel)}");
                validator.Errors.ForEach(e => Console.WriteLine(e));

                throw new Exception("Some data are invalid");
            }
        }
Exemplo n.º 5
0
        // would need to do validation if the game/release date exist in db
        public async void UpdateReleaseDate(ReleaseDateUpdateModel releaseDateUpdate)
        {
            var validator = DataValidatorHelper.Validate(releaseDateUpdate);

            if (validator.IsValid)
            {
                _releaseDateDBAccess.UpdateReleaseDateAsync(releaseDateUpdate);
            }
            else
            {
                Console.WriteLine($"Invalid Data from {nameof(SteamAppToGameModel)}");
                validator.Errors.ForEach(e => Console.WriteLine(e));

                throw new Exception("Some data are invalid");
            }
        }
Exemplo n.º 6
0
        public async Task <int> AddDealDate(DealDateAddModel deal)
        {
            var validator = DataValidatorHelper.Validate(deal);


            if (validator.IsValid)
            {
                return(await _gamedbAccess.AddDealDateAsync(deal));
            }


            Console.WriteLine($"Invalid Data from {nameof(StoreAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }
Exemplo n.º 7
0
        public async Task AddGameDLC(GameDLCAddModel gameDLC)
        {
            var validator = DataValidatorHelper.Validate(gameDLC);

            if (validator.IsValid)
            {
                var dlcID = await AddDLC(gameDLC.DLC);

                var gameDLCDB = await _gamedbAccess.GetGameDLCByGameIdAndDlcIdAsync(gameDLC.GameId, dlcID);

                if (gameDLCDB == null)
                {
                    gameDLC.DLCId = dlcID;

                    await _gamedbAccess.AddGameDLCAsync(gameDLC);
                }
            }
        }
Exemplo n.º 8
0
        public async Task <int> AddPriceOverview(PriceOverviewAddModel priceOverview)
        {
            var validator = DataValidatorHelper.Validate(priceOverview);


            if (validator.IsValid)
            {
                priceOverview.CurrencyId = await AddCurrency(priceOverview.Currency);


                return(await _gamedbAccess.AddPriceOverviewAsync(priceOverview));
            }


            Console.WriteLine($"Invalid Data from {nameof(PriceOverviewAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }
Exemplo n.º 9
0
        public async Task <int> AddGameDeal(GameDealAddModel gameDeal)
        {
            var validator = DataValidatorHelper.Validate(gameDeal);


            if (validator.IsValid)
            {
                var storeId = await AddStore(gameDeal.Store);


                var gameDealDb = await _gamedbAccess.GetGameDealNotExpiredByStoreIdAsync
                                     (gameDeal.GameId, storeId);

                if (gameDealDb == null)
                {
                    gameDeal.DealDateId = await AddDealDate(gameDeal.DealDate);

                    gameDeal.StoreId = storeId;

                    if (gameDeal.PriceOverview != null)
                    {
                        gameDeal.PriceOverviewId = await AddPriceOverview(gameDeal.PriceOverview);
                    }


                    return(await _gamedbAccess.AddGameDealAsync(gameDeal));
                }

                if (gameDealDb.PriceOverviewId != null)
                {
                    UpdatePriceOverview(gameDealDb, gameDeal);
                }

                return(gameDealDb.GameId);
            }


            Console.WriteLine($"Invalid Data from {nameof(GameDealAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }
Exemplo n.º 10
0
        public async Task ValidateReleaseDate(int?releaseDateID, ReleaseDateAddModel releaseDate)
        {
            var validator = DataValidatorHelper.Validate(releaseDate);

            if (validator.IsValid)
            {
                if (releaseDateID != null || releaseDateID != 0)
                {
                    var id = releaseDateID.Value;

                    var releaseDateDB = await _releaseDateDBAccess.GetReleaseDateByIdAsync(id);

                    if (releaseDateDB != null)
                    {
                        // check if current release data on db is true and oen passed is false then update it
                        if (releaseDateDB.ComingSoon && !releaseDate.ComingSoon ||
                            !releaseDateDB.ReleasedDate.Equals(releaseDate.ReleasedDate)
                            )
                        {
                            UpdateReleaseDate(new ReleaseDateUpdateModel
                            {
                                ReleaseDateId = releaseDateDB.ReleaseDateId,
                                ComingSoon    = releaseDate.ComingSoon,
                                ReleasedDate  = releaseDate.ReleasedDate
                            });
                        }
                    }
                    else
                    {
                        throw new Exception($"{nameof(releaseDateDB)}does not exist on DB");
                    }
                }
            }
            else
            {
                Console.WriteLine($"Invalid Data from {nameof(ReleaseDateAddModel)}");
                validator.Errors.ForEach(e => Console.WriteLine(e));

                throw new Exception("Some data are invalid");
            }
        }
Exemplo n.º 11
0
        public async Task <int> AddPlatform(PlatformAddModel platform)
        {
            var validator = DataValidatorHelper.Validate(platform);

            if (validator.IsValid)
            {
                var platformDb = await _gamedbAccess.GetPlatformByNameAsync(platform.Name);

                if (platformDb == null)
                {
                    return(await _gamedbAccess.AddPlatformAsync(platform));
                }

                return(platformDb.PlatformId);
            }

            Console.WriteLine($"Invalid Data from {nameof(ReleaseDateAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }
Exemplo n.º 12
0
        public async Task <int> AddReleaseDate(ReleaseDateAddModel releaseDate)
        {
            var validator = DataValidatorHelper.Validate(releaseDate);

            if (validator.IsValid)
            {
                return(await _releaseDateDBAccess.AddReleaseDateAsync(releaseDate));
            }

            if (String.IsNullOrEmpty(releaseDate.ReleasedDate) && releaseDate.ComingSoon)
            {
                releaseDate.ReleasedDate = "Not Confirmed";

                return(await _releaseDateDBAccess.AddReleaseDateAsync(releaseDate));
            }

            Console.WriteLine($"Invalid Data from {nameof(ReleaseDateAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }
Exemplo n.º 13
0
        public async Task <int> AddSteamApp(SteamAppAddModel steamApp)

        {
            var validator = DataValidatorHelper.Validate(steamApp);

            if (validator.IsValid)
            {
                var steamAppDB = await _steamAppDbAccess.GetSteamAppByIdAsync(steamApp.SteamAppId);

                if (steamAppDB == null)
                {
                    return(await _steamAppDbAccess.AddSteamAppAsync(steamApp));
                }

                return(steamAppDB.SteamAppId);
            }
            Console.WriteLine($"Invalid Data from {nameof(SteamAppAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }
Exemplo n.º 14
0
        public async Task <int> AddSystemRequirement(SystemRequirementAddModel systemRequirement)
        {
            var validator = DataValidatorHelper.Validate(systemRequirement);

            if (validator.IsValid)
            {
                systemRequirement.PlatformId = await AddPlatform(systemRequirement.Platform);

                var srDb = await _gamedbAccess.
                           GetSystemRequirementByGameIdAndPlatformIdAsync(systemRequirement.GameId, systemRequirement.PlatformId);

                if (srDb == null)
                {
                    return(await _gamedbAccess.AddSystemRequirementAsync(systemRequirement));
                }
                return(srDb.SystemRequirementId);
            }

            Console.WriteLine($"Invalid Data from {nameof(SystemRequirementAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }
Exemplo n.º 15
0
        public async Task <int> AddCurrency(CurrencyAddModel currency)
        {
            var validator = DataValidatorHelper.Validate(currency);


            if (validator.IsValid)
            {
                var currencyDb = await _gamedbAccess.GetCurrencyByCodeAsync(currency.Code);

                if (currencyDb == null)
                {
                    return(await _gamedbAccess.AddCurrencyAsync(currency));
                }

                return(currencyDb.CurrencyId);
            }


            Console.WriteLine($"Invalid Data from {nameof(CurrencyAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }
Exemplo n.º 16
0
        public async Task <int> AddStore(StoreAddModel store)
        {
            var validator = DataValidatorHelper.Validate(store);


            if (validator.IsValid)
            {
                var storeDb = await _gamedbAccess.GetStoreAsync(store.Name);

                if (storeDb == null)
                {
                    return(await _gamedbAccess.AddStoreAsync(store));
                }

                return(storeDb.StoreId);
            }


            Console.WriteLine($"Invalid Data from {nameof(StoreAddModel)}");
            validator.Errors.ForEach(e => Console.WriteLine(e));

            throw new Exception("Some data are invalid");
        }