public async Task <IActionResult> Post(AccountPostRequestBody model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState)); } ValidateEmailAndPhoneInUse(model); if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState)); } var account = await RegisterAccount(model); var responseBody = account.ToAccountPostResponseBody(); return(CreatedAtRoute("GetAccount", new { id = responseBody.Id }, responseBody)); }
private async Task <Account> RegisterAccount(AccountPostRequestBody model) { var user_id = await auth0Service.SignUpAndGetId(model.Email, model.Password); var account = model.ToAccount(user_id); accountService.Register(account); return(account); }
private void ValidateEmailAndPhoneInUse(AccountPostRequestBody model) { if (accountService.IsEmailInUse(model.Email)) { ModelState.AddModelError(nameof(model.Email), "This email is already registered."); } if (accountService.IsPhoneInUse(model.Phone)) { ModelState.AddModelError(nameof(model.Phone), "This phone is already registered."); } }