示例#1
0
 public static void SwitchType(RandomGeneratorType type)
 {
     if (generator.type != type)
     {
         generator = RandomNumerGenerator.GetGenerator(type);
     }
 }
 public OnePayTransaction SaveTransaction(TransactionItemDTO transaction, bool status)
 {
     try
     {
         _transaction = new OnePayTransaction();
         _transaction.TransactionId            = "T" + RandomNumerGenerator.GetRandomNumber(10);
         _transaction.TransactionComment       = "Transaction from OnePay for AccountId";
         _transaction.TransactionAmount        = transaction.TransactionAmount;
         _transaction.UserId                   = transaction.UserId;
         _transaction.AccountId                = transaction.AccountId;
         _transaction.PaccountId               = transaction.PAccountId;
         _transaction.TransactionTypeId        = transaction.TransactionType;
         _transaction.TransactionStatusId      = (status) ? (int)TransactionStatusTypes.Successful : (int)TransactionStatusTypes.Declined;
         _transaction.TransactionProvideTypeId = transaction.TransactionProviderType;
         _transaction.Timestamp                = DateTime.Now.ToString();
         if (_transaction != null)
         {
             _context.OnePayTransaction.Add(_transaction);
             _context.SaveChanges();
         }
     }
     catch (AppException ex)
     {
         throw new AppException("Transaction not successful", ex.Message);
     }
     return(_transaction);
 }
示例#3
0
        public UserAccount Create(UserAccount userAccount)
        {
            // validation
            if (userAccount == null)
            {
                throw new AppException("No Account");
            }
            userAccount.AccountId = "ONE" + RandomNumerGenerator.GetRandomNumber(8);
            if (_context.UserAccount.Any(x => x.AccountId == userAccount.AccountId))
            {
                throw new AppException("AccountId \"" + userAccount.AccountId + "\" is already taken");
            }

            try
            {
                _context.UserAccount.Add(userAccount);
                _context.SaveChanges();
            }
            catch (AppException ex)
            {
                throw new AppException("User Account not Created", ex.Message);
            }


            return(userAccount);
        }