예제 #1
0
        public ActionResult CharityDonation(FormCollection frm)
        {
            string charityid    = frm["charirtyid"].ToString();
            string userid       = frm["fromid"].ToString();
            string amount       = frm["givamt"].ToString();
            int    amt          = Convert.ToInt32(amount);
            int    charitygrpid = Convert.ToInt32(charityid);
            Int64  user         = Convert.ToInt64(userid);

            using (givedbEntities ent = new givedbEntities())
            {
                var fromEntity  = ent.KidsDatas.Where(x => x.Id == user).FirstOrDefault();
                var frombalance = ent.KidBalances.Where(x => x.KidId == fromEntity.Id).First();


                var newfromid = frombalance.Give - amt;
                frombalance.Give    = newfromid;
                frombalance.Balance = frombalance.Balance - amt;
                ent.SaveChanges();
            }
            using (givedbEntities ent1 = new givedbEntities())
            {
                var grp = ent1.CharityGroups.Where(x => x.Id == charitygrpid).First().KidsData;

                var balance   = ent1.KidBalances.Where(x => x.KidId == grp.Id).First();
                var newfromid = balance.Give + amt;
                balance.Give    = newfromid;
                balance.Balance = balance.Balance + amt;
                ent1.SaveChanges();
            }
            using (givedbEntities entnew = new givedbEntities())
            {
                var fromEntity = entnew.KidsDatas.Where(x => x.Id == user).FirstOrDefault();

                var    grp      = entnew.CharityGroups.Where(x => x.Id == charitygrpid).First().KidsData;
                string comments = amt.ToString() + " Give Sent To " + grp.Name;
                //    string sentcomments = amnt.ToString() + " Give Received from " + fromEntity.Name;
                KidTransaction trans = new KidTransaction();
                trans.FromKidID   = fromEntity.Id;
                trans.ToAddress   = grp.Id.ToString();
                trans.Amount      = amt;
                trans.Description = comments;
                //trans.ReceivedDescription = sentcomments;
                trans.TransactionDate = DateTime.Now;
                trans.SubWalletType   = 2;
                entnew.KidTransactions.Add(trans);
                entnew.SaveChanges();
            }
            return(RedirectToAction("MyWallet", "Home", new { id = userid }));
        }
예제 #2
0
        public ActionResult SubWalletTransferConfirm(int kidid, string sourceSubWallet, string targetSubWallet, int amt)
        {
            int subWalletTypeId = 1;

            switch (sourceSubWallet)
            {
            case "freedom":
                subWalletTypeId = 1;
                break;

            case "saving":
                subWalletTypeId = 5;
                break;

            case "give":
                subWalletTypeId = 2;
                break;

            case "play":
                subWalletTypeId = 4;
                break;

            case "education":
                subWalletTypeId = 3;
                break;

            default:
                subWalletTypeId = 1;
                break;
            }

            using (givedbEntities ent = new givedbEntities())
            {
                KidTransaction trans = new KidTransaction();
                trans.FromKidID       = kidid;
                trans.ToAddress       = kidid.ToString();
                trans.Amount          = amt;
                trans.Description     = "transferred from '" + sourceSubWallet + "' sub-wallet to '" + targetSubWallet + "' sub-wallet.";
                trans.TransactionDate = DateTime.Now;
                trans.SubWalletType   = subWalletTypeId;
                ent.KidTransactions.Add(trans);
                ent.SaveChanges();
            }
            using (givedbEntities ent1 = new givedbEntities())
            {
                var parent = ent1.KidBalances.Where(x => x.KidId == kidid).First();

                switch (sourceSubWallet)
                {
                case "freedom":
                    parent.Freedom = (parent.Freedom - amt);
                    break;

                case "saving":
                    parent.Savings = (parent.Savings - amt);
                    break;

                case "give":
                    parent.Give = (parent.Give - amt);
                    break;

                case "play":
                    parent.Play = (parent.Play - amt);
                    break;

                case "education":
                    parent.Education = (parent.Education - amt);
                    break;

                default:
                    break;
                }
                ent1.SaveChanges();
            }

            using (givedbEntities ent2 = new givedbEntities())
            {
                var reciever = ent2.KidBalances.Where(x => x.Id == kidid).FirstOrDefault();

                switch (targetSubWallet)
                {
                case "freedom":
                    reciever.Freedom = (reciever.Freedom + amt);
                    break;

                case "saving":
                    reciever.Savings = (reciever.Savings + amt);
                    break;

                case "give":
                    reciever.Give = (reciever.Give + amt);
                    break;

                case "play":
                    reciever.Play = (reciever.Play + amt);
                    break;

                case "education":
                    reciever.Education = (reciever.Education + amt);
                    break;

                default:
                    break;
                }
                ent2.SaveChanges();
            }

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        public ActionResult SendGIV(FormCollection frm)
        {
            string parentid   = frm["parentid"].ToString();
            string roleValue1 = frm.Get("kiddp");
            string subwallet  = frm.Get("subwallet");
            int    walletid   = 0;

            switch (subwallet)
            {
            case "Play":
                walletid = 4;
                break;

            case "Give":
                walletid = 2;
                break;
            }
            if (roleValue1 == "Select Recipient")
            {
                return(View(new { id = parentid }));
            }
            else
            {
                string amount = frm["givamt"].ToString();
                // string address = frm["givaddress"].ToString();
                int parid = Convert.ToInt32(parentid);
                int amnt  = Convert.ToInt32(amount);
                using (givedbEntities ent = new givedbEntities())
                {
                    var fromEntity = ent.KidsDatas.Where(x => x.Id == parid).FirstOrDefault();

                    var    ToEntity = ent.KidsDatas.Where(x => x.Name == roleValue1).FirstOrDefault();
                    string comments = amnt.ToString() + " Give Sent To " + ToEntity.Name;
                    //    string sentcomments = amnt.ToString() + " Give Received from " + fromEntity.Name;
                    KidTransaction trans = new KidTransaction();
                    trans.FromKidID   = parid;
                    trans.ToAddress   = ToEntity.Id.ToString();
                    trans.Amount      = amnt;
                    trans.Description = comments;
                    //trans.ReceivedDescription = sentcomments;
                    trans.TransactionDate = DateTime.Now;
                    trans.SubWalletType   = walletid;
                    ent.KidTransactions.Add(trans);
                    ent.SaveChanges();
                }
                using (givedbEntities ent1 = new givedbEntities())
                {
                    var  parent     = ent1.KidBalances.Where(x => x.KidId == parid).First();
                    long?newbalance = parent.Balance - amnt;
                    parent.Balance = newbalance;
                    if (walletid == 4)
                    {
                        Int32?playbalance = parent.Play - amnt;
                        parent.Play = playbalance;
                    }
                    if (walletid == 2)
                    {
                        Int32?givbalance = parent.Give - amnt;
                        parent.Give = givbalance;
                    }
                    ent1.SaveChanges();
                }

                using (givedbEntities ent2 = new givedbEntities())
                {
                    var reciever = ent2.KidsDatas.Where(x => x.Name == roleValue1).FirstOrDefault();
                    if (reciever != null)
                    {
                        var  receiverval = ent2.KidBalances.Where(x => x.KidId == reciever.Id).First();
                        long?newbalance1 = receiverval.Balance + amnt;
                        receiverval.Balance = newbalance1;
                        if (walletid == 4)
                        {
                            Int32?playbalance = receiverval.Play + amnt;
                            receiverval.Play = playbalance;
                        }
                        if (walletid == 2)
                        {
                            Int32?givbalance = receiverval.Give + amnt;
                            receiverval.Give = givbalance;
                        }
                        ent2.SaveChanges();
                    }
                }

                // ViewBag.id = id;
                return(RedirectToAction("MyWallet", "Home", new { id = parentid }));
            }
        }