private void SaveOperation(OperationContent operationContent, OperationContractModel operation) { _operationUnitOfWork.AccountRepository.Update(operationContent.ToAccount); _operationUnitOfWork.AccountRepository.Update(operationContent.FromAccount); operationContent.ToStorages.ForEach(x => { _operationUnitOfWork.StorageRepository.Update(x); }); operationContent.FromStorages.ForEach(x => { _operationUnitOfWork.StorageRepository.Update(x); }); SaveInOperationArchive(operationContent.FromAccount, operationContent.ToAccount, operation); }
private OperationContent PrepareOperation(OperationContractModel operation) { var operationContent = InitializeOperationContent(operation); CalculateAmount(operationContent.Rates, operation.Items); operationContent.OperationAmount = operation.Items.Sum(x => x.ItemAmount); return(operationContent); }
public void BuyItems(OperationContractModel operation) { var operationContent = PrepareOperation(operation); if (operationContent.ToAccount.AvailableBalance < operationContent.OperationAmount) { throw new Exception("You don't have enough money for operation"); } new Transaction().MakeBuyTransaction(operationContent, operation); SaveOperation(operationContent, operation); }
private OperationContent InitializeOperationContent(OperationContractModel operation) { var operationContent = new OperationContent { Rates = GetCurrentRates(operation.Items), ToAccount = GetAccountInfoByAccoundId(operation.AccountOwnerToAccountId), ToStorages = GetStoragesByAccountNumber(operation.AccountOwnerToAccountId), FromAccount = GetAccountInfoByAccoundId(operation.AccountOwnerFromAccountId), FromStorages = GetStoragesByAccountNumber(operation.AccountOwnerFromAccountId), }; return(operationContent); }
private void SaveInOperationArchive(AccountContractModel accountFrom, AccountContractModel accountTo, OperationContractModel operation) { _operationUnitOfWork.OperationArchiveRepository.CreateMany(operation.Items.Select(x => new OperationArchiveContractModel { ItemTypeId = x.ItemTypeId, AccountFromId = accountFrom.Id, AccountToId = accountTo.Id, OperationAmount = x.ItemAmount, Quantity = x.Quantity })); }
public OperationContent MakeBuyTransaction(OperationContent operationContent, OperationContractModel operation) { TakeAmountIntoAccount(operationContent); operationContent.ToStorages = AddItems(operationContent.ToStorages, operation.Items).ToList(); operationContent.FromStorages = DeductItems(operationContent.FromStorages, operation.Items).ToList(); return(operationContent); }