public async Task DeleteClassroom(Guid id)
        {
            if (_classroomRepository.GetClassroom(id) != null)
            {
                var getAllUsers = _userRepository.GetUserByClassroomId(id);

                if (getAllUsers.Any())
                {
                    var usersCantBeDeleted = CheckIfUsersCanBeDeleted(getAllUsers);
                    if (usersCantBeDeleted)
                    {
                        throw new ArgumentException("There are users with results, first delete the results");
                    }
                    await _userRepository.DeleteAllUsers(getAllUsers);
                }
                await _classroomRepository.DeleteClassroom(id);
            }
        }
Esempio n. 2
0
        public ViewResult Details(int id)
        {
            Classroom Classroom = _classRepo.GetClassroom(id);

            if (Classroom == null)
            {
                Response.StatusCode = 404;
                return(View("NotFound"));
            }
            return(View(Classroom));
        }
Esempio n. 3
0
        public override ValidationResult Validate(UserRequestDto entity)
        {
            var validationResult = new ValidationResult();

            this.ValidateNullOrEmpty(validationResult, nameof(entity.Email), entity.Email);

            if (_userRepository.FindUser(entity.Email) != null)
            {
                validationResult.Errors.Add($"User with email {entity.Email} already added");
            }

            if (!entity.ClassroomId.HasValue && entity.Role == 0)
            {
                validationResult.Errors.Add("A classroomId is required when creating a student");
            }

            if (entity.ClassroomId.HasValue && _classroomRepository.GetClassroom(entity.ClassroomId.Value) == null)
            {
                validationResult.Errors.Add($"Classroom {entity.ClassroomId.Value} not found");
            }

            return(validationResult);
        }