public void MakeTransaction(TransactionArguments args) { try { ValidateTransaction(args); var seller = clientTableRepository.GetById(args.SellerId); var buyer = clientTableRepository.GetById(args.BuyerId); var sellersItem = GetItemFromPortfolio(seller, args.SharesId); var buyersItem = GetItemFromPortfolio(buyer, args.SharesId); decimal sum = sharesTableRepository.GetById(args.SharesId).Price *args.Quantity; seller.Balance += sum; sellersItem.Quantity -= args.Quantity; buyer.Balance -= sum; buyersItem.Quantity += args.Quantity; clientTableRepository.Change(seller); clientTableRepository.Change(buyer); clientSharesTableRepository.Change(sellersItem); clientSharesTableRepository.Change(buyersItem); clientTableRepository.SaveChanges(); clientSharesTableRepository.SaveChanges(); WriteTransactionHistory(args, sum); } catch (Exception ex) { throw new Exception($"Transaction failed : {ex.Message}"); } }
public void PutMoneyToBalance(ArgumentsForPutMoneyToBalance args) { if (!clientTableRepository.ContainsById(args.ClientId)) { throw new ArgumentException($"Client with Id {args.ClientId} doesn't exist"); } ClientEntity clientToChangeBalance = clientTableRepository.GetById(args.ClientId); clientToChangeBalance.Balance += args.AmountToPut; clientTableRepository.Change(clientToChangeBalance); clientTableRepository.SaveChanges(); }