public async Task <ResultData <string> > SetSelectedTeamAsync(string userId, int teamId) { if (string.IsNullOrEmpty(userId)) { return(new ResultData <string>(OwnerIdNullMessage, false)); } RetrospectorUser user = await _userRepository.GetUserByIdAsync(userId); Team team = await _teamsRepository.GetTeamByIdAsync(teamId); if (user == null) { return(new ResultData <string>(UserIdDoesntExistMessage, false)); } if (team == null) { return(new ResultData <string>(TeamDoesntExistMessage, false)); } if (user.SelectedTeam == null) { user.SelectedTeam = new UserSelectedTeam() { UserId = user.Id }; } user.SelectedTeam.TeamId = teamId; await _userRepository.UpdateAsync(user); string successMessage = string.Format(SetDefaultTeamSuccessMessage, userId); return(new ResultData <string>(successMessage, true, userId)); }
public async Task <ResultData <Team> > UpdateTeamAsync(Team team) { if (!_teamRepository.TeamExists(team.Id)) { string errorMessage = string.Format(TeamDoesntExistMessage, team.Id); return(new ResultData <Team>(errorMessage, false, team)); } Team oldTeam = await _teamRepository.GetTeamByIdAsync(team.Id); if (team.OwnerId == null) { if (_teamRepository.TeamNameAlreadyExists(team.Name)) { string errorMessage = string.Format(TeamNameExistsMessage, team.Name); return(new ResultData <Team>(errorMessage, false, team)); } oldTeam.Name = team.Name; } if (team.Name == null) { if (!_userRepository.UserExists(team.OwnerId)) { string errorMessage = string.Format(UserDoesntExistMessage, team.OwnerId); return(new ResultData <Team>(errorMessage, false, team)); } oldTeam.OwnerId = team.OwnerId; } await _teamRepository.UpdateTeamAsync(oldTeam); string successMessage = string.Format(UpdateTeamSuccessMessage, oldTeam); return(new ResultData <Team>(successMessage, true, oldTeam)); }