コード例 #1
0
 public BankOperationModel Transfer(InterbankCardTransferCommand command)
 {
     EnsureIsValid(command);
     EnsureIsSecure <InterbankCardTransferCommand, CardSecurityValidator>(command);
     try
     {
         var fromCard = _deps.UserCards.SurelyFind(command.FromCardId);
         var toCard   = _deps.UserCards.QueryOne(DbQuery.For <UserCard>().FilterBy(x => x.CardNo == command.ToCardNo));
         if (toCard == null)
         {
             throw NotFound.ExceptionFor <UserCard>(command.ToCardNo);
         }
         var transfer = _deps.CardTransferFactory.Create(fromCard, toCard, command.Amount);
         _deps.CardTransfers.Create(transfer);
         var userOperation = new UserBankOperation(transfer, Identity.User);
         _deps.UserBankOperations.Create(userOperation);
         Commit();
         var model = transfer.ToModel <BankOperation, BankOperationModel>();
         Publish(new OperationProgressEvent(Operation.Id, model));
         return(model);
     }
     catch (DomainException ex)
     {
         throw new UserMessageException(new UserMessage(ex.Message, ex.GetType().Name));
     }
     catch (Exception ex)
     {
         throw new ServiceException("Can't create transfer.", ex);
     }
 }
コード例 #2
0
 public BankOperationModel Submit(SubmitPaymentCommand command)
 {
     EnsureIsValid(command);
     EnsureIsSecure <SubmitPaymentCommand, CardSecurityValidator>(command);
     try
     {
         var userCard    = _deps.UserCards.SurelyFind(command.FromCardId);
         var template    = _deps.PaymentTemplates.SurelyFind(command.TemplateCode);
         var payment     = _deps.CardPaymentFactory.Create(userCard, template, command.Form);
         var paymentLink = new PaymentTransactionLink(payment.Withdrawal, payment.Order);
         _deps.Payments.Create(payment);
         _deps.PaymentTransactionLinks.Create(paymentLink);
         var userOperation = new UserBankOperation(payment, Identity.User);
         _deps.UserBankOperations.Create(userOperation);
         Commit();
         var model = payment.ToModel <BankOperation, BankOperationModel>();
         Publish(new OperationProgressEvent(Operation.Id, model));
         return(model);
     }
     catch (Exception ex)
     {
         throw new ServiceException("Can't submit payment.", ex);
     }
 }