Esempio n. 1
0
        public bool AddOrUpdateSellPriceInDB(int id, string name, int price, DayOfWeek?dayOfWeek = null, bool?isMorning = null)
        {
            EnsureTableIsClear();
            if (dayOfWeek == null || isMorning == null)
            {
                DateTime date = DateTimeOffsetter.ToUSCentralTime(DateTime.Now).DateTime;
                dayOfWeek = date.DayOfWeek;
                isMorning = date.Hour < 12;
            }

            TurnipInfo turnipInfo = GetTurnipEntry(id);

            if (turnipInfo == null) //Need to create a new Turnip Entry
            {
                turnipInfo = new TurnipInfo()
                {
                    Id       = id,
                    Name     = name,
                    WeekNum  = _weekNum,
                    BuyPrice = -1 //Default value
                };

                _turnipRepository.InsertIntoTurnipsTable(turnipInfo);
            }

            //Get the count of sell prices and what count we expect to be at
            int sellPricesCount = turnipInfo.SellPrices.Count();
            int countAsOfDate   = (int)dayOfWeek * 2;

            countAsOfDate += (bool)isMorning ? -1 : 0;

            if (sellPricesCount == countAsOfDate) //Overwrite
            {
                turnipInfo.SellPrices[turnipInfo.SellPrices.Count - 1] = price;
            }
            else if (sellPricesCount < countAsOfDate) //Add blank prices in
            {
                for (int counter = sellPricesCount; counter < countAsOfDate - 1; counter++)
                {
                    turnipInfo.SellPrices.Add(-1);
                }

                turnipInfo.SellPrices.Add(price);
            }
            else if (sellPricesCount > countAsOfDate) //Overwrite the desired sell price
            {
                turnipInfo.SellPrices[countAsOfDate - 1] = price;
            }

            _turnipRepository.UpdateTurnipTableEntry(turnipInfo);

            return(true);
        }
Esempio n. 2
0
 private void UpdateWeekNum()
 {
     _weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(DateTimeOffsetter.ToUSCentralTime(DateTime.Now).DateTime, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
 }