Example #1
0
        private async Task <Corporation> GetOrCreateCorporation(int corporationId)
        {
            Corporation corp = await context.Corporations.FirstOrDefaultAsync(x => x.Id == corporationId);

            if (corp == null)
            {
                var corpdata = await eSIService.GetCorporation(corporationId);

                corp = new Corporation
                {
                    Id          = corporationId,
                    Name        = corpdata.Name,
                    Ticker      = corpdata.Ticker,
                    MemberCount = corpdata.MemberCount,
                    LastUpdated = DateTime.UtcNow
                };

                await context.AddAsync(corp);
            }
            else if (corp.LastUpdated < DateTime.UtcNow.AddHours(-24))
            {
                var corpdata = await eSIService.GetCorporation(corporationId);

                corp.Name        = corpdata.Name;
                corp.Ticker      = corpdata.Ticker;
                corp.MemberCount = corpdata.MemberCount;
                corp.LastUpdated = DateTime.UtcNow;
            }

            return(corp);
        }
Example #2
0
        public async Task <MonthlyAggregateCorporation> GetOrCreateMonthlyAggregateCorporation(Corporation corporation, DateTime date)
        {
            var dateMonth = new DateTime(date.Year, date.Month, 1);

            MonthlyAggregateCorporation aggregate = await GetMonthlyAggregateCorporation(corporation.Id, dateMonth);

            if (aggregate == null)
            {
                aggregate = new MonthlyAggregateCorporation
                {
                    CorporationID = corporation.Id,
                    TimeStamp     = dateMonth
                };

                context.Attach(aggregate);
            }
            return(aggregate);
        }
Example #3
0
        public async Task <DailyAggregateCorporation> GetOrCreateDailyAggregateCorporation(Corporation corporation, DateTime date)
        {
            DailyAggregateCorporation aggregate = await GetDailyAggregateCorporation(corporation.Id, date);

            if (aggregate == null)
            {
                aggregate = new DailyAggregateCorporation
                {
                    CorporationID = corporation.Id,
                    TimeStamp     = date
                };

                context.Attach(aggregate);
            }
            return(aggregate);
        }