Ejemplo n.º 1
0
        protected void Page_Init(object sender, System.EventArgs e)
        {
            // locate group to delete
            _GroupId = AlwaysConvert.ToInt(Request.QueryString["GroupId"]);
            Group group = GroupDataSource.Load(_GroupId);

            if (group == null)
            {
                Response.Redirect("Default.aspx");
            }

            // groups managed by the application cannot be deleted
            if (group.IsReadOnly)
            {
                Response.Redirect("Default.aspx");
            }

            // ensure user has permission to edit this group
            IList <Group> managableGroups = SecurityUtility.GetManagableGroups();

            if (managableGroups.IndexOf(group) < 0)
            {
                Response.Redirect("Default.aspx");
            }

            Caption.Text         = string.Format(Caption.Text, group.Name);
            InstructionText.Text = string.Format(InstructionText.Text, group.Name);
            BindGroups(group);
        }
Ejemplo n.º 2
0
 protected void SaveSpecial()
 {
     _Special.Price     = AlwaysConvert.ToDecimal(Price.Text);
     _Special.StartDate = StartDate.SelectedDate;
     _Special.EndDate   = EndDate.SelectedEndDate;
     _Special.Groups.Clear();
     _Special.Save();
     if (SelectedGroups.Checked)
     {
         foreach (ListItem item in Groups.Items)
         {
             CommerceBuilder.Users.Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
             if (item.Selected)
             {
                 _Special.Groups.Add(group);
             }
         }
         if (_Special.Groups.Count == 0)
         {
             SelectedGroups.Checked = false;
             AllGroups.Checked      = true;
         }
     }
     _Special.Save();
 }
 protected void UpdateGroup()
 {
     if (Page.IsValid)
     {
         CommerceBuilder.Users.Group group = GroupDataSource.Load(this.GroupId);
         group.Name = Name.Text;
         group.Roles.Clear();
         group.Save();
         foreach (ListItem roleListItem in RoleList.Items)
         {
             if (roleListItem.Selected)
             {
                 Role role = RoleDataSource.Load(AlwaysConvert.ToInt(roleListItem.Value));
                 group.Roles.Add(role);
             }
         }
         group.Save();
         SavedMessage.Text    = string.Format(SavedMessage.Text, group.Name);
         SavedMessage.Visible = true;
         if (ItemUpdated != null)
         {
             ItemUpdated(this, new PersistentItemEventArgs(this.GroupId, group.Name));
         }
     }
 }
Ejemplo n.º 4
0
 protected void SaveButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         PaymentMethod _PaymentMethod = PaymentMethodDataSource.Load(PaymentMethodId);
         _PaymentMethod.Name = Name.Text;
         _PaymentMethod.PaymentInstrumentType = (PaymentInstrumentType)AlwaysConvert.ToInt16(PaymentInstrumentList.SelectedValue);
         _PaymentMethod.PaymentGateway        = PaymentGatewayDataSource.Load(AlwaysConvert.ToInt(GatewayList.SelectedValue));
         _PaymentMethod.AllowSubscriptions    = AllowSubscriptionPayments.Checked;
         //GROUP RESTRICTION
         _PaymentMethod.Groups.Clear();
         _PaymentMethod.Save();
         if (UseGroupRestriction.SelectedIndex > 0)
         {
             foreach (ListItem item in GroupList.Items)
             {
                 Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                 if (item.Selected)
                 {
                     _PaymentMethod.Groups.Add(group);
                 }
             }
         }
         _PaymentMethod.Save();
         //TRIGER ANY EVENT ATTACHED TO THE UPDATE
         if (ItemUpdated != null)
         {
             ItemUpdated(this, new PersistentItemEventArgs(PaymentMethodId, _PaymentMethod.Name));
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Validates the password against the effective policy
        /// </summary>
        /// <returns>True if the password is valid, false if it does not meet the policy requirements.</returns>
        private bool ValidatePassword()
        {
            // GET THE INITIAL GROUP SO WE CAN DETERMINE PASSWORD POLICY TO EMPLOY
            int groupId = AlwaysConvert.ToInt(AddGroup.SelectedValue);

            CommerceBuilder.Users.Group group = GroupDataSource.Load(groupId);

            // LOAD THE APPROPRIATE PASSWORD POLICY
            PasswordPolicy policy;

            if (IsAdminGroup(group))
            {
                policy = new MerchantPasswordPolicy();
            }
            else
            {
                policy = new CustomerPasswordPolicy();
            }

            PasswordTestResult result = policy.TestPasswordWithFeedback(null, AddPassword.Text);

            if ((result & PasswordTestResult.Success) != PasswordTestResult.Success)
            {
                // THE PASSWORD DOES NOT MEET THE POLICY
                if ((result & PasswordTestResult.PasswordTooShort) == PasswordTestResult.PasswordTooShort)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password length must be at least " + policy.MinLength.ToString() + " characters.");
                }
                if ((result & PasswordTestResult.RequireUpper) == PasswordTestResult.RequireUpper)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one uppercase character.");
                }
                if ((result & PasswordTestResult.RequireLower) == PasswordTestResult.RequireLower)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one lowercase character.");
                }
                if ((result & PasswordTestResult.RequireNumber) == PasswordTestResult.RequireNumber)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one number.");
                }
                if ((result & PasswordTestResult.RequireSymbol) == PasswordTestResult.RequireSymbol)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one symbol (e.g. underscore or punctuation)");
                }
                if ((result & PasswordTestResult.RequireSymbol) == PasswordTestResult.RequireSymbol)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one symbol (e.g. underscore or punctuation)");
                }
                if ((result & PasswordTestResult.RequireNonAlpha) == PasswordTestResult.RequireNonAlpha)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one non-alphabetic character");
                }
                return(false);
            }
            return(true);
        }
        public static bool AssignAllProducts(ProductFilter filter, int[] groupIds, string groupRestrictions)
        {
            int totalCount   = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly);
            int currentIndex = 0;
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            List <Group> groups = new List <Group>();

            foreach (int gid in groupIds)
            {
                Group group = GroupDataSource.Load(gid);
                if (group != null)
                {
                    groups.Add(group);
                }
            }
            while (currentIndex < totalCount)
            {
                IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex);
                foreach (Product p in currentBatch)
                {
                    foreach (Group group in groups)
                    {
                        ProductGroup pg = ProductGroupDataSource.Load(p.Id, group.Id);
                        if (pg == null)
                        {
                            pg = new ProductGroup(p, group);
                            p.ProductGroups.Add(pg);
                        }
                    }

                    switch (groupRestrictions)
                    {
                    case "YES":
                        p.EnableGroups = true;
                        break;

                    case "NO":
                        p.EnableGroups = false;
                        break;

                    default:
                        break;
                    }

                    p.Save();
                }
                currentIndex += 100;
            }

            database.CommitTransaction();
            return(true);
        }
Ejemplo n.º 7
0
        protected void SaveButton_Click(object sender, System.EventArgs e)
        {
            if (Page.IsValid)
            {
                _Affiliate.Name                = Name.Text;
                _Affiliate.ReferralDays        = AlwaysConvert.ToInt16(ReferralDays.Text);
                _Affiliate.CommissionRate      = AlwaysConvert.ToDecimal(CommissionRate.Text);
                _Affiliate.CommissionIsPercent = (CommissionType.SelectedIndex > 0);
                _Affiliate.CommissionOnTotal   = (CommissionType.SelectedIndex == 2);
                _Affiliate.WebsiteUrl          = WebsiteUrl.Text;
                _Affiliate.Email               = Email.Text;
                _Affiliate.Group               = GroupDataSource.Load(AlwaysConvert.ToInt(AffiliateGroup.SelectedValue));

                AffiliateReferralPeriod referralPeriod = (AffiliateReferralPeriod)AlwaysConvert.ToByte(ReferralPeriod.SelectedValue);
                _Affiliate.ReferralPeriodId = (byte)referralPeriod;
                _Affiliate.ReferralPeriod   = referralPeriod;

                if (referralPeriod != AffiliateReferralPeriod.Persistent && referralPeriod != AffiliateReferralPeriod.FirstOrder)
                {
                    _Affiliate.ReferralDays = AlwaysConvert.ToInt16(ReferralDays.Text);
                }
                else
                {
                    _Affiliate.ReferralDays = 0;
                }

                //ADDRESS INFORMATION
                _Affiliate.FirstName    = FirstName.Text;
                _Affiliate.LastName     = LastName.Text;
                _Affiliate.Company      = Company.Text;
                _Affiliate.Address1     = Address1.Text;
                _Affiliate.Address2     = Address2.Text;
                _Affiliate.City         = City.Text;
                _Affiliate.Province     = Province.Text;
                _Affiliate.PostalCode   = PostalCode.Text;
                _Affiliate.CountryCode  = CountryCode.SelectedValue;
                _Affiliate.PhoneNumber  = PhoneNumber.Text;
                _Affiliate.FaxNumber    = FaxNumber.Text;
                _Affiliate.MobileNumber = MobileNumber.Text;
                _Affiliate.Save();

                // SAVE TAX ID
                User user = _Affiliate.Group != null && _Affiliate.Group.Users.Count > 0 ? _Affiliate.Group.Users[0] : null;
                if (user != null)
                {
                    user.TaxExemptionReference = TaxId.Text;
                    user.Save();
                }

                SavedMessage.Visible = true;
                SavedMessage.Text    = string.Format(SavedMessage.Text, LocaleHelper.LocalNow);
            }
        }
Ejemplo n.º 8
0
        private void SaveDiscount()
        {
            VolumeDiscount discount = _VolumeDiscount;

            discount.Name         = Name.Text;
            discount.IsValueBased = IsValueBased.SelectedIndex == 1 ? true : false;
            //LOOP THROUGH GRID ROWS AND SET MATRIX
            int rowIndex = 0;

            foreach (GridViewRow row in DiscountLevelGrid.Rows)
            {
                if (discount.Levels.Count < (rowIndex + 1))
                {
                    // ADD A NEW DISCOUNT LEVEL FOR NEW ROWS
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    newDiscountLevel.Id = _VolumeDiscountId;
                    discount.Levels.Add(newDiscountLevel);
                }
                decimal             minValue       = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("MinValue")).Text);
                decimal             maxValue       = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("MaxValue")).Text);
                decimal             discountAmount = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("DiscountAmount")).Text);
                bool                isPercent      = (((DropDownList)row.FindControl("IsPercent")).SelectedIndex == 0);
                VolumeDiscountLevel thisLevel      = discount.Levels[rowIndex];
                thisLevel.MinValue       = minValue;
                thisLevel.MaxValue       = maxValue;
                thisLevel.DiscountAmount = discountAmount;
                thisLevel.IsPercent      = isPercent;
                thisLevel.Save();
                rowIndex++;
            }
            //SCOPE
            discount.IsGlobal = (UseGlobalScope.SelectedIndex == 0);
            //GROUP RESTRICTION
            if (UseGroupRestriction.SelectedIndex > 0)
            {
                _VolumeDiscount.Groups.Clear();
                _VolumeDiscount.Save();
                foreach (ListItem item in GroupList.Items)
                {
                    Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        _VolumeDiscount.Groups.Add(group);
                    }
                }
            }
            else
            {
                _VolumeDiscount.Groups.Clear();
            }
            discount.Save();
        }
Ejemplo n.º 9
0
        protected String GetGroupName(object id)
        {
            int   groupId = AlwaysConvert.ToInt(id);
            Group group   = GroupDataSource.Load(groupId);

            if (group != null)
            {
                return(group.Name);
            }
            else
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 10
0
        protected string GetGroupName(object dataItem)
        {
            Subscription s = (Subscription)dataItem;
            Group        g = GroupDataSource.Load(AlwaysConvert.ToInt(s.GroupId));

            if (g != null)
            {
                return(g.Name);
            }
            else
            {
                return(string.Empty);
            }
        }
        public static bool AssignProducts(int[] productIds, int[] groupIds, string groupRestrictions)
        {
            List <string>           ids      = new List <string>();
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            List <Group> groups = new List <Group>();

            foreach (int gid in groupIds)
            {
                Group group = GroupDataSource.Load(gid);
                if (group != null)
                {
                    groups.Add(group);
                }
            }

            foreach (int pid in productIds)
            {
                Product product = ProductDataSource.Load(pid);
                foreach (Group group in groups)
                {
                    ProductGroup pg = ProductGroupDataSource.Load(pid, group.Id);
                    if (pg == null)
                    {
                        pg = new ProductGroup(product, group);
                        product.ProductGroups.Add(pg);
                    }
                }

                switch (groupRestrictions)
                {
                case "YES":
                    product.EnableGroups = true;
                    break;

                case "NO":
                    product.EnableGroups = false;
                    break;

                default:
                    break;
                }

                product.Save();
            }
            database.CommitTransaction();
            return(true);
        }
Ejemplo n.º 12
0
        protected void GroupGrid_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int groupId = (int)GroupGrid.DataKeys[e.NewEditIndex].Value;

            CommerceBuilder.Users.Group group = GroupDataSource.Load(groupId);
            if (group != null)
            {
                AddPanel.Visible  = false;
                EditPanel.Visible = true;
                EditCaption.Text  = string.Format(EditCaption.Text, group.Name);
                EditGroupDialog editDialog = EditPanel.FindControl("EditGroupDialog1") as EditGroupDialog;
                if (editDialog != null)
                {
                    editDialog.GroupId = groupId;
                }
                AddEditAjax.Update();
            }
        }
Ejemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _GroupId = AlwaysConvert.ToInt(Request.QueryString["GroupId"]);
            Group group = GroupDataSource.Load(_GroupId);

            if (group == null)
            {
                Response.Redirect("Default.aspx");
            }

            // ensure user has permission to manage this group
            IList <Group> managableGroups = SecurityUtility.GetManagableGroups();

            if (managableGroups.IndexOf(group) < 0)
            {
                Response.Redirect("Default.aspx");
            }

            _IsReadonlyGroup = group.IsReadOnly;
            _Subscriptions   = group.SubscriptionPlans.Count;

            AlphabetRepeater.DataSource = GetAlphabetDS();
            AlphabetRepeater.DataBind();

            if (!Page.IsPostBack)
            {
                SearchGroup.DataSource     = AbleContext.Current.Store.Groups;
                SearchGroup.DataTextField  = "Name";
                SearchGroup.DataValueField = "GroupId";
                SearchGroup.DataBind();

                Caption.Text = string.Format(Caption.Text, group.Name);
                ListItem item = SearchGroup.Items.FindByValue(_GroupId.ToString());
                if (item != null)
                {
                    Session.Remove("ManageUserSearchCriteria");
                    SearchGroup.ClearSelection();
                    item.Selected = true;
                }
                LoadLastSearch();
            }
        }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     CommerceBuilder.Users.Group group = GroupDataSource.Load(this.GroupId);
     if (group != null)
     {
         Name.Text = group.Name;
         RoleList.SelectedIndex = -1;
         foreach (Role role in group.Roles)
         {
             ListItem item = RoleList.Items.FindByValue(role.Id.ToString());
             if (item != null)
             {
                 item.Selected = true;
             }
         }
     }
     else
     {
         this.Controls.Clear();
     }
 }
Ejemplo n.º 15
0
        protected void IsInGroup_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox    isInGroup     = (CheckBox)sender;
            GridViewRow row           = (GridViewRow)isInGroup.NamingContainer;
            GridView    grid          = row.NamingContainer as GridView;
            int         dataItemIndex = (row.DataItemIndex - (grid.PageSize * grid.PageIndex));
            int         userId        = (int)grid.DataKeys[dataItemIndex].Value;

            User user = UserDataSource.Load(userId);

            CommerceBuilder.Users.Group group = GroupDataSource.Load(_GroupId);
            UserGroup userGroup = UserGroupDataSource.Load(user.Id, group.Id);

            if (userGroup == null)
            {
                userGroup = new UserGroup(user, group);
            }
            int index = user.UserGroups.IndexOf(userGroup);

            if (isInGroup.Checked)
            {
                //IN ROLE WAS CHECKED, ADD ROLE IF NOT FOUND
                if (index < 0)
                {
                    user.UserGroups.Add(userGroup);
                    user.UserGroups.Save();
                    AbleContext.Current.Database.FlushSession();
                }
            }
            else
            {
                //IN ROLE WAS UNCHECKED, DELETE ROLE IF FOUND
                if (index > -1)
                {
                    user.UserGroups.DeleteAt(index);
                }
            }
            //REBIND GRIDS
            BindSearchPanel();
        }
        protected void AddButton_Click(object sender, System.EventArgs e)
        {
            PaymentMethod method = new PaymentMethod();

            method.Name = Name.Text;
            method.PaymentInstrumentType = (PaymentInstrumentType)AlwaysConvert.ToInt16(PaymentInstrumentList.SelectedValue);
            method.PaymentGateway        = PaymentGatewayDataSource.Load(AlwaysConvert.ToInt(GatewayList.SelectedValue));
            method.AllowSubscriptions    = AllowSubscriptionPayments.Checked;
            //GROUP RESTRICTION
            if (UseGroupRestriction.SelectedIndex > 0)
            {
                foreach (ListItem item in GroupList.Items)
                {
                    Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        method.Groups.Add(group);
                    }
                }
            }
            method.OrderBy = (short)PaymentMethodDataSource.GetNextOrderBy();
            method.Save();
            //UPDATE THE ADD MESSAGE
            AddedMessage.Text    = string.Format(AddedMessage.Text, method.Name);
            AddedMessage.Visible = true;
            //RESET THE ADD FORM
            PaymentInstrumentList.SelectedIndex = -1;
            Name.Text = string.Empty;
            GatewayList.SelectedIndex         = -1;
            AllowSubscriptionPayments.Checked = false;
            UseGroupRestriction.SelectedIndex = 0;
            BindGroups();
            //TRIGER ANY EVENT ATTACHED TO THE UPDATE
            if (ItemAdded != null)
            {
                ItemAdded(this, new PersistentItemEventArgs(method.Id, method.Name));
            }
        }
Ejemplo n.º 17
0
 protected void SaveButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         Special special = new Special();
         special.Product   = _Product;
         special.Price     = AlwaysConvert.ToDecimal(Price.Text);
         special.StartDate = StartDate.SelectedDate;
         special.EndDate   = EndDate.SelectedEndDate;
         if (SelectedGroups.Checked)
         {
             foreach (ListItem item in Groups.Items)
             {
                 CommerceBuilder.Users.Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                 if (item.Selected)
                 {
                     special.Groups.Add(group);
                 }
             }
         }
         special.Save();
         CancelButton_Click(sender, e);
     }
 }
Ejemplo n.º 18
0
        private void SaveShipMethodMatrix()
        {
            //UPDATE NAME
            _ShipMethod.Name = Name.Text;
            //UPDATE SHIP RATE
            UpdateRanges();
            //UPDATE SURCHARGE
            _ShipMethod.Surcharge = AlwaysConvert.ToDecimal(Surcharge.Text);
            if (_ShipMethod.Surcharge < 0)
            {
                _ShipMethod.Surcharge = 0;
            }
            if (_ShipMethod.Surcharge > 0)
            {
                _ShipMethod.SurchargeMode      = (SurchargeMode)AlwaysConvert.ToByte(SurchargeMode.SelectedValue);
                _ShipMethod.SurchargeIsVisible = (SurchargeIsVisible.SelectedIndex > 0);
            }
            else
            {
                _ShipMethod.SurchargeMode      = 0;
                _ShipMethod.SurchargeIsVisible = false;
            }

            if (_ShipMethod.SurchargeIsVisible)
            {
                _ShipMethod.SurchargeTaxCodeId = AlwaysConvert.ToInt(SurchargeTaxCode.SelectedValue);
            }
            else
            {
                _ShipMethod.SurchargeTaxCodeId = 0;
            }
            //UPDATE WAREHOUSES
            _ShipMethod.Warehouses.Clear();
            _ShipMethod.Save();
            if (UseWarehouseRestriction.SelectedIndex > 0)
            {
                foreach (ListItem item in WarehouseList.Items)
                {
                    Warehouse warehouse = WarehouseDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        _ShipMethod.Warehouses.Add(warehouse);
                    }
                }
            }
            //UPDATE ZONES
            _ShipMethod.ShipZones.Clear();
            _ShipMethod.Save();
            if (UseZoneRestriction.SelectedIndex > 0)
            {
                foreach (ListItem item in ZoneList.Items)
                {
                    ShipZone shipZone = ShipZoneDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        _ShipMethod.ShipZones.Add(shipZone);
                    }
                }
            }
            //UPDATE ROLES
            _ShipMethod.Groups.Clear();
            _ShipMethod.Save();
            if (UseGroupRestriction.SelectedIndex > 0)
            {
                foreach (ListItem item in GroupList.Items)
                {
                    CommerceBuilder.Users.Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        _ShipMethod.Groups.Add(group);
                    }
                }
            }
            //UPDATE MIN PURCHASE
            _ShipMethod.MinPurchase = AlwaysConvert.ToDecimal(MinPurchase.Text);
            //UPDATE MAX PURCHASE
            _ShipMethod.MaxPurchase = AlwaysConvert.ToDecimal(MaxPurchase.Text);
            //UPDATE TAX CODES
            _ShipMethod.TaxCode = TaxCodeDataSource.Load(AlwaysConvert.ToInt(TaxCode.SelectedValue));
            //SAVE METHOD AND REDIRECT TO LIST
            _ShipMethod.Save();
        }
Ejemplo n.º 19
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // DUPLICATE TAX RULE NAMES SHOULD NOT BE ALLOWED
                int taxRuleId = TaxRuleDataSource.GetTaxRuleIdByName(Name.Text);
                if (taxRuleId > 0)
                {
                    // TAX RULE(S) WITH SAME NAME ALREADY EXIST
                    CustomValidator customNameValidator = new CustomValidator();
                    customNameValidator.ControlToValidate = "Name";
                    customNameValidator.Text         = "*";
                    customNameValidator.ErrorMessage = "A Tax Rule with the same name already exists.";
                    customNameValidator.IsValid      = false;
                    phNameValidator.Controls.Add(customNameValidator);
                    return;
                }
                //SAVE TAX RULE
                TaxRule taxRule = new TaxRule();
                taxRule.Name              = Name.Text;
                taxRule.TaxRate           = AlwaysConvert.ToDecimal(TaxRate.Text);
                taxRule.UseBillingAddress = AlwaysConvert.ToBool(UseBillingAddress.SelectedValue.Equals("1"), false);
                taxRule.TaxCodeId         = AlwaysConvert.ToInt(TaxCode.SelectedValue);
                taxRule.Priority          = AlwaysConvert.ToInt16(Priority.Text);
                taxRule.UsePerItemTax     = PerUnitCalculation.Checked;
                taxRule.Save();
                //UPDATE TAX CODES
                taxRule.TaxCodes.Clear();
                taxRule.Save();
                foreach (ListItem listItem in TaxCodes.Items)
                {
                    if (listItem.Selected)
                    {
                        TaxCode taxCode = TaxCodeDataSource.Load(AlwaysConvert.ToInt(listItem.Value));
                        taxRule.TaxCodes.Add(taxCode);
                        listItem.Selected = false;
                    }
                }
                //UPDATE ZONES
                taxRule.ShipZones.Clear();
                if (ZoneRule.SelectedIndex > 0)
                {
                    foreach (ListItem item in ZoneList.Items)
                    {
                        ShipZone shipZone = ShipZoneDataSource.Load(AlwaysConvert.ToInt(item.Value));
                        if (item.Selected)
                        {
                            taxRule.ShipZones.Add(shipZone);
                        }
                    }
                }
                //UPDATE GROUP FILTER
                taxRule.Groups.Clear();
                taxRule.GroupRule = (FilterRule)GroupRule.SelectedIndex;
                if (taxRule.GroupRule != FilterRule.All)
                {
                    foreach (ListItem item in GroupList.Items)
                    {
                        Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                        if (item.Selected)
                        {
                            taxRule.Groups.Add(group);
                        }
                    }
                }
                //IF NO GROUPS ARE SELECTED, APPLY TO ALL GROUPS
                if (taxRule.Groups.Count == 0)
                {
                    taxRule.GroupRule = FilterRule.All;
                }

                // UPDATE ROUNDING RULE
                taxRule.RoundingRuleId = AlwaysConvert.ToByte(RoundingRule.SelectedValue);

                taxRule.Save();
                //UPDATE THE ADD MESSAGE
                Response.Redirect("TaxRules.aspx");
            }
        }
Ejemplo n.º 20
0
        private void SaveProduct()
        {
            // get a reference to the loaded product
            // this assists in file comparions between add/edit page
            Product product = _Product;

            // basic product information pane
            product.Name           = Name.Text;
            product.ManufacturerId = AlwaysConvert.ToInt(ManufacturerList.SelectedValue);
            product.Price          = AlwaysConvert.ToDecimal(Price.Text);
            product.ModelNumber    = ModelNumber.Text;
            product.MSRP           = AlwaysConvert.ToDecimal(Msrp.Text);
            product.Weight         = AlwaysConvert.ToDecimal(Weight.Text);
            product.CostOfGoods    = AlwaysConvert.ToDecimal(CostOfGoods.Text);
            product.GTIN           = Gtin.Text;
            product.Sku            = Sku.Text;
            product.IsFeatured     = IsFeatured.Checked;

            // descriptions
            product.Summary             = Summary.Text;
            product.Description         = Description.Text;
            product.ExtendedDescription = ExtendedDescription.Text;

            // shipping, tax, and inventory
            product.WarehouseId = AlwaysConvert.ToInt(Warehouse.SelectedValue);
            product.VendorId    = AlwaysConvert.ToInt(Vendor.SelectedValue);
            product.ShippableId = (byte)AlwaysConvert.ToInt(IsShippable.SelectedValue);
            product.Length      = AlwaysConvert.ToDecimal(Length.Text);
            product.Width       = AlwaysConvert.ToDecimal(Width.Text);
            product.Height      = AlwaysConvert.ToDecimal(Height.Text);
            product.TaxCodeId   = AlwaysConvert.ToInt(TaxCode.SelectedValue);
            if (CurrentInventoryMode.Visible)
            {
                product.InventoryModeId = AlwaysConvert.ToByte(CurrentInventoryMode.SelectedIndex);
                if (product.InventoryMode == InventoryMode.Product)
                {
                    product.InStock             = AlwaysConvert.ToInt(InStock.Text);
                    product.AvailabilityDate    = AvailabilityDate.SelectedDate;
                    product.InStockWarningLevel = AlwaysConvert.ToInt(LowStock.Text);
                    product.AllowBackorder      = BackOrder.Checked;
                }
                else if (product.InventoryMode == InventoryMode.Variant)
                {
                    product.AllowBackorder = BackOrder.Checked;
                }

                product.EnableRestockNotifications = EnableRestockNotifications.Checked;
            }

            // advanced settings
            product.WrapGroupId       = AlwaysConvert.ToInt(WrapGroup.SelectedValue);
            product.AllowReviews      = AllowReviewsPanel.Visible ? AllowReviews.Checked : true;
            product.Visibility        = (CatalogVisibility)Visibility.SelectedIndex;
            product.HidePrice         = HidePrice.Checked;
            product.Webpage           = WebpageDataSource.Load(AlwaysConvert.ToInt(DisplayPage.SelectedValue));
            product.IsProhibited      = IsProhibited.Checked;
            product.IsGiftCertificate = GiftCertificate.Checked;
            product.DisablePurchase   = DisablePurchase.Checked;
            product.UseVariablePrice  = UseVariablePrice.Checked;
            product.MinimumPrice      = AlwaysConvert.ToDecimal(MinPrice.Text);
            product.MaximumPrice      = AlwaysConvert.ToDecimal(MaxPrice.Text);
            product.HandlingCharges   = AlwaysConvert.ToDecimal(HandlingCharges.Text);
            product.MinQuantity       = AlwaysConvert.ToInt16(MinQuantity.Text);
            product.MaxQuantity       = AlwaysConvert.ToInt16(MaxQuantity.Text);
            product.HtmlHead          = HtmlHead.Text.Trim();
            product.SearchKeywords    = SearchKeywords.Text.Trim();
            _Product.EnableGroups     = AlwaysConvert.ToBool(EnableGroups.SelectedValue, false);
            _Product.ProductGroups.DeleteAll();
            foreach (ListItem item in ProductGroups.Items)
            {
                if (item.Selected)
                {
                    int          groupId = AlwaysConvert.ToInt(item.Value);
                    ProductGroup pg      = new ProductGroup(_Product, GroupDataSource.Load(groupId));
                    _Product.ProductGroups.Add(pg);
                }
            }

            // search engines and feeds
            product.CustomUrl = CustomUrl.Text;
            CustomUrlValidator.OriginalValue = _Product.CustomUrl;
            product.ExcludeFromFeed          = !IncludeInFeed.Checked;
            product.Title                 = ProductTitle.Text.Trim();
            product.MetaDescription       = MetaDescriptionValue.Text.Trim();
            product.MetaKeywords          = MetaKeywordsValue.Text.Trim();
            product.GoogleCategory        = GoogleCategory.Text;
            product.Condition             = Condition.SelectedValue;
            product.Gender                = Gender.SelectedValue;
            product.AgeGroup              = AgeGroup.SelectedValue;
            product.Color                 = Color.Text;
            product.Size                  = Size.Text;
            product.AdwordsGrouping       = AdwordsGrouping.Text;
            product.AdwordsLabels         = AdwordsLabels.Text;
            product.ExcludedDestination   = ExcludedDestination.SelectedValue;
            product.AdwordsRedirect       = AdwordsRedirect.Text;
            product.PublishFeedAsVariants = PublishAsVariants.Checked;

            // TAX CLOUD PRODUCT TIC
            if (trTIC.Visible && !string.IsNullOrEmpty(HiddenTIC.Value))
            {
                product.TIC = AlwaysConvert.ToInt(HiddenTIC.Value);
            }
            else
            {
                product.TIC = null;
            }

            // save product
            product.Save();
            ModalPopupExtender.Hide();
        }
Ejemplo n.º 21
0
        protected int SaveCoupon()
        {
            if (Page.IsValid)
            {
                // VALIDATE IF A PROPER END DATE IS SELECTED
                if (EndDate.SelectedEndDate != DateTime.MinValue && DateTime.Compare(EndDate.SelectedEndDate, StartDate.SelectedEndDate) < 0)
                {
                    CustomValidator dateValidator = new CustomValidator();
                    dateValidator.ControlToValidate = "Name"; // THIS SHOULD BE "EndDate" CONTROL, BUT THAT CANNOT BE VALIDATED
                    dateValidator.Text         = "*";
                    dateValidator.ErrorMessage = "End date can not be earlier than start date.";
                    dateValidator.IsValid      = false;
                    phEndDateValidator.Controls.Add(dateValidator);
                    return(0);
                }

                Coupon existingCoupon = CouponDataSource.LoadForCouponCode(CouponCode.Text);
                if (existingCoupon != null)
                {
                    CustomValidator codeValidator = new CustomValidator();
                    codeValidator.ControlToValidate = "CouponCode";
                    codeValidator.Text         = "*";
                    codeValidator.ErrorMessage = "The coupon code " + CouponCode.Text + " is already in use.";
                    codeValidator.IsValid      = false;
                    phCouponCodeValidator.Controls.Add(codeValidator);
                    return(0);
                }

                Coupon _Coupon = new Coupon();
                _Coupon.CouponType     = this.CouponType;
                _Coupon.Name           = Name.Text;
                _Coupon.CouponCode     = CouponCode.Text;
                _Coupon.DiscountAmount = AlwaysConvert.ToDecimal(DiscountAmount.Text);
                _Coupon.IsPercent      = (DiscountType.SelectedIndex == 0);
                //QUANTITY SETTINGS (PRODUCT COUPON)
                if (_Coupon.CouponType == CouponType.Product)
                {
                    _Coupon.MinQuantity = AlwaysConvert.ToInt16(Quantity.Text);
                    if (RepeatCoupon.Checked)
                    {
                        _Coupon.MaxQuantity      = 0;
                        _Coupon.QuantityInterval = _Coupon.MinQuantity;
                    }
                    else
                    {
                        _Coupon.MaxQuantity      = _Coupon.MinQuantity;
                        _Coupon.QuantityInterval = 0;
                    }
                    _Coupon.MaxValue    = 0;
                    _Coupon.MinPurchase = 0;
                }
                //PURCHASE RESTRICTIONS (ORDER AND SHIPPING COUPONS)
                else
                {
                    _Coupon.MaxValue         = AlwaysConvert.ToDecimal(MaxValue.Text);
                    _Coupon.MinPurchase      = AlwaysConvert.ToDecimal(MinPurchase.Text);
                    _Coupon.MinQuantity      = 0;
                    _Coupon.MaxQuantity      = 0;
                    _Coupon.QuantityInterval = 0;
                }
                //SET START DATE
                _Coupon.StartDate = StartDate.SelectedDate;
                //SET END DATE
                _Coupon.EndDate = EndDate.SelectedEndDate;
                //MAX USES
                _Coupon.MaxUsesPerCustomer = AlwaysConvert.ToInt16(MaximumUsesPerCustomer.Text);
                _Coupon.MaxUses            = AlwaysConvert.ToInt16(MaximumUses.Text);
                //COMBINE RULE
                _Coupon.AllowCombine = AllowCombine.Checked;
                //PRODUCT (OR SHIPPING) RULE
                if (_Coupon.CouponType != CouponType.Shipping)
                {
                    _Coupon.ProductRule = (CouponRule)ProductRule.SelectedIndex;
                }
                else
                {
                    _Coupon.ProductRule = (CouponRule)ShipMethodRule.SelectedIndex;
                    _Coupon.ShipMethods.Clear();
                    _Coupon.Save();
                    if (_Coupon.ProductRule != CouponRule.All)
                    {
                        foreach (ListItem item in ShipMethodList.Items)
                        {
                            ShipMethod shipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(item.Value));
                            if (item.Selected)
                            {
                                _Coupon.ShipMethods.Add(shipMethod);
                            }
                        }
                    }
                }
                //GROUP RESTRICTION
                if (UseGroupRestriction.SelectedIndex > 0)
                {
                    _Coupon.Groups.Clear();
                    _Coupon.Save();
                    foreach (ListItem item in GroupList.Items)
                    {
                        Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                        if (item.Selected)
                        {
                            _Coupon.Groups.Add(group);
                        }
                    }
                }
                _Coupon.Save();
                return(_Coupon.Id);
            }
            return(0);
        }
Ejemplo n.º 22
0
        private bool Save()
        {
            if (!Page.IsValid)
            {
                return(false);
            }
            _DigitalGood.Name             = Name.Text;
            _DigitalGood.FileName         = FileName.Text;
            _DigitalGood.MediaKey         = MediaKey.Text;
            _DigitalGood.ActivationModeId = AlwaysConvert.ToByte(ActivationMode.SelectedValue);
            _DigitalGood.MaxDownloads     = AlwaysConvert.ToByte(MaxDownloads.Text);
            int tempDays    = AlwaysConvert.ToInt(ActivationTimeoutDays.Text);
            int tempHours   = AlwaysConvert.ToInt(ActivationTimeoutHours.Text);
            int tempMinutes = AlwaysConvert.ToInt(ActivationTimeoutMinutes.Text);

            if ((tempDays > 0) || (tempHours > 0) || (tempMinutes > 0))
            {
                _DigitalGood.ActivationTimeout = string.Format("{0},{1},{2}", tempDays, tempHours, tempMinutes);
            }
            else
            {
                _DigitalGood.ActivationTimeout = string.Empty;
            }
            tempDays    = AlwaysConvert.ToInt(DownloadTimeoutDays.Text);
            tempHours   = AlwaysConvert.ToInt(DownloadTimeoutHours.Text);
            tempMinutes = AlwaysConvert.ToInt(DownloadTimeoutMinutes.Text);
            if ((tempDays > 0) || (tempHours > 0) || (tempMinutes > 0))
            {
                _DigitalGood.DownloadTimeout = string.Format("{0},{1},{2}", tempDays, tempHours, tempMinutes);
            }
            else
            {
                _DigitalGood.DownloadTimeout = string.Empty;
            }

            //VALIDATE THE FILE SIE
            if (System.IO.File.Exists(_DigitalGood.AbsoluteFilePath))
            {
                //READ THE EXISTING FILE SIZE
                System.IO.FileInfo fi = new System.IO.FileInfo(_DigitalGood.AbsoluteFilePath);
                _DigitalGood.FileSize = fi.Length;
            }

            //CHECK THE README TEXT
            _DigitalGood.LicenseAgreementId     = AlwaysConvert.ToInt(LicenseAgreement.SelectedValue);
            _DigitalGood.LicenseAgreementModeId = AlwaysConvert.ToByte(LicenseAgreementMode.SelectedValue);
            _DigitalGood.ReadmeId         = AlwaysConvert.ToInt(Readme.SelectedValue);
            _DigitalGood.EnableSerialKeys = EnableSerialKeys.Checked;
            //Check serial key provider
            if (string.IsNullOrEmpty(KeySource.SelectedValue) ||
                KeySource.SelectedValue.Equals("0"))
            {
                _DigitalGood.SerialKeyProviderId = null;
            }
            else
            {
                _DigitalGood.SerialKeyProviderId = KeySource.SelectedValue;
            }

            //Check fulfillment mode
            if (FulfillmentMode.SelectedValue.Equals("0"))
            {
                _DigitalGood.FulfillmentMode = CommerceBuilder.DigitalDelivery.FulfillmentMode.Manual;
            }
            else if (FulfillmentMode.SelectedValue.Equals("1"))
            {
                _DigitalGood.FulfillmentMode = CommerceBuilder.DigitalDelivery.FulfillmentMode.OnOrder;
            }
            else
            {
                _DigitalGood.FulfillmentMode = CommerceBuilder.DigitalDelivery.FulfillmentMode.OnPaidOrder;
            }

            //Check Activation Email
            if (string.IsNullOrEmpty(ActivationEmailTemplateList.SelectedValue) ||
                ActivationEmailTemplateList.SelectedValue.Equals("0"))
            {
                _DigitalGood.ActivationEmailId = 0;
            }
            else
            {
                _DigitalGood.ActivationEmailId = AlwaysConvert.ToInt(ActivationEmailTemplateList.SelectedValue);
            }

            //Check Fulfillment Email
            if (string.IsNullOrEmpty(FulfillmentEmailTemplateList.SelectedValue) ||
                FulfillmentEmailTemplateList.SelectedValue.Equals("0"))
            {
                _DigitalGood.FulfillmentEmailId = 0;
            }
            else
            {
                _DigitalGood.FulfillmentEmailId = AlwaysConvert.ToInt(FulfillmentEmailTemplateList.SelectedValue);
            }


            _DigitalGood.DigitalGoodGroups.DeleteAll();
            foreach (ListItem item in Groups.Items)
            {
                if (item.Selected)
                {
                    int groupId          = AlwaysConvert.ToInt(item.Value);
                    DigitalGoodGroup dgg = new DigitalGoodGroup(_DigitalGood, GroupDataSource.Load(groupId));
                    _DigitalGood.DigitalGoodGroups.Add(dgg);
                }
            }

            _DigitalGood.Save();
            ToggleConfigureProvider();
            return(true);
        }