示例#1
0
        public async Task <int> AddGameDealAsync(GameDealAddModel gameDeal)
        {
            string query = $@"INSERT INTO  GameDeal (Url, StoreId, GameId, PriceOverviewId,DealDateId,IsFree)
                        VALUES(@Url, @StoreId, @GameId, @PriceOverviewId,@DealDateId,@IsFree)";

            return(await SaveDataAsync(query, gameDeal));
        }
示例#2
0
        public async void UpdatePriceOverview(GameDealModel gameDB, GameDealAddModel gamedeal)
        {
            if (gameDB.PriceOverviewId != 0 || gameDB.PriceOverviewId != null)
            {
                var priceOverviewDB = await _gamedbAccess.GetPriceOverviewByIdAsync(gameDB.PriceOverviewId.Value);

                if (priceOverviewDB != null)
                {
                    if (gamedeal.PriceOverview != null)
                    {
                        var priceIsSame = ComparePriceIsSame(priceOverviewDB, gamedeal.PriceOverview);

                        if (!priceIsSame)
                        {
                            // exprie the current deal and add a new one
                            await _gamedbAccess.ExpireGameDealAsync(gameDB.DealDateId);
                            await AddGameDeal(gamedeal);
                        }
                    }
                    else
                    {
                        Console.WriteLine("PriceOverview Mission");
                    }
                }
                else
                {
                    throw new Exception("price overview does not exist in db");
                }
            }
        }
示例#3
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");
        }
        private void addGameDeal(SteamAppDetails app, int gameId)
        {
            DateTime currentDateTime  = DateTime.Now;
            string   sqlFormattedDate = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff");


            var gamedeal = new GameDealAddModel
            {
                GameId   = gameId,
                DealDate = new DealDateAddModel {
                    DatePosted = sqlFormattedDate
                },
                Url    = _basedStoreURl + app.SteamAppID,
                IsFree = app.IsFree,
                Store  = new StoreAddModel {
                    Name = _storeName
                },
            };

            var priceOverview = app.PriceOverview;

            if (priceOverview != null)
            {
                gamedeal.PriceOverview = new PriceOverviewAddModel
                {
                    Price              = priceOverview.Initial,
                    PriceFormat        = priceOverview.InitialFormat,
                    FinalPrice         = priceOverview.Final,
                    FinalPriceFormat   = priceOverview.FinalFormat,
                    DiscountPercentage = priceOverview.DiscountPercentage,
                    Currency           = new CurrencyAddModel {
                        Code = priceOverview.Currency, Symbole = "£"
                    }
                };

                if (priceOverview.Initial != priceOverview.Final)
                {
                    gamedeal.DealDate.LimitedTimeDeal = true;
                }
            }
            _gameManager.AddGameDeal(gamedeal);
        }