public async Task <Player> Register(NewPlayer model, bool sudo = false) { var game = await GameStore.Retrieve(model.GameId); if (!sudo && !game.RegistrationActive) { throw new RegistrationIsClosed(); } var user = await Store.GetUserEnrollments(model.UserId); if (user.Enrollments.Any(p => p.GameId == model.GameId)) { throw new AlreadyRegistered(); } var entity = Mapper.Map <Data.Player>(model); entity.TeamId = Guid.NewGuid().ToString("n"); entity.Role = PlayerRole.Manager; entity.ApprovedName = user.ApprovedName; entity.Name = user.ApprovedName; entity.Sponsor = user.Sponsor; entity.SessionMinutes = game.SessionMinutes; await Store.Create(entity); return(Mapper.Map <Player>(entity)); }
public async Task AdvanceTeams(TeamAdvancement model) { var game = await GameStore.Retrieve(model.NextGameId); var allteams = await Store.List() .Where(p => p.GameId == model.GameId) .ToArrayAsync() ; var teams = allteams.GroupBy(p => p.TeamId) .Where(g => model.TeamIds.Contains(g.Key)) .ToArray() ; var enrollments = new List <Data.Player>(); foreach (var team in teams) { string newId = Guid.NewGuid().ToString("n"); foreach (var player in team) { player.Advanced = true; enrollments.Add(new Data.Player { TeamId = newId, UserId = player.UserId, GameId = model.NextGameId, ApprovedName = player.ApprovedName, Name = player.Name, Sponsor = player.Sponsor, Role = player.Role, Score = model.WithScores ? player.Score : 0 }); } } await Store.Create(enrollments); await Store.Update(allteams); }