public void Update() { var account = new AccountUpdateSchema { Id = 8, Password = _cryptograph.RNG("4321"), LastSignedinAt = DateTime.Now, StatusId = Status.Active.ToInt() }; _accountService.UpdateAsync(account).GetAwaiter().GetResult(); Assert.IsTrue(account.StatusCode == 200); }
public async Task UpdateAsync(AccountUpdateSchema account) { await _storedProcedure.ExecuteAsync(account); }
public async Task <IServiceResult> ExternalSigninAsync(ExternalUserBindingModel externalUser, AccountProfileResult accountProfile) { if (accountProfile == null && accountProfile.AccountId.HasValue) { return(DataTransferer.DefectiveEntry()); } if (accountProfile.StatusId != Status.Active) { return(DataTransferer.UserIsNotActive()); } var now = DateTime.UtcNow; var accountQuery = new AccountGetFirstSchema { Id = accountProfile.AccountId, StatusId = Status.Active.ToInt() }; var account = await FirstAsync(accountQuery); if (account == null) { return(DataTransferer.UserNotFound()); } // todo: check the account using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { try { var accountDeviceQuery = new AccountDeviceGetFirstSchema { AccountId = account.Id, DeviceId = externalUser.DeviceId }; var accountDevice = await _accountDeviceService.FirstAsync(accountDeviceQuery); if (accountDevice == null) { return(DataTransferer.DeviceIdNotFound()); } int deviceId; if (accountDevice != null) { deviceId = accountDevice.Id.Value; // set a new token await _accountDeviceService.UpdateAsync(new AccountDeviceUpdateSchema { Id = accountDevice.Id.Value }); } else { // create new device for account deviceId = await _accountDeviceService.AddAsync(new AccountDeviceAddSchema { AccountId = account.Id, DeviceId = externalUser.DeviceId, DeviceName = externalUser.DeviceName, DeviceType = externalUser.DeviceType, CreatedAt = now, StatusId = Status.Active.ToInt() }); } // clean forgot password tokens //account.Id.Value, transaction await _accountProfileService.CleanForgotPasswordTokensAsync(account.Id.Value); //if(accountProfileCleanTokens.StatusCode != 200) { // Log.Error($"Can't update 'ForgotPasswordTokens' to NULL for AccountId={account.Id}"); // return DataTransferer.SomethingWentWrong(); //} // set last signed in at var accountUpdate = new AccountUpdateSchema { Id = account.Id.Value, LastSignedinAt = now }; await UpdateAsync(accountUpdate); if (accountUpdate.StatusCode != 200) { Log.Error($"Can't update 'LastSignedinAt' after a successfully signing in for AccountId={account.Id}"); } transaction.Complete(); var token = _jwtHandler.Bearer(new Account(account.Id.Value, deviceId, account.Username, now).ToClaimsIdentity()); return(DataTransferer.Ok(token)); } catch (Exception ex) { Log.Error(ex, ex.Source); return(DataTransferer.InternalServerError(ex)); } } }