public async Task <IActionResult> EditSharedAccount(string id, EditSharedAccountDto sharedAccountDto) { if (id != sharedAccountDto.Id) { return(BadRequest()); } try { var sharedAccount = new SharedAccountEditModel() { Id = sharedAccountDto.Id, Name = sharedAccountDto.Name, Urls = sharedAccountDto.Urls, Apps = sharedAccountDto.Apps, Login = sharedAccountDto.Login, LoginType = sharedAccountDto.LoginType, Domain = sharedAccountDto.Domain }; var vaultIds = await _sharedAccountService.EditSharedAccountAsync(sharedAccount); _remoteDeviceConnectionsService.StartUpdateHardwareVaultAccounts(vaultIds); } catch (Exception ex) { _logger.LogError(ex.Message); return(StatusCode(500, new { error = ex.Message })); } return(NoContent()); }
protected override async Task OnInitializedAsync() { try { SharedAccountService = ScopedServices.GetRequiredService <ISharedAccountService>(); RemoteDeviceConnectionsService = ScopedServices.GetRequiredService <IRemoteDeviceConnectionsService>(); ModalDialogService.OnCancel += OnCancelAsync; SharedAccount = await SharedAccountService.GetSharedAccountByIdAsync(AccountId); if (SharedAccount == null) { throw new Exception("Account not found"); } SharedAccountEditModel = new SharedAccountEditModel().Initialize(SharedAccount); EntityBeingEdited = MemoryCache.TryGetValue(SharedAccount.Id, out object _); if (!EntityBeingEdited) { MemoryCache.Set(SharedAccount.Id, SharedAccount); } SetInitialized(); } catch (Exception ex) { Logger.LogError(ex.Message); await ToastService.ShowToastAsync(ex.Message, ToastType.Error); await ModalDialogService.CancelAsync(); } }
public async Task <List <string> > EditSharedAccountAsync(SharedAccountEditModel sharedAccountModel) { if (sharedAccountModel == null) { throw new ArgumentNullException(nameof(sharedAccountModel)); } _dataProtectionService.Validate(); await ValidateAccountNameAndLoginAsync(sharedAccountModel.Name, sharedAccountModel.GetLogin(), sharedAccountModel.Id); sharedAccountModel.Urls = Validation.VerifyUrls(sharedAccountModel.Urls); var sharedAccount = await GetSharedAccountByIdAsync(sharedAccountModel.Id); if (sharedAccount == null) { throw new HESException(HESCode.SharedAccountNotFound); } sharedAccount = sharedAccountModel.SetNewValue(sharedAccount); // Get all accounts where used this shared account var accounts = await _accountService .Query() .Include(x => x.Employee.HardwareVaults) .Where(x => x.SharedAccountId == sharedAccount.Id && x.Deleted == false) .AsNoTracking() .ToListAsync(); List <HardwareVaultTask> tasks = new List <HardwareVaultTask>(); foreach (var account in accounts) { account.Name = sharedAccount.Name; account.Urls = sharedAccount.Urls; account.Apps = sharedAccount.Apps; account.Login = sharedAccount.Login; account.UpdatedAt = DateTime.UtcNow; foreach (var hardwareVault in account.Employee.HardwareVaults) { tasks.Add(_hardwareVaultTaskService.GetAccountUpdateTask(hardwareVault.Id, account.Id)); } } using (TransactionScope transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await _sharedAccountRepository.UpdateOnlyPropAsync(sharedAccount, new string[] { nameof(SharedAccount.Name), nameof(SharedAccount.Urls), nameof(SharedAccount.Apps), nameof(SharedAccount.Login) }); await _accountService.UpdateOnlyPropAsync(accounts, new string[] { nameof(Account.Name), nameof(Account.Urls), nameof(Account.Apps), nameof(Account.Login), nameof(Account.UpdatedAt) }); await _hardwareVaultTaskService.AddRangeTasksAsync(tasks); transactionScope.Complete(); } return(accounts.SelectMany(x => x.Employee.HardwareVaults.Select(s => s.Id)).ToList()); }