コード例 #1
0
        public Boolean ResellerPurchaseBulk()
        {
            List <reseller>         res = db.resellers.ToList();
            WalletHandlerController wc  = new WalletHandlerController();


            foreach (reseller temp  in res)
            {
                //  wc.buyBulkVoucher(temp.User_ID, );
            }



            return(true);
        }
コード例 #2
0
        public async Task <Boolean> GenerateTransactiions(int consumerStart, int numResellers, int monthStart, int yearStart)
        {
            var res = db.resellers.ToArray();
            var con = db.consumers.ToArray();
            WalletHandlerController         wc = new WalletHandlerController();
            ConsumerWalletHandlerController cw = new ConsumerWalletHandlerController();

            int[] healthOptions     = { 211, 221, 231 };
            int[] familyOptions     = { 161, 151, 141 };
            int[] individualOptions = { 131, 121, 101 };



            int ConsumerIncrement = 8;


            Random   random = new Random();
            int      resllerCounter;
            int      continueM = consumerStart;
            DateTime LASTYear  = new DateTime(yearStart, monthStart, 01);

            resllerCounter = numResellers;

            var run = true;

            while (run)
            {
                for (int r = continueM; r < resllerCounter; r++)
                {
                    List <ConsumerPurchases> purchases = new List <ConsumerPurchases>();
                    consumer       temp;
                    List <product> prod        = db.products.ToList();
                    decimal?       overallCost = 0;

                    for (int c = r * ConsumerIncrement; c < (r + 1) * ConsumerIncrement; c++)
                    {
                        temp = con.ElementAt(c);
                        int               assets   = random.Next(100);
                        int               travel   = random.Next(100);
                        int               funeral  = random.Next(100);
                        int               medical  = random.Next(100);
                        decimal?          salary   = temp.grossMonthlyIncome;
                        ConsumerPurchases purchase = new ConsumerPurchases();
                        purchase.ConsumerID = con[c].User_ID;
                        purchase.cost       = 0;
                        int purchaseNo = 0;

                        if (assets < 85)
                        {
                            if (salary > 3000)
                            {
                                purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (31)).ipUnitCost;
                                purchase.data[purchaseNo] = 31;
                            }
                            else
                            {
                                purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (241)).ipUnitCost;
                                purchase.data[purchaseNo] = 241;
                            }
                            purchaseNo++;
                        }

                        if (travel < 76)
                        {
                            if (salary > 4000)
                            {
                                purchase.data[purchaseNo] = 91;
                                purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (91)).ipUnitCost;
                            }
                            else if (temp.employmentStatus == "Employed")
                            {
                                purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (41)).ipUnitCost;
                                purchase.data[purchaseNo] = 41;
                            }
                            purchaseNo++;
                        }

                        if (medical < 65)
                        {
                            if (salary > 4000)
                            {
                                purchase.data[purchaseNo] = healthOptions[medical % 3];
                                int pos = healthOptions[medical % 3];
                                purchase.cost += db.insuranceproducts.Single(e => e.Product_ID == pos).ipUnitCost;
                            }
                            else if (salary > 2600)
                            {
                                purchase.data[purchaseNo] = 71;
                                purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (71)).ipUnitCost;
                            }
                            purchaseNo++;
                        }

                        if (funeral < 85)
                        {
                            if (temp.maritalStatus.CompareTo("Single") == 1)
                            {
                                if (salary > 4000)
                                {
                                    purchase.data[purchaseNo] = 131;
                                    purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (131)).ipUnitCost;
                                }
                                else if (salary > 3000)
                                {
                                    purchase.data[purchaseNo] = 121;
                                    purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (121)).ipUnitCost;
                                }
                                else if (salary > 2000)
                                {
                                    purchase.data[purchaseNo] = 101;
                                    purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (101)).ipUnitCost;
                                }
                            }

                            if (temp.maritalStatus.CompareTo("Married") == 1 || temp.numDependant >= 2)
                            {
                                if (salary > 4000)
                                {
                                    purchase.data[purchaseNo] = 161;
                                    purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (161)).ipUnitCost;
                                }
                                else if (salary > 3000)
                                {
                                    purchase.data[purchaseNo] = 151;
                                    purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (151)).ipUnitCost;
                                }
                                else if (salary > 2000)
                                {
                                    purchase.data[purchaseNo] = 141;
                                    purchase.cost            += db.insuranceproducts.Single(e => e.Product_ID == (141)).ipUnitCost;
                                }
                            }

                            purchaseNo++;
                        }
                        overallCost += purchase.cost;
                        purchases.Add(purchase);
                    }
                    int resID = res.ElementAt(r).User_ID;
                    await wc.buyBulkVoucher(resID, (Decimal)overallCost + 60);


                    foreach (var s  in purchases)
                    {
                        await wc.sendBulkVoucher(resID, s.ConsumerID, (Decimal)s.cost + 3);

                        int count = 0;
                        foreach (var pur  in s.data)
                        {
                            count++;
                            if (pur != 0)
                            {
                                await cw.redeemProduct(s.ConsumerID, pur, 1, DateTime.Now);
                            }
                        }
                    }
                }

                if (resllerCounter < 10)
                {
                    resllerCounter++;
                }

                continueM = 0;

                LASTYear = LASTYear.AddMonths(1);

                run = false;
            }



            return(true);
        }