public async Task <Models.Squad> UpdateAsync(Models.Squad squad) { squad.LastUpdated = DateTime.Now; await _squads.ReplaceOneAsync(x => x.Id == squad.Id, squad); return(squad); }
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()); }
public async Task <Models.Squad> CreateAsync(string userId) { var squad = new Models.Squad() { UserId = userId, Id = Guid.NewGuid() }; await _squads.InsertOneAsync(squad); return(squad); }
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)); }
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); }
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()); }
private static bool DistinctCheck(Models.Squad squad) { return(!AllCardIds(squad).GroupBy(x => x).Any(c => c.Count() > 1)); }
private static bool SquadIdCheck(Models.Squad squad, Guid usersSquadId) { return(squad.Id == usersSquadId); }
public async Task <bool> Validate(Models.Squad squad, Guid usersSquadId, string userId) { return(SquadIdCheck(squad, usersSquadId) && await CardCheck(squad, userId) && FormationCheck(squad) && DistinctCheck(squad)); }
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)); }