Esempio n. 1
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. 2
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);
        }