コード例 #1
0
        public async Task <Models.Squad> UpdateAsync(Models.Squad squad)
        {
            squad.LastUpdated = DateTime.Now;
            await _squads.ReplaceOneAsync(x => x.Id == squad.Id, squad);

            return(squad);
        }
コード例 #2
0
        private static bool FormationCheck(Models.Squad squad)
        {
            var allowedPositions = Models.FormationLookup.AllowedPositions[squad.Formation].Select(x => x.ToString());
            var inLineup         = squad.Lineup.Keys.Except(allowedPositions);
            var inAllowed        = allowedPositions.Except(squad.Lineup.Keys);

            return(!inLineup.Any() && !inAllowed.Any());
        }
コード例 #3
0
        public async Task <Models.Squad> CreateAsync(string userId)
        {
            var squad = new Models.Squad()
            {
                UserId = userId, Id = Guid.NewGuid()
            };
            await _squads.InsertOneAsync(squad);

            return(squad);
        }
コード例 #4
0
ファイル: SquadService.cs プロジェクト: randyammar/pitch-api
        public async Task <Models.Squad> UpdateAsync(Models.Squad squad, string userId)
        {
            var squadInDb = await _squadRepository.GetAsync(userId);

            if (!await _squadValidationService.Validate(squad, squadInDb.Id, userId))
            {
                throw new System.Exception("Squad is not valid.");
            }
            return(await _squadRepository.UpdateAsync(squad));
        }
コード例 #5
0
        private async Task <bool> CardCheck(Models.Squad squad, string userId)
        {
            var cardIds  = AllCardIds(squad);
            var request  = new GetCardsRequest(cardIds);
            var response = await _bus.RequestAsync <GetCardsRequest, GetCardsResponse>(request);

            foreach (var cardId in cardIds)
            {
                var card = response.Cards.FirstOrDefault(x => x.Id == cardId);
                if (card == null || card.UserId != userId)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #6
0
 private static IList <Guid> AllCardIds(Models.Squad squad)
 {
     return(squad.Lineup.Select(x => x.Value).Concat(squad.Subs).Where(x => x.HasValue).Select(x => x.Value).ToList());
 }
コード例 #7
0
 private static bool DistinctCheck(Models.Squad squad)
 {
     return(!AllCardIds(squad).GroupBy(x => x).Any(c => c.Count() > 1));
 }
コード例 #8
0
 private static bool SquadIdCheck(Models.Squad squad, Guid usersSquadId)
 {
     return(squad.Id == usersSquadId);
 }
コード例 #9
0
 public async Task <bool> Validate(Models.Squad squad, Guid usersSquadId, string userId)
 {
     return(SquadIdCheck(squad, usersSquadId) && await CardCheck(squad, userId) && FormationCheck(squad) && DistinctCheck(squad));
 }
コード例 #10
0
        public async Task <Models.Squad> Update(Models.Squad squad)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; //TODO move to currentUserContext

            return(await _squadService.UpdateAsync(squad, userId));
        }