public async Task <IActionResult> UserRegistrationAsync([FromBody] ReistrationViewModel registrationViewModelPl) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState.ErrorCount)); } return(await CreateInfoObjectResult(userService.RegistrationAsync, registrationViewModelPl)); }
public async Task <ResultViewModel> RegistrationAsync(ReistrationViewModel registrationViewModel) { try { if (registrationViewModel == null) { return(new ResultViewModel((int)HttpStatusCode.BadRequest, "Null Request.")); } User currentUser = await DBContext.User.FirstOrDefaultAsync(e => e.Email == registrationViewModel.Email); if (currentUser != null) { return(new ResultViewModel((int)HttpStatusCode.BadRequest, "User already exist")); } PasswordHasher hasher = new PasswordHasher(registrationViewModel.Password); User user = new User { Email = registrationViewModel.Email, Password = hasher.GetHash(), LastName = registrationViewModel.LastName, FirstName = registrationViewModel.FirstName, ThirdName = registrationViewModel.ThirdName, RegistrationDate = DateTime.Now.Date, MobilePhone = registrationViewModel.Phone, RoleId = 2, }; await Task.Run(() => DBContext.User.AddAsync(user)); await Task.Run(() => DBContext.SaveChangesAsync()); Task.WaitAll(); await Task.Run(() => AddClientAsync(user.Id)); return(new ResultViewModel((int)HttpStatusCode.OK, new JwtCreater(currentUser.Email, DBContext.Role.FirstOrDefaultAsync(e => e.Id == currentUser.RoleId).Result.Name, currentUser.IsFirstEntry.ToString()).GetJwt(), null)); } catch (Exception ex) { return(new ResultViewModel((int)HttpStatusCode.InternalServerError, ex.Message)); } }