public async Task <IActionResult> Register([FromBody] TeacherForRegister teacherForRegister) { if (await _authRepository.TeacherExists(teacherForRegister.UserName)) { ModelState.AddModelError("UserName", "Username already exists"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var teacherToCreate = new TeachersLogin { Username = teacherForRegister.UserName, }; var teacherCreate = new Teacher() { name = teacherForRegister.name, surname = teacherForRegister.surname, title = teacherForRegister.title, userGroup = teacherForRegister.userGroup }; var getTeacher = await _authRepository.TeacherCreate(teacherCreate); var createdUser = await _authRepository.TeacherRegister(teacherToCreate, teacherForRegister.Password, getTeacher.id); return(StatusCode(201)); }
public async Task <TeachersLogin> TeacherRegister(TeachersLogin teacher, string password, int teacherId) { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); teacher.PasswordHash = passwordHash; teacher.PasswordSalt = passwordSalt; teacher.teacherId = teacherId; await _context.TeachersLogins.AddAsync(teacher); await _context.SaveChangesAsync(); return(teacher); }