Ejemplo n.º 1
0
 /// <summary>
 /// 转账
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public OperateResult TransferMoney(TransferMoneyViewModel model)
 {
     SqlParameter[] pams =
     {
         new SqlParameter("@userId",          model.UserId),
         new SqlParameter("@fromMerberCarId", model.FromMerberCardId),
         new SqlParameter("@toMerberCaId",    model.ToMerberCardId),
         new SqlParameter("@transferMoney",   model.TransferMoney),
         new SqlParameter("@remark",          model.Remark),
         new SqlParameter("@errorMsg",        System.Data.SqlDbType.NVarChar, 128)
     };
     pams[5].Direction = System.Data.ParameterDirection.Output;
     try
     {
         db.Database.ExecuteSqlCommand("EXEC dbo.SP_TransferMoney @userId,@fromMerberCarId,@toMerberCaId,@transferMoney,@remark,@errorMsg output", pams);
         if (!string.IsNullOrWhiteSpace(pams[5].Value.ToString()))
         {
             return(new OperateResult(false, pams[5].Value.ToString()));
         }
         else
         {
             return(new OperateResult(false, "转账成功"));
         }
     }
     catch (Exception e)
     {
         return(new OperateResult(false, e.Message));
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 会员转账
 /// </summary>
 /// <param name="viewModel"></param>
 /// <returns></returns>
 public OperateResult TransferMoney(TransferMoneyViewModel viewModel)
 {
     if (viewModel.UserId == 0)
     {
         return(new OperateResult(ResultStatus.Error, "转账人ID为空"));
     }
     if (string.IsNullOrWhiteSpace(viewModel.FromMemberCardId))
     {
         return(new OperateResult(ResultStatus.Error, "转账人卡号为空"));
     }
     if (string.IsNullOrWhiteSpace(viewModel.ToMemberCardId))
     {
         return(new OperateResult(ResultStatus.Error, "被转账人卡号为空"));
     }
     if (viewModel.TransferMoney == 0)
     {
         return(new OperateResult(ResultStatus.Error, "转账金额为0"));
     }
     if (string.IsNullOrWhiteSpace(viewModel.Remark))
     {
         viewModel.Remark = "";
     }
     SqlParameter[] pams =
     {
         new SqlParameter("@userId",           viewModel.UserId),
         new SqlParameter("@fromMemberCardId", viewModel.FromMemberCardId),
         new SqlParameter("@toMemberCardId",   viewModel.ToMemberCardId),
         new SqlParameter("@transferMoney",    viewModel.TransferMoney),
         new SqlParameter("@remark",           viewModel.Remark),
         new SqlParameter("@errorMsg",         System.Data.SqlDbType.NVarChar,128),
     };
     //指定输出参数
     pams[5].Direction = System.Data.ParameterDirection.Output;
     try
     {
         db.Database.ExecuteSqlCommand("EXEC dbo.SP_TransferMoney @userId,@fromMemberCardId,@toMemberCardId,@transferMoney,@remark,@errorMsg output", pams);
         //如果errorMsg有值,说明执行存储过程判断逻辑有问题
         if (!string.IsNullOrWhiteSpace(pams[5].Value.ToString()))
         {
             return(new OperateResult(ResultStatus.Error, pams[5].Value.ToString()));
         }
         else
         {
             return(new OperateResult(ResultStatus.Success, "转账成功"));
         }
     }
     catch (Exception ex)
     {
         return(new OperateResult(ResultStatus.Error, ex.Message));
     }
     //https://www.cnblogs.com/blogs2014/p/5310093.html 错误级别解释
 }
Ejemplo n.º 3
0
        public ActionResult TransferMoney(TransferMoneyViewModel viewModel)
        {
            var userId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                viewModel.CustomerBankAccs = unitOfWork.BankAccounts.GetCheckingAndSavingsBankAccs(userId);
                return(View("TransferMoney", viewModel));
            }

            var transactions    = new List <Transaction>();
            var transactionType = unitOfWork.TransactionTypes.GetTransactionType(viewModel.TransactionCategory);
            var debitAccount    = unitOfWork.BankAccounts.GetJustBankAccount(viewModel.DebitAccNo);
            var creditAccNo     = viewModel.CreditAccNo ?? viewModel.CreditAccIban.Substring(10);
            var creditAccount   = unitOfWork.BankAccounts.GetJustBankAccount(creditAccNo);

            if (creditAccount == null)
            {
                viewModel.CustomerBankAccs = unitOfWork.BankAccounts.GetCheckingAndSavingsBankAccs(userId);
                viewModel.ErrorMessage     = "Credit Bank Account could not be found.";
                return(View("TransferMoney", viewModel));
            }

            if (!debitAccount.InitiateTransaction(creditAccount, viewModel.Amount.Value, transactionType, null, out transactions))
            {
                viewModel.CustomerBankAccs = unitOfWork.BankAccounts.GetCheckingAndSavingsBankAccs(userId);
                viewModel.ErrorMessage     = "Could not complete transaction.";
                return(View("TransferMoney", viewModel));
            }

            foreach (var transaction in transactions)
            {
                unitOfWork.Transactions.AddTransaction(transaction);
            }
            unitOfWork.Complete();

            var transHub = new
            {
                DebitAccountNo  = debitAccount.AccountNumber,
                DebitBalance    = debitAccount.Balance,
                CreditAccountNo = creditAccount.AccountNumber,
                CreditBalance   = creditAccount.Balance,
                DebitAmount     = transactions[0].DebitAmount,
                Time            = transactions[0].ValueDateTime.ToLongTimeString(),
                Date            = transactions[0].ValueDateTime.ToLongDateString()
            };

            SignalHub.GetTransactions(transHub);
            return(RedirectToAction("Index", new { AccountNumber = debitAccount.AccountNumber }));
        }
 public TransferMoneyView(TransferMoneyViewModel model)
 {
     InitializeComponent();
     this._ViewModel  = model;
     this.DataContext = this._ViewModel;
     if (_ViewModel.MustCompare == true)
     {
         PART_TextBox.IsReadOnly      = false;
         TransferDatepicker.IsEnabled = true;
     }
     else
     {
         btnNew.IsEnabled             = false;
         PART_TextBox.IsReadOnly      = true;
         TransferDatepicker.IsEnabled = false;
     }
 }
Ejemplo n.º 5
0
        public ActionResult TransferMoney(string accountNumber)
        {
            var userId           = User.Identity.GetUserId();
            var customerBankAccs = unitOfWork.BankAccounts.GetCheckingAndSavingsBankAccs(userId);

            if (accountNumber != null)
            {
                customerBankAccs = customerBankAccs.Where(a => a.AccountNumber == accountNumber);
            }

            var viewModel = new TransferMoneyViewModel()
            {
                CustomerBankAccs    = customerBankAccs,
                TransactionCategory = TransactionCategory.MoneyTransfer
            };

            return(View(viewModel));
        }
Ejemplo n.º 6
0
        public async Task <string> Transfer(TransferMoneyViewModel model)
        {
            var client = await ClientManager.GetByEmail(User.Claims.Single(x => x.Type == ClaimTypes.Email).Value);

            try
            {
                if (await CashAccountManager.Transfer(client.Id, model.ReceiverId, model.Amount))
                {
                    return("Success");
                }
                else
                {
                    return("Unhandled exception");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 7
0
 public ActionResult TransferL(TransferMoneyViewModel t)
 {
     t.UserId = 1;
     return(Json(_MemberCardService.TransferMoney(t)));
     // return Content("<script>window.parent.$('#dlg').dialog('close');window.parent.$('#dg').datagrid('reload');window.parent.$.messager.alert('提示','" + s + "','info');</script>");
 }
 public TransferMoneyView()
 {
     InitializeComponent();
     DataContext = new TransferMoneyViewModel();
 }