Example #1
0
        public PurchaseDTO Pay(int clientId, int purchaseId)
        {
            ClientService.CheckCredentials(clientId);
            Purchase purchase = PurchaseService.FindEntity(purchaseId);

            if (purchase.PayingTime != null)
            {
                throw new AppException("Already payed", 400);
            }
            decimal       amount = purchase.Amount;
            ClientAccount source = ClientService.GetAccount(clientId);

            if (amount > source.Balance)
            {
                throw new AppException("Not enough money", 400);
            }
            TraderAccount target = TraderService.GetAccount(purchase.CommercialLink.TraderId);

            PaymentMonitor.Remove(purchaseId);
            source.Balance     -= amount;
            target.Balance     += amount;
            purchase.PayingTime = DateTime.Now;
            ClientAccountService.Update(source);
            TraderAccountService.Update(target);
            purchase = PurchaseService.Update(purchase);
            return(PurchaseService.EntityToDTO(purchase));
        }
Example #2
0
 public MultiService(
     ClientService clientService,
     TraderService traderService,
     CommercialLinkService clService,
     RelatedToBothService <Purchase, PurchaseDTO> purchaseService,
     AccountService <ClientAccount, ClientAccountDTO> clientAccountService,
     AccountService <TraderAccount, TraderAccountDTO> traderAccountService,
     PaymentMonitor paymentMonitor,
     Credentials credentials
     )
 {
     ClService            = clService;
     ClientService        = clientService;
     TraderService        = traderService;
     PurchaseService      = purchaseService;
     ClientAccountService = clientAccountService;
     TraderAccountService = traderAccountService;
     PaymentMonitor       = paymentMonitor;
     Credentials          = credentials;
 }