Esempio n. 1
0
        private CashDistributionEngine get_CashDistributionEngineAndCheckBalance(decimal paymentAmount, bool isNonRefundablePaymentAllowed)
        {
            UserId.IsNullOrWhiteSpaceThrowException("You must be logged in");
            decimal amountToBuyShop = MenuPathMain.Payment_To_Buy_Shop();

            Person person = PersonBiz.GetPersonForUserId(UserId);

            person.IsNullThrowException();

            CashBalanceVM cashBalance = BalanceFor_Person(person.Id, CashStateENUM.Available);

            CashDistributionEngine cde = new CashDistributionEngine(
                cashBalance,
                paymentAmount,
                0,
                isNonRefundablePaymentAllowed);


            if (cde.CanBuy())
            {
                string msg = string.Format("You have a total balance of: Rs{0:N2}. Money = {1:N2}, Non Refundable Tokens {2:N2}. You can buy the shop for this month! The expected spending will be as follows: Money = Rs{3:N2}, Tokens = Rs{4:N2}",
                                           cde.CashBalance.Total(),
                                           cde.CashBalance.Refundable,
                                           cde.CashBalance.NonRefundable,
                                           cde.Refundable_Final,
                                           cde.NonRefundable_Final);

                cde.Message = msg;
                return(cde);
            }
            else
            {
                throw new Exception("You have a total balance of: Rs" + cde.CashBalance.Total().ToString("N2") + ". You do not have sufficent money to buy the shop.");
            }
        }
Esempio n. 2
0
        private static decimal getTotalPayment(ShopVM shopCreate)
        {
            if (shopCreate.NoOfMonths == 0)
            {
                throw new Exception("No of months is zero");
            }

            //see if User has the money to do what they want.
            decimal paymentAmount = MenuPathMain.Payment_To_Buy_Shop() * shopCreate.NoOfMonths;

            return(paymentAmount);
        }
Esempio n. 3
0
        private static decimal getShopRatePerMonth()
        {
            decimal ratePerMonth = MenuPathMain.Payment_To_Buy_Shop();

            return(ratePerMonth);
        }
Esempio n. 4
0
        private ControllerCreateEditParameter setup_Shop_Into_ControllerCreateEditParameter(
            ShopVM shopCreate,
            string button,
            HttpPostedFileBase[] httpMiscUploadedFiles,
            Owner userOwner,
            out CashDistributionEngine cde,
            out int quantity,
            out Product product,
            out MenuPathMain mpm,
            out ControllerCreateEditParameter parm)
        {
            decimal paymentAmount = MenuPathMain.Payment_To_Buy_Shop();
            decimal commissionPct = BuySellDoc.Get_Maximum_Commission_Product_Percent();
            bool    isNonRefundablePaymentAllowed = true;

            cde = get_CashDistributionEngineAndCheckBalance(paymentAmount, isNonRefundablePaymentAllowed);

            //check the name, if it is already used, throw error and return to create screen
            if (isShopNameExists(shopCreate.ShopName))
            {
                string err = string.Format("The shop name '{0}' already exists... sorry. Try again.", shopCreate.ShopName);
                throw new Exception(err);
            }
            //create the shop
            //get the shop Child Product
            ProductChild shop = ProductChildBiz.FindForName(ProductChild.GetShopName());

            shop.IsNullThrowException("Shop not found");

            Owner ownerProductChild = shop.Owner;

            ownerProductChild.IsNullThrowException("No Product Child Owner");

            quantity = shopCreate.NoOfMonths;
            if (quantity == 0)
            {
                throw new Exception("The quantity is zero. This is not allowed");
            }

            Customer customerUser = getCustomerOfUser();

            SelectList selectListOwner      = null;
            SelectList selectListCustomer   = null;
            SelectList selectListBillTo     = null;
            SelectList selectListShipTo     = null;
            string     addressBillToId      = "";
            string     addressShipToId      = "";
            decimal    salePrice            = MenuPathMain.Payment_To_Buy_Shop();
            DateTime   expectedDeliveryDate = DateTime.Now;
            DateTime   guaranteePeriodEnds  = DateTime.Now;

            //MenuPathMain mpm = MenuPathMainBiz.Find(shopCreate.MenuPathMainId);
            //mpm.IsNullThrowException("Menu Path Main is null");

            mpm     = getMainMenuPath(shopCreate);
            product = setup_Product_For_Shop(shopCreate, userOwner);

            string shopId = product.Id;

            BuySellDoc sale = CreateSale(
                shop,
                ownerProductChild,
                quantity,
                salePrice,
                customerUser,
                selectListOwner,
                selectListCustomer,
                addressBillToId,
                addressShipToId,
                selectListBillTo,
                selectListShipTo,
                BuySellDocStateENUM.RequestUnconfirmed,
                BuySellDocStateModifierENUM.Accept,
                expectedDeliveryDate,
                guaranteePeriodEnds,
                shopId);

            product.BuySellDocs.Add(sale);

            parm = new ControllerCreateEditParameter(
                product as ICommonWithId,
                httpMiscUploadedFiles,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                MenuENUM.EditDefault,
                UserName,
                UserId,
                shopCreate.ReturnUrl,
                GetGlobalObject(),
                button);

            return(parm);
        }
Esempio n. 5
0
        public async Task <ShopCreatedSuccessfullyVM> Setup_To_Create_Shop_Post_Async(ShopVM shopCreate, string button, HttpPostedFileBase[] httpMiscUploadedFiles)
        {
            UserId.IsNullOrWhiteSpaceThrowException("You are not logged in.");
            shopCreate.MenuPathMainId.IsNullOrWhiteSpaceThrowException("Main Menu Path not received");
            Owner userOwner = OwnerBiz.GetPlayerFor(UserId);

            userOwner.IsNullThrowException("You are not authourized to create a shop. Please become a seller first.");

            if (button == "accept")
            {
                //CashDistributionEngine cde;
                //int quantity;
                //Product product;
                //MenuPathMain mpm;
                //ControllerCreateEditParameter parm = setup_Shop_Into_ControllerCreateEditParameter(shopCreate, button, httpMiscUploadedFiles, userOwner, out cde, out quantity, out product, out mpm, out parm);

                decimal paymentAmount = MenuPathMain.Payment_To_Buy_Shop();
                decimal commissionPct = BuySellDoc.Get_Maximum_Commission_Product_Percent();
                bool    isNonRefundablePaymentAllowed = true;
                CashDistributionEngine cde            = get_CashDistributionEngineAndCheckBalance(paymentAmount, isNonRefundablePaymentAllowed);

                //check the name, if it is already used, throw error and return to create screen
                if (isShopNameExists(shopCreate.ShopName))
                {
                    string err = string.Format("The shop name '{0}' already exists... sorry. Try again.", shopCreate.ShopName);
                    throw new Exception(err);
                }
                //create the shop


                int quantity = shopCreate.NoOfMonths;
                if (quantity == 0)
                {
                    throw new Exception("The quantity is zero. This is not allowed");
                }

                Customer   customerUser         = getCustomerOfUser();
                SelectList selectListOwner      = null;
                SelectList selectListCustomer   = null;
                SelectList selectListBillTo     = null;
                SelectList selectListShipTo     = null;
                string     addressBillToId      = "";
                string     addressShipToId      = "";
                decimal    salePrice            = MenuPathMain.Payment_To_Buy_Shop();
                DateTime   expectedDeliveryDate = DateTime.Now;
                DateTime   guaranteePeriodEnds  = DateTime.Now;

                //MenuPathMain mpm = MenuPathMainBiz.Find(shopCreate.MenuPathMainId);
                //mpm.IsNullThrowException("Menu Path Main is null");

                MenuPathMain mpm     = getMainMenuPath(shopCreate);
                Product      product = setup_Product_For_Shop(shopCreate, userOwner);

                //get the shop Child Product
                ProductChild shopBuySellItem = ProductChildBiz.FindForName(ProductChild.GetShopName());
                shopBuySellItem.IsNullThrowException("Shop not found");

                string shopId = product.Id;
                Owner  ownerOfProductChild = shopBuySellItem.Owner;
                ownerOfProductChild.IsNullThrowException("No Product Child Owner");

                BuySellDoc sale = CreateSale(
                    shopBuySellItem,
                    ownerOfProductChild,
                    quantity,
                    salePrice,
                    customerUser,
                    selectListOwner,
                    selectListCustomer,
                    addressBillToId,
                    addressShipToId,
                    selectListBillTo,
                    selectListShipTo,
                    BuySellDocStateENUM.RequestUnconfirmed,
                    BuySellDocStateModifierENUM.Accept,
                    expectedDeliveryDate,
                    guaranteePeriodEnds,
                    shopId);

                product.BuySellDocs.Add(sale);

                ControllerCreateEditParameter parm = new ControllerCreateEditParameter(
                    product as ICommonWithId,
                    httpMiscUploadedFiles,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    MenuENUM.EditDefault,
                    UserName,
                    UserId,
                    shopCreate.ReturnUrl,
                    GetGlobalObject(),
                    button);

                await ShopBiz.CreateAndSaveAsync(parm);


                decimal  refundable_Spent    = cde.Refundable_Final;
                decimal  nonRefundable_spent = cde.NonRefundable_Final;
                string   shopName            = product.FullName();
                string   mp1Name             = mpm.MenuPath1.FullName();
                string   mp2Name             = mpm.MenuPath2.FullName();
                string   mp3Name             = mpm.MenuPath3.FullName();
                int      numberOfMonths      = quantity;
                DateTime expiryDate          = product.ShopExpiryDate.Date_NotNull_Min;

                ShopCreatedSuccessfullyVM shopCreatedSuccessfully = new ShopCreatedSuccessfullyVM(
                    refundable_Spent,
                    nonRefundable_spent,
                    shopName,
                    mp1Name,
                    mp2Name,
                    mp3Name,
                    numberOfMonths,
                    expiryDate,
                    shopCreate.ReturnUrl);

                //BuySellDocBiz.SaveChanges();
                return(shopCreatedSuccessfully);
            }
            else
            {
                string err = string.Format("You caneled the operation.");
                throw new Exception(err);
            }
        }
Esempio n. 6
0
        public async Task <ShopCreatedSuccessfullyVM> Setup_To_Edit_Shop_Post_Async(ShopVM shopVm, string button, HttpPostedFileBase[] httpMiscUploadedFiles)
        {
            UserId.IsNullOrWhiteSpaceThrowException("You are not logged in.");
            shopVm.IsNullThrowExceptionArgument("Shop");
            button.IsNullOrWhiteSpaceThrowArgumentException("button");
            Owner userOwner = OwnerBiz.GetPlayerFor(UserId);

            userOwner.IsNullThrowException("You are not authourized to create a shop. Please become a seller first.");
            if (button == "accept")
            {
                //locate the shop

                if (shopVm.NoOfMonths == 0)
                {
                    throw new Exception("No of months is zero");
                }
                decimal salePrice = MenuPathMain.Payment_To_Buy_Shop();
                int     quantity  = shopVm.NoOfMonths;

                //see if User has the money to do what they want.
                decimal paymentAmount = salePrice * quantity;

                bool isNonRefundablePaymentAllowed = true;
                CashDistributionEngine cde         = get_CashDistributionEngineAndCheckBalance(paymentAmount, isNonRefundablePaymentAllowed);

                //get the shop Child Product
                ProductChild shopBuySellItem = ProductChildBiz.FindForName(ProductChild.GetShopName());
                shopBuySellItem.IsNullThrowException("Shop not found");

                Owner ownerOfProductChild = shopBuySellItem.Owner;
                ownerOfProductChild.IsNullThrowException("No Product Child Owner");

                Customer customerUser = getCustomerOfUser();

                Product product = ProductBiz.Find(shopVm.Id);
                product.IsNullThrowException("product");
                string shopId = product.Id;
                updateTheProductFromTheShopVm(product, shopVm);

                SelectList selectListOwner      = null;
                SelectList selectListCustomer   = null;
                SelectList selectListBillTo     = null;
                SelectList selectListShipTo     = null;
                string     addressBillToId      = "";
                string     addressShipToId      = "";
                DateTime   expectedDeliveryDate = DateTime.Now;
                DateTime   guaranteePeriodEnds  = DateTime.Now;


                BuySellDoc sale = CreateSale(
                    shopBuySellItem,
                    ownerOfProductChild,
                    quantity,
                    salePrice,
                    customerUser,
                    selectListOwner,
                    selectListCustomer,
                    addressBillToId,
                    addressShipToId,
                    selectListBillTo,
                    selectListShipTo,
                    BuySellDocStateENUM.RequestUnconfirmed,
                    BuySellDocStateModifierENUM.Accept,
                    expectedDeliveryDate,
                    guaranteePeriodEnds,
                    shopId);

                product.BuySellDocs.Add(sale);

                ControllerCreateEditParameter parm = new ControllerCreateEditParameter(
                    product as ICommonWithId,
                    httpMiscUploadedFiles,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    MenuENUM.EditDefault,
                    UserName,
                    UserId,
                    shopVm.ReturnUrl,
                    null, //globalObject not required for products
                    button);

                await ProductBiz.UpdateAndSaveAsync(parm);


                MenuPathMain mpm = product.MenuPathMains_Fixed.FirstOrDefault();

                decimal  refundable_Spent    = cde.Refundable_Final;
                decimal  nonRefundable_spent = cde.NonRefundable_Final;
                string   shopName            = product.FullName();
                string   mp1Name             = mpm.MenuPath1.FullName();
                string   mp2Name             = mpm.MenuPath2.FullName();
                string   mp3Name             = mpm.MenuPath3.FullName();
                int      numberOfMonths      = quantity;
                DateTime expiryDate          = product.ShopExpiryDate.Date_NotNull_Min;

                ShopCreatedSuccessfullyVM shopCreatedSuccessfully = new ShopCreatedSuccessfullyVM(
                    refundable_Spent,
                    nonRefundable_spent,
                    shopName,
                    mp1Name,
                    mp2Name,
                    mp3Name,
                    numberOfMonths,
                    expiryDate,
                    shopVm.ReturnUrl);

                return(shopCreatedSuccessfully);
            }

            return(null);
        }