public async Task <bool> RegisterTask(UserRegistrarionModelRequest registrarionModel) { using (var context = _serviceProvider.GetService <DatabaseContext>()) { var isEmailOrPhoneUsed = await context.Users .AsNoTracking() .AnyAsync(x => x.Email == registrarionModel.Email || x.MobileNumber == registrarionModel.MobileNumber); if (isEmailOrPhoneUsed) { return(false); } var userEntity = new UserEntity { Birthday = registrarionModel.Birthday, Email = registrarionModel.Email, FirstName = registrarionModel.FirstName, LastName = registrarionModel.LastName, MobileNumber = registrarionModel.MobileNumber, Password = _cryptoProvider.Encoding(registrarionModel.Password) }; await context.AddAsync(userEntity); await context.SaveChangesAsync(); } return(true); }
public async Task <IActionResult> RegisterAsync([FromBody] UserRegistrarionModelRequest registrarionModel) { if (!ModelState.IsValid) { return(BadRequest()); } try { var result = await _accountService.RegisterTask(registrarionModel); if (!result) { return(StatusCode(403, "Email or mobile phone is already exist")); } return(StatusCode(200)); } catch (Exception ex) { _logger.Error(ex); return(StatusCode(500, "Internal server error")); } }