/// <summary> /// Созлание записи в таблице модуля проводок /// </summary> /// <param name="account">DTO счета</param> /// <param name="request">Сущность комманды на создание счета</param> /// <param name="cancellationToken">Токе отмены</param> /// <returns></returns> public async Task <ResponseBaseDto> AddBuferEntry(AccountDto account, CreateAccountHistoryEntryCommand request, CancellationToken cancellationToken) { var emptyAccount = "00000000000000000000"; if (request.IsTopUp) { await _accountHistoryBufferRepository.AddBufferEntry(new BufferForFutureEntriesDatesModel(emptyAccount, request.AccountNumber, request.Amount, request.DueDate.Date, request.OperationId, 0, request.AccountType, request.Description)); } else { await _accountHistoryBufferRepository.AddBufferEntry(new BufferForFutureEntriesDatesModel(request.AccountNumber, emptyAccount, request.Amount, request.DueDate.Date, request.OperationId, request.AccountType, 0, request.Description )); } await _accountHistoryBufferRepository.SaveChangesAsync(); return(_baseHelper.FormMessageResponse(ok, message)); }
/// <summary> /// Добавление записи об изменении счета /// </summary> /// <param name="account">DTO счета</param> /// <param name="operationId">Id операции</param> /// <param name="amount">Сумма изменения по счету</param> /// <param name="isTopUp">Проверка действмя</param> /// <param name="dueDate">Дата влияния на счет</param> /// <param name="description">Описание</param> /// <param name="accountPresent">Нужно ли создавать счет</param> /// <returns></returns> public async Task <ResponseBaseDto> FormAccountEntryResponse(AccountDto account, Guid operationId, decimal amount, bool isTopUp, DateTimeOffset dueDate, string description, bool accountPresent) { var helperListForAccounts = new List <AccountModel>(); var initialBalance = account.Balance; var balance = new decimal(); AccountHistoryModel entry; if (isTopUp) { balance = _helper.TopUpBalance(initialBalance, amount); } else { if (_helper.ValidateAmmount(initialBalance, amount)) { return(_helper.FormMessageResponse(_errorStatus, _message)); } else { balance = _helper.WithDrawlBalance(initialBalance, amount); } } if (accountPresent) { helperListForAccounts.Add(_helper.entryForUpdate(account, balance)); } else { account.Id = await _helper.SaveAccount(account, balance); } if (isTopUp) { entry = new AccountHistoryModel(Guid.Empty, account.Id, amount, balance, dueDate, operationId, description); } else { entry = new AccountHistoryModel(account.Id, amount, balance, dueDate, description, operationId); } await _accountsHistoryRepository.AddEntry(entry); if (helperListForAccounts.Count != 0) { _accountRepository.Update(helperListForAccounts); } if (await _accountsHistoryRepository.SaveChangesAsync() == 0) { throw new ApplicationException(); } var result = new AccountTransferDto { AccountId = account.Id, CurrentBalance = balance }; return(_helper.FormResponseForCreateEntrySolo(result)); }