private void Page_Load(object sender, EventArgs e)
    {
        // Find parent discount object
        if (Page.EditedObjectParent == null)
        {
            return;
        }

        var discount = new Discount(Page.EditedObjectParent);

        // Check if user is allowed to read discount
        if (!DiscountInfoProvider.IsUserAuthorizedToReadDiscount(discount.DiscountSiteID, MembershipContext.AuthenticatedUser))
        {
            Page.EditedObjectParent = null;
        }

        var url = URLHelper.ResolveUrl("~/CMSModules/Ecommerce/Pages/Tools/Discount/Discount_Codes_Generator.aspx");

        url = URLHelper.AddParameterToUrl(url, "discountId", discount.DiscountID.ToString());
        // Inform generator about discount type in case of multi buy discount
        if ((MultiBuyDiscountInfo)discount != null)
        {
            url = URLHelper.AddParameterToUrl(url, "isMultiBuy", "1");
        }

        // Add action for coupon codes generation
        Page.AddHeaderAction(new HeaderAction
        {
            Text        = ResHelper.GetString("com.discount.generatecoupons"),
            RedirectUrl = url,
            Index       = 1,
            Enabled     = discount.DiscountUsesCoupons && DiscountInfoProvider.IsUserAuthorizedToModifyDiscount(SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser),
            ButtonStyle = ButtonStyle.Default
        });
    }
示例#2
0
    void HeaderActions_ActionPerformed(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "generate")
        {
            if (!DiscountInfoProvider.IsUserAuthorizedToModifyDiscount(SiteContext.CurrentSiteName, CurrentUser))
            {
                RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifyDiscounts");
            }

            // Collect data from form
            count        = ValidationHelper.GetInteger(txtNumberOfCodes.Text, 0);
            numberOfUses = ValidationHelper.GetInteger(txtTimesToUse.Text, int.MinValue);
            prefix       = txtPrefix.Text.Trim();

            // Validate inputs
            if (!ValidateInputs())
            {
                return;
            }

            // Set numberOfUses to 0 for empty
            if (string.IsNullOrEmpty(txtTimesToUse.Text))
            {
                numberOfUses = 0;
            }

            // Run action in asynchronous control
            EnsureAsyncLog();
            RunAsync(GenerateCodes);
        }
    }
    void HeaderActions_ActionPerformed(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "generate")
        {
            if (!DiscountInfoProvider.IsUserAuthorizedToModifyDiscount(SiteContext.CurrentSiteName, CurrentUser))
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyDiscounts");
            }

            // Collect data from form
            count        = ValidationHelper.GetInteger(txtNumberOfCodes.Text, 0);
            numberOfUses = ValidationHelper.GetInteger(txtTimesToUse.Text, int.MinValue);
            prefix       = txtPrefix.Text.Trim();

            // Validate inputs
            if (count < 1)
            {
                ShowError(GetString("com.couponcode.invalidcount"));
                return;
            }

            if (!string.IsNullOrEmpty(txtTimesToUse.Text) && ((numberOfUses <= 0) || (numberOfUses > 999999)))
            {
                ShowError(GetString("com.couponcode.invalidnumberOfUses"));
                return;
            }

            if (!string.IsNullOrEmpty(prefix) && !ValidationHelper.IsCodeName(prefix))
            {
                ShowError(GetString("com.couponcode.invalidprefix"));
                return;
            }
            // Set numberOfUses to 0 for empty
            if (string.IsNullOrEmpty(txtTimesToUse.Text))
            {
                numberOfUses = 0;
            }

            // Run action in asynchronous control
            EnsureAsyncLog();
            RunAsync(GenerateCodes);
        }
    }
    private void Page_Load(object sender, EventArgs e)
    {
        // Find parent discount object
        if (Page.EditedObjectParent != null)
        {
            var parentDiscount = (DiscountInfo)Page.EditedObjectParent;

            // Check if user is allowed to read discount
            if (!DiscountInfoProvider.IsUserAuthorizedToReadDiscount(new SiteInfoIdentifier(parentDiscount.DiscountSiteID), MembershipContext.AuthenticatedUser))
            {
                Page.EditedObjectParent = null;
            }

            // Add action for coupon codes generation
            Page.AddHeaderAction(new HeaderAction
            {
                Text        = ResHelper.GetString("com.discount.generatecoupons"),
                RedirectUrl = URLHelper.ResolveUrl("~/CMSModules/Ecommerce/Pages/Tools/Discount/Discount_Codes_Generator.aspx?discountId=" + parentDiscount.DiscountID),
                Index       = 1,
                Enabled     = parentDiscount.DiscountUsesCoupons && DiscountInfoProvider.IsUserAuthorizedToModifyDiscount(SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser)
            });
        }
    }