コード例 #1
0
        public async Task <ResultData <RetrospectorUser> > AddUserToTeamAsync(string email, int teamId)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(new ResultData <RetrospectorUser>(EmailNullMessage, false));
            }

            RetrospectorUser user = await _userRepository.GetUserByEmailAsync(email);

            if (user == null)
            {
                return(new ResultData <RetrospectorUser>(UserEmailDoesntExistMessage, false));
            }

            Team team = await _teamsRepository.GetTeamByIdAsync(teamId);

            if (team == null)
            {
                return(new ResultData <RetrospectorUser>(TeamDoesntExistMessage, false));
            }

            TeamUser teamUser = await _teamsRepository.GetTeamUserAsync(user.Id, teamId);

            if (teamUser != null)
            {
                return(new ResultData <RetrospectorUser>(UserAlreadyInTeamMessage, false));
            }

            teamUser = new TeamUser
            {
                TeamId = teamId,
                UserId = user.Id
            };

            await _userRepository.AddUserToTeamAsync(teamUser);

            return(new ResultData <RetrospectorUser>(UsersAddedToTeamMessage, true, user));
        }