示例#1
0
        public async Task <IActionResult> Kick(CourseKickParticipantCommand command)
        {
            if (!_userResolver.HasCoursePrivilege(command.CourseId, new List <PrivilegeEnum>()
            {
                PrivilegeEnum.CanManageCourse, PrivilegeEnum.CanKickParticipants
            }))
            {
                return(Unauthorized());
            }
            await _commandBus.ExecuteAsync(command);

            return(Ok());
        }
示例#2
0
        public async Task HandleAsync(CourseKickParticipantCommand command)
        {
            var user = await _context
                       .User
                       .Include(x => x.Subscription)
                       .Include(x => x.DiscussionComment)
                       .Include(x => x.Discussion)
                       .ThenInclude(x => x.DiscussionComment)
                       .Include(x => x.ExamAttempt)
                       .ThenInclude(x => x.UserAnswer)
                       .Include(x => x.CourseTaskAttemptUser)
                       .ThenInclude(x => x.TaskAttemptAttachment)
                       .Include(x => x.UserCoursePrivilege)
                       .FirstOrDefaultAsync(x => x.Id == command.UserId);

            _context.Discussion.RemoveRange(user.Discussion);
            _context.DiscussionComment.RemoveRange(user.DiscussionComment);

            var attempts = user.ExamAttempt.ToList();

            attempts.ForEach(x =>
            {
                _context.UserAnswer.RemoveRange(x.UserAnswer);
            });
            _context.ExamAttempt.RemoveRange(user.ExamAttempt);

            var courseTaskAttempts = user.CourseTaskAttemptUser.ToList();

            courseTaskAttempts.ForEach(x =>
            {
                _context.TaskAttemptAttachment.RemoveRange(x.TaskAttemptAttachment);
            });
            _context.RemoveRange(courseTaskAttempts);

            _context.UserCoursePrivilege.RemoveRange(user.UserCoursePrivilege);

            _context.Subscription.RemoveRange(user.Subscription.Where(x => x.CourseId == command.CourseId));

            _context.SaveChanges();
        }