Пример #1
0
        public async Task AddUsersToTeam(AddUsersToTeam command)
        {
            await _administratorService.ValidateAtLeastModerator(command.UserId, command.GroupId);

            var group = await _groupRepository.GetWithGroupAndTeamStudents(command.GroupId);

            var groupStudents = group.Students.Where(s => command.Emails.Any(e => e == s.Email)).ToList();
            var team          = group.Teams.FirstOrDefault(t => t.Name == command.TeamName);

            if (team == null)
            {
                throw new AppException($"Team with this name doesn't exist {command.TeamName}", AppErrorCode.DOESNT_EXIST);
            }

            team.AddStudents(groupStudents);
            await _groupRepository.SaveChangesAsync();

            var usersNotExistingInDb = command.Emails.Where(e => !groupStudents.Select(u => u.Email).Contains(e));

            if (usersNotExistingInDb.ToList().Count != 0)
            {
                throw new AppException($"Users with those emails don't exist in your group {string.Join(", ", usersNotExistingInDb)}." +
                                       $"Other users were added successfully.", AppErrorCode.DOESNT_EXIST);
            }
        }
Пример #2
0
        public async Task <ActionResult> AddUsersToTeam(Guid groupId, string teamName, [FromBody] AddUsersToTeam command)
        {
            command.GroupId  = groupId;
            command.TeamName = teamName;
            command.UserId   = User.GetUserId();
            await _teamService.AddUsersToTeam(command);

            return(Ok());
        }