public async Task <IActionResult> Register(RegisterAccountDTO registerAccountDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool isUsernameExist = await _accountAppService.checkUsernameExist(registerAccountDTO.UserName); if (isUsernameExist) { return(BadRequest(new Response { Message = "Username already exist" })); } bool isEmailExist = await _accountAppService.checkEmailExist(registerAccountDTO.Email); if (isEmailExist) { return(BadRequest(new Response { Message = "Email already exist" })); } try { registerAccountDTO.IsDoctor = false; ApplicationUserIdentity registerUser = await _accountAppService.Register(registerAccountDTO); await _accountAppService.AssignToRole(registerUser.Id, UserRoles.Patient); _generalAppService.CommitTransaction(); return(Ok(new Response { Message = "Account created successfully" })); } catch (Exception ex) { _generalAppService.RollbackTransaction(); return(BadRequest(new Response { Message = ex.Message })); } }