public ActionResult add(Models.Wallet wallet)
        {
            SqlConnectionStringBuilder constr = new SqlConnectionStringBuilder("Data Source=DESKTOP-N9AAJ82\\SKERDI;Initial Catalog=KEMBIM_VALUTOR;Integrated Security=True");
            string qrstr = "select eur, gbp, \"all\", usd from wallet where user_id = " + Session["user_id"] + "";

            using (SqlConnection con = new SqlConnection(constr.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(qrstr, con);
                con.Open();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    reader.Read();
                    try
                    {
                        wallet.Eur += (double)reader[0];
                        wallet.Gbp += (double)reader[1];
                        wallet.All += (double)reader[2];
                        wallet.Usd += (double)reader[3];
                    }
                    catch (Exception)
                    {
                    }
                }
                string     qrstradd = "Update wallet set eur = " + wallet.Eur + ",gbp = " + wallet.Gbp + ",\"all\" = " + wallet.All + ",usd = " + wallet.Usd + "";
                SqlCommand cmdadd   = new SqlCommand(qrstradd, con);
                cmdadd.ExecuteNonQuery();
                con.Close();
            }
            return(RedirectToAction("wallet"));
        }
예제 #2
0
        public WalletConfigurationView(Models.Wallet wallet)
        {
            InitializeComponent();
            var walletModel = new WalletConfigurationViewModel(wallet);

            DataContext = walletModel;
        }
예제 #3
0
        /// <summary>
        /// 提现申请
        /// </summary>
        /// <returns></returns>
        public bool AuditApply(Guid id)
        {
            using (var dbContext = new WalletDbContext())
            {
                CrashApply crashApply = dbContext.CrashApplys.FirstOrDefault(c => c.Id == id);
                if (crashApply == null)
                {
                    throw new Exception("找不到提现的记录");
                }
                crashApply.ApplyState = ApplyState.ApplyPassed;
                crashApply.AuditTime  = DateTime.Now;
                dbContext.Set <CrashApply>().Attach(crashApply);
                dbContext.Entry(crashApply).State = EntityState.Modified;

                Models.Wallet wallet = GetWalletByMemberId(crashApply.MemberId);
                if (wallet == null)
                {
                    throw new Exception("钱包是空的");
                }
                else if (crashApply.Money > wallet.Frozen)
                {
                    throw new Exception("提现的金额不能大于冻结的金额");
                }

                return(dbContext.SaveChanges() > 0);
            }
        }
예제 #4
0
        public async Task <ActionResult <Models.Wallet> > PostWallet(Models.Wallet wallet)
        {
            _context.Wallet.Add(wallet);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetWallet", new { id = wallet.Id }, wallet));
        }
예제 #5
0
        public async Task <IActionResult> PutWallet(int id, Models.Wallet wallet)
        {
            if (id != wallet.Id)
            {
                return(BadRequest());
            }

            _context.Entry(wallet).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WalletExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #6
0
        public bool Deposit(string memberId, WalletType walletType, decimal money, string remark, out string error, string tag = null, string fromMemberId = null)
        {
            error = string.Empty;
            if (money == 0)
            {
                return(true);
            }
            using (var dbContext = new WalletDbContext())
            {
                var wallet =
                    dbContext.Set <Models.Wallet>()
                    .FirstOrDefault(w => w.WalletType == walletType && w.MemberId.Equals(memberId, StringComparison.OrdinalIgnoreCase));
                if (wallet == null)
                {
                    wallet            = new Models.Wallet();
                    wallet.Id         = KeyGenerator.GetGuidKey();
                    wallet.MemberId   = memberId;
                    wallet.WalletType = walletType;
                    wallet.Frozen     = 0;
                    wallet.Available  = money;
                    dbContext.Wallets.Add(wallet);
                }
                else
                {
                    wallet.Available += money;
                    dbContext.Set <Models.Wallet>().Attach(wallet);
                    dbContext.Entry(wallet).State = EntityState.Modified;
                }

                WalletBill walletBill = new WalletBill();
                walletBill.Id           = KeyGenerator.GetGuidKey();
                walletBill.MemberId     = memberId;
                walletBill.BillType     = BillType.TakeIn;
                walletBill.WalletType   = walletType;
                walletBill.Money        = money;
                walletBill.Remark       = remark;
                walletBill.BillTag      = tag;
                walletBill.CreateTime   = DateTime.Now;
                walletBill.FromMemberId = fromMemberId;
                dbContext.WalletBills.Add(walletBill);
                dbContext.SaveChanges();
                return(true);
            }
        }
        public ActionResult wallet(Models.Wallet wallet)
        {
            SqlConnectionStringBuilder constr = new SqlConnectionStringBuilder("Data Source=DESKTOP-N9AAJ82\\SKERDI;Initial Catalog=KEMBIM_VALUTOR;Integrated Security=True");
            string qrstr = "select EUR,GBP," + "\"ALL\"" + ",USD from wallet where user_id = '" + Session["user_id"] + "'";

            using (SqlConnection con = new SqlConnection(constr.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(qrstr, con);
                con.Open();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    reader.Read();
                    try
                    {
                        wallet.Eur = (double)reader[0];
                    }
                    catch (Exception)
                    { wallet.Eur = 0; }
                    try
                    {
                        wallet.Gbp = (double)reader[1];
                    }
                    catch (Exception)
                    { wallet.Gbp = 0; }
                    try
                    {
                        wallet.All = (double)reader[2];
                    }
                    catch (Exception)
                    { wallet.All = 0; }
                    try
                    {
                        wallet.Usd = (double)reader[3];
                    }
                    catch (Exception)
                    { wallet.Usd = 0; }

                    reader.Close();
                }
            }
            ViewBag.edit = false;

            return(View(wallet));
        }
예제 #8
0
        /// <summary>
        /// 申请提现
        /// </summary>
        public bool ApplyCrash(string memberId, string account, decimal money, PaymentType paymentType, string name)
        {
            using (var dbContext = new WalletDbContext())
            {
                CrashApply crashApply = new CrashApply();
                crashApply.Id            = KeyGenerator.GetGuidKey();
                crashApply.MemberId      = memberId;
                crashApply.Account       = account;
                crashApply.TransactionNo = KeyGenerator.GetOrderNumber();
                crashApply.RealName      = name;
                crashApply.Money         = money;
                crashApply.PaymentType   = paymentType;
                crashApply.ApplyState    = ApplyState.Applying;
                crashApply.CreateTime    = DateTime.Now;
                dbContext.CrashApplys.Add(crashApply);

                if (paymentType == PaymentType.WeiXin)
                {
                    //判断是否绑定了微信
                }

                Models.Wallet wallet = GetWalletByMemberId(memberId);
                if (wallet == null)
                {
                    throw new WebApiInnerException("0003", "钱包没有可以提现的余额");
                }
                else
                {
                    if (money > wallet.Available)
                    {
                        throw new WebApiInnerException("0004", "提现的金额不能大于钱包的余额");
                    }
                    wallet.Frozen    += money;
                    wallet.Available -= money;
                }
                dbContext.Set <Models.Wallet>().Attach(wallet);
                dbContext.Entry(wallet).State = EntityState.Modified;

                return(dbContext.SaveChanges() > 0);
            }
        }
예제 #9
0
        public async Task <CreateTransferResult> Handle(CreateTransferCommand command, CancellationToken cancellationToken)
        {
            if (command.UserName == null)
            {
                throw new ResultFailedException();
            }

            var user = await _context.Users.Include(u => u.Wallets).FirstOrDefaultAsync(u => u.Id == command.UserId);

            if (!user.Wallets.Any(w => w.Currency == command.SourceCurrency))
            {
                return(CreateTransferResult.ReturnFailure());
            }

            var source = user.Wallets.FirstOrDefault(w => w.Currency == command.SourceCurrency);

            if (source.Amount < command.Amount)
            {
                return(CreateTransferResult.ReturnFailure());
            }

            if (command.DestinationCurrency != null)
            {
                if (command.SourceCurrency == command.DestinationCurrency)
                {
                    throw new Exception();
                }

                var userDestinationOWnWallet = user.Wallets.FirstOrDefault(w => w.Currency == command.DestinationCurrency);

                if (userDestinationOWnWallet == null)
                {
                    throw new Exception();
                }


                var convertedAmount = _converterOfCurrency.ConvertCurrency(command.SourceCurrency, command.DestinationCurrency, command.Amount);

                source.Amount -= command.Amount;
                userDestinationOWnWallet.Amount += convertedAmount;

                var transaction = new Transaction
                {
                    SourceUsername      = user.UserName,
                    DestinationUsername = command.UserName,
                    Currency            = command.SourceCurrency,
                    Amount = command.Amount,
                    Date   = DateTime.Now,
                };
                _context.Add(transaction);
            }
            else
            {
                var destinationUser = _context.Users.Include(w => w.Wallets).FirstOrDefault(u => u.UserName == command.UserName);

                if (destinationUser == null)
                {
                    throw new ResultFailedException();
                }



                var destinationWallet = destinationUser.Wallets.FirstOrDefault(w => w.Currency == command.SourceCurrency);


                if (destinationWallet == null)
                {
                    destinationWallet = new Models.Wallet
                    {
                        Amount   = 0,
                        Currency = command.SourceCurrency,
                    };

                    destinationUser.Wallets.Add(destinationWallet);
                }

                source.Amount            -= command.Amount;
                destinationWallet.Amount += command.Amount;

                var transaction = new Transaction
                {
                    SourceUsername      = user.UserName,
                    DestinationUsername = destinationUser.UserName,
                    Currency            = command.SourceCurrency,
                    Amount = command.Amount,
                    Date   = DateTime.Now,
                };

                _context.Add(transaction);
            }

            _context.SaveChanges();

            return(CreateTransferResult.ReturnSuccess());
        }