Пример #1
0
        public void RegisterUser(StudentRegistrationDTO studentRegistrationDTO)
        {
            //todo: validate these values!!
            //check username existence

            var usernameExisting = studentRepository.FindStudentByUserName(studentRegistrationDTO.UserName);

            if (usernameExisting != null)
            {
                throw new RegistrationException("This username is already taken.");
            }

            if (studentRegistrationDTO.GradeBook != null && studentRegistrationDTO.Courses != null)
            {
                var student = new Student
                {
                    Email         = studentRegistrationDTO.Email,
                    FirstName     = studentRegistrationDTO.FirstName,
                    LastName      = studentRegistrationDTO.LastName,
                    GenderType    = (int)studentRegistrationDTO.Gender,
                    InstagramName = studentRegistrationDTO.InstagramName,
                    MessengerName = studentRegistrationDTO.MessengerName,
                    NeptunCode    = studentRegistrationDTO.NeptunCode,
                    Password      = Crypto.HashPassword(studentRegistrationDTO.Password),
                    UserName      = studentRegistrationDTO.UserName
                };

                if (studentRegistrationDTO.Image != null)
                {
                    student.ImagePath = StoreFile(studentRegistrationDTO.Image, "Images");
                }

                studentRepository.CreateUserStudent(student);
                var stud = studentRepository.FindStudentByUserName(student.UserName);

                try
                {
                    ProcessNeptunExports(stud, studentRegistrationDTO.GradeBook, studentRegistrationDTO.Courses);
                }
                catch (Exception e)
                {
                    _logger.Log(LogLevel.Error, e.Message);
                    studentRepository.Delete(stud, stud.UserID);
                    throw new RegistrationException("Neptun export processing was unsuccesful.");
                }
            }
            else
            {
                throw new RegistrationException("Neptun exports weren't included, or was in bad format. required file: .CSV - comma or semicolon separated, and UTF-8 coded");
            }
        }
Пример #2
0
        public async Task RegisterStudentAsync(StudentRegistrationDTO request)
        {
            University university = await universityRepository.GetByIdAsync(request.UniversityId);

            if (university == null)
            {
                throw new BadRequestException("University doesn't exist!");
            }

            User studentUser = await RegisterAsync(request);

            await usersRepository.AddUserToRoleAsync(studentUser, RoleName.STUDENT);

            await studentsRepository.AddAsync(new Student
            {
                UserId       = studentUser.Id,
                UniversityId = request.UniversityId
            });

            await studentsRepository.SaveChangesAsync();
        }
 public IActionResult Registration([FromForm] StudentRegistrationDTO userReg)
 {
     _authenticationService.RegisterUser(userReg);
     return(Ok());
 }