public async Task UpdateTeam(UpdateTeamModel model, string ownerId) { var existingTeam = await GetTeamById(model.Id); if (existingTeam == null) { throw new ArgumentException($"A team with id: {model.Id} does not exist anymore."); } existingTeam = await GetTeamByOwnerIdAndName(ownerId, model.Name); if (existingTeam != null) { throw new ArgumentException($"A Team with name '{model.Name}' already exists."); } await using var command = _connection.CreateCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "UpdateTeam"; command.Parameters.AddWithValue("@Id", model.Id); command.Parameters.AddWithValue("@Name", model.Name); if (_connection.State != ConnectionState.Open) { await _connection.OpenAsync(); } await command.ExecuteNonQueryAsync(); }
public async Task <IActionResult> Update([FromBody] UpdateTeamModel model) { try { if (!ModelState.IsValid) { throw new ArgumentException($"Validation failed. Please check data you entered"); } var user = await _userManager.GetUserAsync(User); await _dataAccess.UpdateTeam(model, user.Id); return(Ok()); } catch (Exception e) { _logger.LogError(e, "UpdateTeam"); if (_hostEnvironment.IsDevelopment()) { throw; } return(BadRequest(new { Error = e.Message })); } }
public async Task <IActionResult> UpdateTeam(int teamId, [FromBody] UpdateTeamModel model) { if (model == null) { throw new ApiException(400, "Invalid request body", ErrorCode.InvalidRequestFormat); } await _teamsService.UpdateTeam(teamId, model, _currentUser.Id); return(Ok()); }
public async Task <ActionResult> UpdateTeamModal(UpdateTeamModel model) { if (!ModelState.IsValid) { return(View(model)); } var result = await GameWriter.UpdateTeam(model); if (!ModelState.IsWriterResultValid(result)) { return(View(model)); } return(CloseModalSuccess()); }
public async Task UpdateTeam(int teamId, UpdateTeamModel model, int currentUserId) { var team = await _db.Teams.FindAsync(teamId); if (team == null) { throw new ApiException(404, "Team not found", ErrorCode.NotFound); } if (team.AdminId != currentUserId) { throw new ApiException(401, "Access denied", ErrorCode.AuthError); } team.Name = string.IsNullOrWhiteSpace(model.Name) ? team.Name : model.Name; await UpdateTeamUsers(teamId, model.UserIds, currentUserId); await _db.SaveChangesAsync(); }
public async Task <IWriterResult> UpdateTeam(UpdateTeamModel model) { using (var context = DataContextFactory.CreateContext()) { var team = await context.Team .Include(x => x.Game) .FirstOrDefaultAsync(x => x.Id == model.Id); if (team == null) { return(new WriterResult(false, $"Team not found")); } if (team.Game.Status != Enums.GameStatus.NotStarted && team.Game.Status != Enums.GameStatus.Paused) { return(new WriterResult(false, $"Unable to update team to game in {team.Game.Status} status")); } if (await context.Team.AnyAsync(x => x.GameId == team.GameId && x.Name == model.Name && x.Id != model.Id)) { return(new WriterResult(false, $"Game with name already exists")); } if (await context.Team.AnyAsync(x => x.GameId == team.GameId && x.Color == model.Color && x.Id != model.Id)) { return(new WriterResult(false, $"Game with color already exists")); } team.Name = model.Name; team.Description = model.Description; team.Color = model.Color; team.Icon = model.Icon; team.Rank = model.Rank; await context.SaveChangesAsync(); return(new WriterResult(true)); } }