示例#1
0
        public async Task <ResultData <RetrospectorUser> > RemoveUserFromTeamAsync(string userId, int teamId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(new ResultData <RetrospectorUser>(UserIdNullMessage, false));
            }

            RetrospectorUser user = await _userRepository.GetUserWithTeamUsersAsync(userId);

            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>(UserNotInTeamMessage, false));
            }

            user.TeamUsers = user.TeamUsers.Where(tu => tu.TeamId != teamId).ToList();
            await _userRepository.UpdateAsync(user);

            return(new ResultData <RetrospectorUser>(UsersAddedToTeamMessage, true, user));
        }
示例#2
0
        public async Task <RetrospectorUser> UpdateAsync(RetrospectorUser user)
        {
            _context.Users.Update(user);
            await _context.SaveChangesAsync();

            return(user);
        }
示例#3
0
        public async Task <ResultData <RetrospectorUser> > CreateUserAsync(string email, string roleName)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(new ResultData <RetrospectorUser>(EmailNullMessage, false));
            }

            if (string.IsNullOrEmpty(roleName))
            {
                return(new ResultData <RetrospectorUser>(RoleNameEmptyMessage, false));
            }

            RetrospectorUser user = await _accountsRepository.GetUserByEmailAsync(email);

            if (user != null)
            {
                string userFoundMessage = string.Format(UserIsFoundMessage, email);
                return(new ResultData <RetrospectorUser>(userFoundMessage, true, user));
            }

            user = new RetrospectorUser
            {
                Email      = email,
                UserName   = email,
                Notes      = new List <Note>(),
                TeamUsers  = new List <TeamUser>(),
                OwnedTeams = new List <Team>()
            };

            IdentityResult identityResult = await _accountsRepository.AddUserAsync(user);

            if (!identityResult.Succeeded)
            {
                return(new ResultData <RetrospectorUser>(UserCreateFailMessage, false));
            }

            Result roleResult = await AssginToRoleUserAsync(user, roleName);

            if (!roleResult.Success)
            {
                string roleMessage = string.Format(AssignToUserRoleFailMessage, email);

                return(new ResultData <RetrospectorUser>(roleMessage, false));
            }

            string message = string.Format(UserCreateSuccessMessage, user.Email);

            return(new ResultData <RetrospectorUser>(message, true, user));
        }
示例#4
0
        private async Task <Result> AssginToRoleUserAsync(RetrospectorUser user, string roleName)
        {
            if (user == null)
            {
                return(new Result(UserNotFoundMessage, false));
            }

            if (string.IsNullOrEmpty(roleName))
            {
                return(new Result(RoleNameEmptyMessage, false));
            }

            await _accountsRepository.AssignToRoleUserAsync(user, roleName);

            string message = string.Format(AssignedToRoleSuccessMessage, user.Email, roleName);

            return(new Result(message, true));
        }
示例#5
0
        public async Task <ResultData <IList <string> > > GetUserRolesAsync(RetrospectorUser user)
        {
            if (user == null)
            {
                return(new ResultData <IList <string> >(UserNotFoundMessage, false));
            }

            string message;

            IList <string> userRoles = await _accountsRepository.GetUserRolesAsync(user);

            if (userRoles.Count == 0)
            {
                message = string.Format(UserRolesCountZeroMessage, user.Email);
                return(new ResultData <IList <string> >(message, false));
            }

            message = string.Format(UserRolesFound, user.Email);
            return(new ResultData <IList <string> >(message, true, userRoles));
        }
示例#6
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));
        }
示例#7
0
        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 AssignToRoleUserAsync(RetrospectorUser user, string rolename)
 {
     await _userManager.AddToRoleAsync(user, rolename);
 }
 public async Task <IList <string> > GetUserRolesAsync(RetrospectorUser user)
 {
     return(await _userManager.GetRolesAsync(user));
 }
 public async Task <IdentityResult> AddUserAsync(RetrospectorUser user)
 {
     return(await _userManager.CreateAsync(user));
 }