public async Task <TeamDto> CreateTeam(TeamRegistrationDto team) { Team existingTeam = await _dbContext.Teams.SingleOrDefaultAsync(x => x.Name.ToUpper() == team.Name.ToUpper()); if (existingTeam != null) { throw new BusinessException($"A team with name '{team.Name}' already exists."); } Arena existingArena = await _dbContext.Arenas.SingleOrDefaultAsync(x => x.Name.ToUpper() == team.Name.ToUpper()); if (existingArena != null) { throw new BusinessException($"An arena with name '{team.Name}' already exists."); } Team teamToCreate = _teamRegistrationMapper.Map(team); teamToCreate.Password = Crypt.HashPassword(team.Password, 10, enhancedEntropy: true); teamToCreate.PersonalArena = new Arena { Active = true, DeploymentRestriction = TimeSpan.Zero, MaximumPoints = 1000, Width = 10, Height = 10, Name = team.Name, LastRefreshDateTime = DateTime.UtcNow, Private = true }; await _dbContext.Teams.AddAsync(teamToCreate); await _dbContext.SaveChangesAsync(); return(_teamMapper.Map(teamToCreate)); }
public async Task <TeamDto> UpdateTeam(Guid teamId, TeamRegistrationDto team) { ValidateTeam(team); Team teamToUpdate = await _dbContext.Teams.SingleOrDefaultAsync(x => x.Id == teamId); if (teamToUpdate == null) { throw new HtfValidationException("The specified team is unknown!"); } if (!Crypt.EnhancedVerify(team.Password, teamToUpdate.Password)) { throw new HtfValidationException("The specified password is not correct!"); } teamToUpdate.Name = team.Name; teamToUpdate.FeedbackEndpoint = team.FeedbackEndpoint; teamToUpdate.Score--; await _dbContext.SaveChangesAsync(); return(await _dbContext.Teams.Include(x => x.Location).Select(x => new TeamDto { Id = x.Id, Name = x.Name, FeedbackEndpoint = x.FeedbackEndpoint, Score = x.Score, LocationId = x.Location.Id, LocationName = x.Location.Name, TotalNumberOfAndroids = x.TotalNumberOfAndroids, NumberOfAndroidsAvailable = x.TotalNumberOfAndroids - x.Androids.Count, NumberOfAndroidsActive = x.Androids.Count(a => !a.Compromised), NumberOfAndroidsCompromised = x.Androids.Count(a => a.Compromised), }).SingleOrDefaultAsync(e => e.Id == teamId)); }
private async void OnCreateNewTeam() { using (new IsBusy(_eventAggregator)) { await ExceptionHandling(async () => { var password = new NetworkCredential(string.Empty, TeamPassword).Password; _cacheService.Store("PSWD", password); var team = new TeamRegistrationDto { Name = TeamName, Password = password }; CurrentTeam = await _teamClient.CreateTeam(team); }); } }
private void ValidateTeam(TeamRegistrationDto team) { if (team == null) { throw new HtfValidationException("The team to register is invalid due to an unknown reason!"); } if (string.IsNullOrEmpty(team.Name)) { throw new HtfValidationException("The name of the team cannot be empty!"); } if (string.IsNullOrEmpty(team.Password)) { throw new HtfValidationException("The password for the team cannot be empty!"); } }
public async Task <TeamDto> EditTeam(Guid teamId, String password, TeamRegistrationDto team) { Team teamToUpdate = await _dbContext.Teams.SingleOrDefaultAsync(x => x.Id == teamId); if (teamToUpdate == null) { throw new BusinessException(""); } if (!Crypt.EnhancedVerify(password, teamToUpdate.Password)) { throw new BusinessException(""); } teamToUpdate.Name = team.Name; teamToUpdate.Password = Crypt.HashPassword(team.Password, 10, enhancedEntropy: true); await _dbContext.SaveChangesAsync(); return(_teamMapper.Map(teamToUpdate)); }
public async Task <TeamDto> RegisterTeam(TeamRegistrationDto team) { ValidateTeam(team); Team teamToRegister = _teamRegistrationMapper.Map(team); List <Location> availableLocations = await _dbContext.Locations.Where(x => x.Teams.Count == 0).ToListAsync(); teamToRegister.Location = availableLocations.RandomSingle(); if (teamToRegister.Location == null) { throw new Exception("No locations available"); } teamToRegister.Score = 100; teamToRegister.TotalNumberOfAndroids = 1000; teamToRegister.Password = Crypt.HashPassword(teamToRegister.Password, 10, enhancedEntropy: true); _dbContext.Teams.Add(teamToRegister); await _dbContext.SaveChangesAsync(); TeamDto registeredTeam = _teamMapper.Map(teamToRegister); registeredTeam.NumberOfAndroidsAvailable = teamToRegister.TotalNumberOfAndroids; return(registeredTeam); }
public Team Map(TeamRegistrationDto team) { return(_mapper.Map <Team>(team)); }
public Task <TeamDto> EditTeam(TeamRegistrationDto team) { return(Task.FromResult(new TeamDto())); }
public Task <TeamDto> EditTeam(TeamRegistrationDto team) { return(Put <TeamDto, TeamRegistrationDto>( $"{BaseUri}/{RouteConstants.PREFIX}/{RouteConstants.PUT_TEAM}", team)); }
public Task <TeamDto> CreateTeam(TeamRegistrationDto team) { return(Post <TeamDto, TeamRegistrationDto>( $"{BaseUri}/{RouteConstants.PREFIX}/{RouteConstants.POST_TEAM}", team)); }
public async Task <IActionResult> UpdateTeam(Guid teamId, [FromBody] TeamRegistrationDto team) { TeamDto updatedTeam = await _teamLogic.UpdateTeam(teamId, team); return(Ok(updatedTeam)); }
public async Task <IActionResult> RegisterTeam([FromBody] TeamRegistrationDto team) { TeamDto registeredTeam = await _teamLogic.RegisterTeam(team); return(Ok(registeredTeam)); }
public Task <IActionResult> CreateTeam([FromBody] TeamRegistrationDto team) { return(Ok(l => l.CreateTeam(team))); }