예제 #1
0
        public ActionResult UserInfo()
        {
            string username = AccountInfo.GetUserName(Request);

            UserinfoModel userinfo = new UserinfoModel();
            DataTable userInfoDataTable = new DataTable();
            UserInfoDetailTableAdapter userInfoDetailAdapter = new UserInfoDetailTableAdapter();
            UserInfoTableAdapter userInfoAdapter = new UserInfoTableAdapter();
            userInfoDataTable = userInfoAdapter.GetDataByUsername(username);
            string userTypeName = null;
            string email = null;
            if (!string.IsNullOrEmpty(userInfoDataTable.Rows[0]["TypeShortName"].ToString()))
            {
                userInfoDataTable = userInfoDetailAdapter.GetDataByUsername(username);
                userTypeName = (string)userInfoDataTable.Rows[0]["TypeName"];
                email = userInfoDataTable.Rows[0]["Email"].ToString();
            }
            else
            {
                AccountTableAdapter accountAdapter = new AccountTableAdapter();
                DataTable accountDataTable = new DataTable();
                accountDataTable = accountAdapter.GetDataByUsername(username);
                email = accountDataTable.Rows[0]["Email"].ToString();
            }
            DateTime date = DateTime.Parse(userInfoDataTable.Rows[0]["LastUpdatedMoney"].ToString());
            int amountOfMoney = (int)userInfoDataTable.Rows[0]["AmountOfMoney"];

            TransactionHistoryTableAdapter transactionAdapter = new TransactionHistoryTableAdapter();
            int? money = transactionAdapter.GetCurrentMoney(username, date);
            if (money == null)
            {
                money = 0;
            }

            amountOfMoney += money.Value;

            userinfo.Username = username;
            userinfo.Name = userInfoDataTable.Rows[0]["Name"].ToString();
            userinfo.TypeName = userTypeName;
            userinfo.Email = email;
            userinfo.AmountOfMoney = amountOfMoney;

            return View(userinfo);
        }
예제 #2
0
        public ActionResult WithdrawMoney(WithdrawMoney model)
        {
            ViewBag.message = "";

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            string updateBy = AccountInfo.GetUserName(Request);
            string username = model.Username;
            int withDrawMoney = model.AmountOfMoney;
            int transactionType = 3;
            string transactionContent = "Rút tiền";

            UserinfoModel userinfo = new UserinfoModel();
            DataTable userInfoDataTable = new DataTable();
            UserInfoDetailTableAdapter userInfoDetailAdapter = new UserInfoDetailTableAdapter();
            UserInfoTableAdapter userInfoAdapter = new UserInfoTableAdapter();
            userInfoDataTable = userInfoAdapter.GetDataByUsername(username);
            //string userTypeName = null;
            //string email = null;
            //if (!string.IsNullOrEmpty(userInfoDataTable.Rows[0]["TypeShortName"].ToString()))
            //{
            //	userInfoDataTable = userInfoDetailAdapter.GetDataByUsername(username);
            //	userTypeName = (string)userInfoDataTable.Rows[0]["TypeName"];
            //	email = userInfoDataTable.Rows[0]["Email"].ToString();
            //}
            //else
            //{
            //	AccountTableAdapter accountAdapter = new AccountTableAdapter();
            //	DataTable accountDataTable = new DataTable();
            //	accountDataTable = accountAdapter.GetDataByUsername(username);
            //	email = accountDataTable.Rows[0]["Email"].ToString();
            //}
            DateTime date = DateTime.Parse(userInfoDataTable.Rows[0]["LastUpdatedMoney"].ToString());
            int amountOfMoney = (int)userInfoDataTable.Rows[0]["AmountOfMoney"];

            TransactionHistoryTableAdapter transactionAdapter = new TransactionHistoryTableAdapter();
            int? money = transactionAdapter.GetCurrentMoney(username, date);
            if (money == null)
            {
                money = 0;
            }

            amountOfMoney += money.Value;

            if (withDrawMoney > amountOfMoney)
            {
                Session["withDrawMoney"] = "Giao dịch thất bại! Số tiền trong tài khoản không đủ để thực hiện giao dịch";
                return View(model);
            }
            else
            {
                try
                {
                    string transactionID = transactionAdapter.RechargeMoneyScalar(username, transactionType, amountOfMoney, transactionContent, null, false, date, updateBy, date).ToString();
                    int id = int.Parse(transactionID);
                    XmlSync.SaveTransactionHistoryXml(id, username, transactionType, amountOfMoney, transactionContent, null, false, date, updateBy, date, null);
                    Session["withDrawMoney"] = "Giao dịch thành công!";
                }
                catch (Exception ex)
                {
                    Log.ErrorLog(ex.Message);
                    Session["withDrawMoney"] = "Giao dịch thất bại!";
                }

                return RedirectToAction("WithdrawMoney","Transaction");
            }
        }
예제 #3
0
        public ActionResult DetailUser(string username)
        {
            UserinfoModel userinfo = new UserinfoModel();
            UserInfoDetailTableAdapter userinfoAdapter = new UserInfoDetailTableAdapter();
            DataTable userinfoDataTable = userinfoAdapter.GetDataByUsername(username);
            DateTime date = DateTime.Parse(userinfoDataTable.Rows[0]["LastUpdatedMoney"].ToString());
            int amountOfMoney = (int)userinfoDataTable.Rows[0]["AmountOfMoney"];

            TransactionHistoryTableAdapter transactionAdapter = new TransactionHistoryTableAdapter();
            int? money = transactionAdapter.GetCurrentMoney(username, date);
            if (money == null)
            {
                money = 0;
            }

            amountOfMoney += money.Value;

            userinfo.Username = username;
            userinfo.Name = userinfoDataTable.Rows[0]["Name"].ToString();
            userinfo.TypeName = (string)userinfoDataTable.Rows[0]["TypeName"];
            userinfo.Email = userinfoDataTable.Rows[0]["Email"].ToString();
            userinfo.AmountOfMoney = amountOfMoney;
            userinfo.Role = (int)userinfoDataTable.Rows[0]["Role"];

            return View(userinfo);
        }