Exemplo n.º 1
0
        public async Task <Business> UpdateGainsSinceLastCheckIn(int businessId)
        {
            var business = await _context.Business
                           .Include(s => s.BusinessInvestments)
                           .SingleOrDefaultAsync(s => s.Id == businessId);

            var gains = await CalculateGainsSinceLastCheckIn(businessId);

            business.Cash += gains;
            if (business.LifeTimeEarnings < business.Cash)
            {
                business.LifeTimeEarnings = business.Cash;
            }
            business.LifeTimeEarnings += gains;

            if ((DateTime.UtcNow - business.LastCheckIn).TotalHours > 8)
            {
                business.ReceivedMessages.Add(new Message()
                {
                    DateReceived        = DateTime.UtcNow,
                    MessageBody         = $"You've gained {gains.ToKMB()} since you last visited on {business.LastCheckIn}",
                    ReceivingBusinessId = business.Id,
                });
            }

            business.LastCheckIn = DateTime.UtcNow;
            await _appHelper.TrySaveChangesConcurrentAsync(_context);

            return(business);
        }
Exemplo n.º 2
0
        public async Task <Entrepreneur> UpdateEntrepreneurScore(int businessId)
        {
            var business = await _context.Business
                           .Include(s => s.Owner)
                           .SingleOrDefaultAsync(s => s.Id == businessId);

            business.Owner.Score = await CalculateScore(businessId);

            _context.Entrepreneurs.Update(business.Owner);
            await _appHelper.TrySaveChangesConcurrentAsync(_context);

            return(business.Owner);
        }