private async Task <bool> SaveAsync() { _dataInput = Input; bool value = false; var prueba = Input; var prueba2 = ModelState; var stop = "hola"; if (ModelState.IsValid) { IdentityUser userEmailExists = _userHelper.GetUserByEmail(Input.Email); if (userEmailExists == null) { var strategy = _context.Database.CreateExecutionStrategy(); await strategy.ExecuteAsync(async() => { using (var transaction = _context.Database.BeginTransaction()) { var user = new IdentityUser { Email = Input.Email, PhoneNumber = Input.PhoneNumber, UserName = Input.Email }; try { var result = await _userHelper.CreateAsync(user, Input.Password); if (result.Succeeded) { await _userHelper.AddToRoleAsync(user, Input.Role); var dataUser = _userHelper.GetUserByEmail(Input.Email); var imageByte = await _imageHelper.ByteAvatarImageAsync( Input.AvatarImage, _environment, "images/images/default.png"); var tUser = _converterHelper.ToTUserModel(Input); tUser.Image = imageByte; tUser.IdUser = dataUser.Id; await _context.AddAsync(tUser); await _context.SaveChangesAsync(); transaction.Commit(); _dataInput = null; value = true; } else { _dataInput.ErrorMessage = result.Errors.ToString(); value = false; } } catch (System.Exception ex) { _dataInput.ErrorMessage = ex.Message; transaction.Rollback(); value = false; } } }); } else { _dataInput.ErrorMessage = $"There email {Input.Email} already exists"; value = false; } } else { _dataInput.ErrorMessage = "Select a Role"; value = false; } return(value); }