예제 #1
0
 public static BattleInvitationViewModel Map(BattleInvitation battleInvitation)
 {
     return(new BattleInvitationViewModel
     {
         Id = battleInvitation.Id,
         InviterAccountId = battleInvitation.InviterAccountId,
         DateTime = battleInvitation.DateTime
     });
 }
예제 #2
0
        public async Task ProcessSuccessfulBattleInvitationAchievements(BattleInvitation battleInvitation,
                                                                        AccountStatsSummary inviterPlayerStats, CancellationToken cancellationToken)
        {
            var achievementTypes = await _context.AchievementTypes.AsNoTracking().Where(q => q.IsArchived == false && q.NumberOfSuccessfulBattleInvitations != null).ToListAsync(cancellationToken);

            foreach (var a in achievementTypes)
            {
                if (inviterPlayerStats.SuccessfulBattleInvitationsCount >= a.NumberOfSuccessfulBattleInvitations)
                {
                    _context.Achievements.Add(new Achievement
                    {
                        AccountId         = battleInvitation.AccountId,
                        AchievementTypeId = a.Id,
                        AchieveDateTime   = DateTime.UtcNow
                    });
                }
            }

            await _context.SaveChangesAsync(cancellationToken);
        }
예제 #3
0
        public async Task <IActionResult> InvitePlayerToOneToOneBattle([FromRoute] long accountId, CancellationToken cancellationToken)
        {
            var battleInvitation = await _dataContext.BattleInvitations.FirstOrDefaultAsync(q => q.AccountId == accountId && q.InviterAccountId == AccountId, cancellationToken);

            if (battleInvitation != null)
            {
                return(BadRequest("duplicate_invitation", "Invitation already sent."));
            }

            battleInvitation = new BattleInvitation
            {
                InviterAccountId = AccountId,
                AccountId        = accountId,
                DateTime         = DateTime.UtcNow,
                Status           = BattleInvitationStatus.Pending
            };

            _dataContext.BattleInvitations.Add(battleInvitation);
            await _dataContext.SaveChangesAsync(cancellationToken);

            return(Ok());
        }