public void Calculate(Cart cart, int prefID)
        {
            List <ShippingOrderValue> shippingSettings = ShippingDAL.GetShippingOrderValue(ShippingOptionType.TotalAmount, _isRushShipping, prefID).OrderBy(s => s.OrderTotal).ToList();

            decimal cartSubtotal = cart.SubTotal;


            int totalShippingSettings = shippingSettings.Count;

            for (int i = 0; i < totalShippingSettings; i++)
            {
                ShippingOrderValue currentSetting = shippingSettings[i];
                if (cartSubtotal <= currentSetting.OrderTotal ||
                    i == totalShippingSettings - 1)
                {
                    // add additional shipping charge by specified key
                    ShippingCharge shippingCharge = ShippingDAL.GetShippingCharge(prefID, cart.ShippingChargeKey);
                    if (shippingCharge != null)
                    {
                        cart.AdditionalShippingCharge = shippingCharge.Cost;
                    }

                    if (_isRushShipping)
                    {
                        cart.RushShippingCost = currentSetting.Cost;
                    }
                    else
                    {
                        cart.ShippingCost = currentSetting.Cost;
                    }
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public void Calculate(Cart cart, int prefID)
        {
            List <ShippingOrderValue> shippingSettings = ShippingDAL.GetShippingOrderValue(ShippingOptionType.Weight, _isRushShipping, prefID).OrderBy(s => s.OrderTotal).ToList();

            bool           withQuantity = false;
            decimal        cartWeight;
            SitePreference sp = CSFactory.GetCacheSitePref();

            if (!sp.AttributeValuesLoaded)
            {
                sp.LoadAttributeValues();
            }
            if (sp.AttributeValues.ContainsKey("qtyinweightbasedshipping"))
            {
                if (sp.AttributeValues["qtyinweightbasedshipping"].BooleanValue)
                {
                    withQuantity = true;
                }
            }
            if (withQuantity)
            {
                cartWeight = cart.CartItems.Sum(c => c.Weight * c.Quantity);
            }
            else
            {
                cartWeight = cart.CartItems.Sum(c => c.Weight);
            }

            int totalShippingSettings = shippingSettings.Count;

            for (int i = 0; i < totalShippingSettings; i++)
            {
                ShippingOrderValue currentSetting = shippingSettings[i];
                if (cartWeight <= currentSetting.OrderTotal ||
                    i == totalShippingSettings - 1)
                {
                    // add additional shipping charge by specified key
                    ShippingCharge shippingCharge = ShippingDAL.GetShippingCharge(prefID, cart.ShippingChargeKey);
                    if (shippingCharge != null)
                    {
                        cart.AdditionalShippingCharge = shippingCharge.Cost;
                    }

                    if (_isRushShipping)
                    {
                        cart.RushShippingCost = currentSetting.Cost;
                    }
                    else
                    {
                        cart.ShippingCost = currentSetting.Cost;
                    }

                    break;
                }
            }
        }
Exemplo n.º 3
0
        protected void btnSave_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                ShippingOptionType option     = ShippingOptionType.TotalAmount;
                ShippingOptionType optionRush = ShippingOptionType.TotalAmount;

                if (pnlOrderVal.Visible)
                {
                    option = ShippingOptionType.TotalAmount;
                    if (this.rptItems.Items.Count > 0)
                    {
                        using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())
                               )
                        {
                            foreach (RepeaterItem lst in rptItems.Items)
                            {
                                if ((lst.ItemType == ListItemType.Item) ||
                                    (lst.ItemType == ListItemType.AlternatingItem))
                                {
                                    int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                    TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                    TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                    ShippingOrderValue order       =
                                        context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                    order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                    order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                    context.SubmitChanges();
                                }
                            }
                        }
                    }
                } //end if for Shipping OrderValue

                if (pnlWeight.Visible)
                {
                    option = ShippingOptionType.Weight;
                    if (this.rptOrderWeight.Items.Count > 0)
                    {
                        using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())
                               )
                        {
                            foreach (RepeaterItem lst in rptOrderWeight.Items)
                            {
                                if ((lst.ItemType == ListItemType.Item) ||
                                    (lst.ItemType == ListItemType.AlternatingItem))
                                {
                                    int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                    TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                    TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                    ShippingOrderValue order       =
                                        context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                    order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                    order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                    context.SubmitChanges();
                                }
                            }
                        }
                    }
                } //end if for Shipping OrderWeight

                if (pnlSkuItem.Visible)
                {
                    option = ShippingOptionType.SkuBased;
                    if (this.rptSkuItem.Items.Count > 0)
                    {
                        using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())
                               )
                        {
                            foreach (RepeaterItem lst in rptSkuItem.Items)
                            {
                                if ((lst.ItemType == ListItemType.Item) ||
                                    (lst.ItemType == ListItemType.AlternatingItem))
                                {
                                    int         Id         = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text);
                                    TextBox     txtCostVal = (TextBox)lst.FindControl("txtPercentage");
                                    SkuShipping order      =
                                        context.SkuShippings.FirstOrDefault(
                                            p => (p.SkuId == Id) && (p.IncludeRushShipping == false) && (p.PrefId == 1));
                                    if (order != null)
                                    {
                                        order.Cost = Convert.ToDecimal(txtCostVal.Text);
                                        context.SubmitChanges();
                                    }
                                    else
                                    {
                                        SkuShipping item = new SkuShipping();
                                        item.SkuId = Id;
                                        item.Cost  = Convert.ToDecimal(txtCostVal.Text);
                                        item.IncludeRushShipping = false;
                                        item.PrefId = 1;
                                        context.SkuShippings.InsertOnSubmit(item);
                                        context.SubmitChanges();
                                    }
                                }
                            }
                        }
                    }
                } //end if for Shipping SkuItem level

                if (pnlFlat.Visible)
                {
                    option = ShippingOptionType.Flat;
                }

                if (cbRushShippingOption.Checked)
                {
                    if (pnlRushOrderTotal.Visible)
                    {
                        optionRush = ShippingOptionType.TotalAmount;
                        if (this.rptRushOrderTotal.Items.Count > 0)
                        {
                            using (
                                CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())
                                )
                            {
                                foreach (RepeaterItem lst in rptRushOrderTotal.Items)
                                {
                                    if ((lst.ItemType == ListItemType.Item) ||
                                        (lst.ItemType == ListItemType.AlternatingItem))
                                    {
                                        int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                        TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                        TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                        ShippingOrderValue order       =
                                            context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                        order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                        order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                        context.SubmitChanges();
                                    }
                                }
                            }
                        }
                    }

                    if (pnlRushOrderweight.Visible)
                    {
                        optionRush = ShippingOptionType.Weight;
                        if (this.rptRushOrderWeight.Items.Count > 0)
                        {
                            using (
                                CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())
                                )
                            {
                                foreach (RepeaterItem lst in rptRushOrderWeight.Items)
                                {
                                    if ((lst.ItemType == ListItemType.Item) ||
                                        (lst.ItemType == ListItemType.AlternatingItem))
                                    {
                                        int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                        TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                        TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                        ShippingOrderValue order       =
                                            context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                        order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                        order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                        context.SubmitChanges();
                                    }
                                }
                            }
                        }
                    }

                    if (pnlRushSkuItem.Visible)
                    {
                        optionRush = ShippingOptionType.SkuBased;
                        if (this.rptRushSkuItem.Items.Count > 0)
                        {
                            using (
                                CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())
                                )
                            {
                                foreach (RepeaterItem lst in rptRushSkuItem.Items)
                                {
                                    if ((lst.ItemType == ListItemType.Item) ||
                                        (lst.ItemType == ListItemType.AlternatingItem))
                                    {
                                        int         Id         = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text);
                                        TextBox     txtCostVal = (TextBox)lst.FindControl("txtPercentage");
                                        SkuShipping order      =
                                            context.SkuShippings.FirstOrDefault(
                                                p =>
                                                (p.SkuId == Id) && (p.IncludeRushShipping == true) && (p.PrefId == 1));
                                        if (order != null)
                                        {
                                            order.Cost = Convert.ToDecimal(txtCostVal.Text);
                                            context.SubmitChanges();
                                        }
                                        else
                                        {
                                            SkuShipping item = new SkuShipping();
                                            item.SkuId = Id;
                                            item.Cost  = Convert.ToDecimal(txtCostVal.Text);
                                            item.IncludeRushShipping = true;
                                            item.PrefId = 1;
                                            context.SkuShippings.InsertOnSubmit(item);
                                            context.SubmitChanges();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (pnlRushFlat.Visible)
                {
                    optionRush = ShippingOptionType.Flat;
                }


                using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                {
                    ShippingPref Val = context.ShippingPrefs.FirstOrDefault(x => x.PrefId == DefaultSitePrefereceId);
                    if (Val != null)
                    {
                        if (pnlFlat.Visible)
                        {
                            Val.flatShipping = Convert.ToDecimal(txtFlat.Text);
                        }
                        if (pnlRushFlat.Visible)
                        {
                            Val.RushShippingCost = Convert.ToDecimal(txtRushFlat.Text);
                        }
                        if (cbRushShippingOption.Checked)
                        {
                            Val.RushOptionId = (int)optionRush;
                        }
                        Val.OptionId = (int)option;

                        Val.InCludeRushShipping = cbRushShippingOption.Checked;
                        context.SubmitChanges();
                    }
                }

                // save additional charges
                if (this.rptShippingCharges.Items.Count > 0)
                {
                    List <int> deleteList = new List <int>();

                    using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                    {
                        foreach (RepeaterItem lst in rptShippingCharges.Items)
                        {
                            if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                            {
                                int      id        = Convert.ToInt32(((HiddenField)lst.FindControl("hidShippingChargeId")).Value);
                                CheckBox chkDelete = (CheckBox)lst.FindControl("chkDelete");

                                if (chkDelete.Checked)
                                {
                                    deleteList.Add(id);
                                }
                                else
                                {
                                    TextBox txtKey   = (TextBox)lst.FindControl("txtKey");
                                    TextBox txtCost  = (TextBox)lst.FindControl("txtCost");
                                    TextBox txtLabel = (TextBox)lst.FindControl("txtLabel");

                                    ShippingCharge shippingCharge =
                                        context.ShippingCharges.Single(p => p.ShippingChargeId == id);

                                    shippingCharge.Key           = txtKey.Text;
                                    shippingCharge.Cost          = Convert.ToDecimal(txtCost.Text);
                                    shippingCharge.FriendlyLabel = txtLabel.Text;
                                    context.SubmitChanges();
                                }
                            }
                        }
                    }

                    if (deleteList.Count > 0)
                    {
                        foreach (int id in deleteList)
                        {
                            CSBusiness.Shipping.ShippingManager.RemoveShippingCharge(id);
                        }
                    }
                }
                lblCancel.Visible  = false;
                lblSuccess.Visible = true;
            } //end of Save Command
            else
            {
                PopulateControls();
                lblCancel.Visible  = true;
                lblSuccess.Visible = false;
            }

            // Response.Redirect("Main.aspx");
        }
        /// <summary>
        /// Save Command Operation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                ShippingOptionType option     = ShippingOptionType.SiteLevelPref;
                ShippingOptionType optionRush = ShippingOptionType.SiteLevelPref;
                int?stateId = null;
                int countryId;
                if (DropDownListState.SelectedItem.Value.Length > 0)
                {
                    stateId = Convert.ToInt32(DropDownListState.SelectedItem.Value);
                }
                countryId = Convert.ToInt32(DropDownListCountry.SelectedItem.Value);

                if (PrefId == 0) //New Region Defined in the system
                {
                    //Check User Creating same Custom Shipping again or not
                    if (!ShippingDAL.IsValidShippingRegion(countryId, stateId))
                    {
                        using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                        {
                            ShippingPref item = new ShippingPref
                            {
                                flatShipping        = (pnlFlat.Visible) ? Convert.ToDecimal(txtFlat.Text) : 0,
                                RushShippingCost    = (pnlRushFlat.Visible) ? Convert.ToDecimal(txtRushFlat.Text) : 0,
                                RushOptionId        = (int)optionRush,
                                OptionId            = (int)option,
                                InCludeRushShipping = cbRushShippingOption.Checked,
                                IsCustomized        = true
                            };

                            context.ShippingPrefs.InsertOnSubmit(item);
                            context.SubmitChanges();

                            PrefId = item.PrefId;


                            //Associate PrefId to Region Table
                            ShippingRegion newRegion = new ShippingRegion
                            {
                                CountryId = countryId,
                                StateId   = stateId,
                                PrefId    = PrefId
                            };
                            context.ShippingRegions.InsertOnSubmit(newRegion);
                            context.SubmitChanges();
                        }
                    }
                    else
                    {
                        //fire Existing Item Message
                    }
                }

                if (PrefId > 0)
                {
                    if (pnlOrderVal.Visible)
                    {
                        option = ShippingOptionType.TotalAmount;
                        if (this.rptItems.Items.Count > 0)
                        {
                            using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                            {
                                foreach (RepeaterItem lst in rptItems.Items)
                                {
                                    if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                    {
                                        int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                        TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                        TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                        ShippingOrderValue order       = context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                        if (order != null)
                                        {
                                            order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                            order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                            order.PrefId     = PrefId;
                                            context.SubmitChanges();
                                        }
                                    }
                                }
                            }
                        }
                    } //end if for Shipping OrderValue

                    if (pnlWeight.Visible)
                    {
                        option = ShippingOptionType.Weight;
                        if (this.rptOrderWeight.Items.Count > 0)
                        {
                            using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                            {
                                foreach (RepeaterItem lst in rptOrderWeight.Items)
                                {
                                    if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                    {
                                        int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                        TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                        TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                        ShippingOrderValue order       = context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                        if (order != null)
                                        {
                                            order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                            order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                            order.PrefId     = PrefId;
                                            context.SubmitChanges();
                                        }
                                    }
                                }
                            }
                        }
                    }//end if for Shipping OrderWeight

                    if (pnlSkuItem.Visible)
                    {
                        option = ShippingOptionType.SkuBased;
                        if (this.rptSkuItem.Items.Count > 0)
                        {
                            using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                            {
                                foreach (RepeaterItem lst in rptSkuItem.Items)
                                {
                                    if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                    {
                                        int         Id         = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text);
                                        TextBox     txtCostVal = (TextBox)lst.FindControl("txtPercentage");
                                        SkuShipping order      = context.SkuShippings.FirstOrDefault(p => (p.SkuId == Id) && (p.IncludeRushShipping == false) && (p.PrefId == PrefId));
                                        if (order != null)
                                        {
                                            order.Cost = Convert.ToDecimal(txtCostVal.Text);
                                            context.SubmitChanges();
                                        }
                                        else
                                        {
                                            SkuShipping item = new SkuShipping();
                                            item.SkuId = Id;
                                            item.Cost  = Convert.ToDecimal(txtCostVal.Text);
                                            item.IncludeRushShipping = false;
                                            item.PrefId = PrefId;
                                            context.SkuShippings.InsertOnSubmit(item);
                                            context.SubmitChanges();
                                        }
                                    }
                                }
                            }
                        }
                    }//end if for Shipping SkuItem level

                    if (pnlFlat.Visible)
                    {
                        option = ShippingOptionType.Flat;
                    }

                    if (cbSitePref.Checked)
                    {
                        option = ShippingOptionType.SiteLevelPref;
                    }

                    if (cbRushShippingOption.Checked)
                    {
                        if (pnlRushOrderTotal.Visible)
                        {
                            optionRush = ShippingOptionType.TotalAmount;
                            if (this.rptRushOrderTotal.Items.Count > 0)
                            {
                                using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                                {
                                    foreach (RepeaterItem lst in rptRushOrderTotal.Items)
                                    {
                                        if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                        {
                                            int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                            TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                            TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                            ShippingOrderValue order       = context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                            if (order != null)
                                            {
                                                order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                                order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                                order.PrefId     = PrefId;
                                                context.SubmitChanges();
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (pnlRushOrderweight.Visible)
                        {
                            optionRush = ShippingOptionType.Weight;
                            if (this.rptRushOrderWeight.Items.Count > 0)
                            {
                                using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                                {
                                    foreach (RepeaterItem lst in rptRushOrderWeight.Items)
                                    {
                                        if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                        {
                                            int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                            TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                            TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                            ShippingOrderValue order       = context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                            if (order != null)
                                            {
                                                order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                                order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                                order.PrefId     = PrefId;
                                                context.SubmitChanges();
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (pnlRushSkuItem.Visible)
                        {
                            optionRush = ShippingOptionType.SkuBased;
                            if (this.rptRushSkuItem.Items.Count > 0)
                            {
                                using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                                {
                                    foreach (RepeaterItem lst in rptRushSkuItem.Items)
                                    {
                                        if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                        {
                                            int         Id         = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text);
                                            TextBox     txtCostVal = (TextBox)lst.FindControl("txtPercentage");
                                            SkuShipping order      = context.SkuShippings.FirstOrDefault(p => (p.SkuId == Id) && (p.IncludeRushShipping == true) && (p.PrefId == PrefId));
                                            if (order != null)
                                            {
                                                order.Cost = Convert.ToDecimal(txtCostVal.Text);
                                                context.SubmitChanges();
                                            }
                                            else
                                            {
                                                SkuShipping item = new SkuShipping();
                                                item.SkuId = Id;
                                                item.Cost  = Convert.ToDecimal(txtCostVal.Text);
                                                item.IncludeRushShipping = true;
                                                item.PrefId = PrefId;
                                                context.SkuShippings.InsertOnSubmit(item);
                                                context.SubmitChanges();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (pnlRushFlat.Visible)
                    {
                        optionRush = ShippingOptionType.Flat;
                    }

                    if (cbRushSitePref.Checked)
                    {
                        optionRush = ShippingOptionType.SiteLevelPref;
                    }

                    using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                    {
                        ShippingPref Val = context.ShippingPrefs.FirstOrDefault(x => x.PrefId == PrefId);
                        if (Val != null)
                        {
                            if (pnlFlat.Visible)
                            {
                                Val.flatShipping = Convert.ToDecimal(txtFlat.Text);
                            }
                            if (pnlRushFlat.Visible)
                            {
                                Val.RushShippingCost = Convert.ToDecimal(txtRushFlat.Text);
                            }
                            if (cbRushShippingOption.Checked)
                            {
                                Val.RushOptionId = (int)optionRush;
                            }
                            Val.OptionId = (int)option;

                            Val.InCludeRushShipping = cbRushShippingOption.Checked;
                            context.SubmitChanges();
                        }
                    }
                }// prefId check

                // save additional charges
                if (this.rptShippingCharges.Items.Count > 0)
                {
                    List <int> deleteList = new List <int>();

                    using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                    {
                        foreach (RepeaterItem lst in rptShippingCharges.Items)
                        {
                            if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                            {
                                int      id        = Convert.ToInt32(((HiddenField)lst.FindControl("hidShippingChargeId")).Value);
                                CheckBox chkDelete = (CheckBox)lst.FindControl("chkDelete");

                                if (chkDelete.Checked)
                                {
                                    deleteList.Add(id);
                                }
                                else
                                {
                                    TextBox txtKey   = (TextBox)lst.FindControl("txtKey");
                                    TextBox txtCost  = (TextBox)lst.FindControl("txtCost");
                                    TextBox txtLabel = (TextBox)lst.FindControl("txtLabel");

                                    ShippingCharge shippingCharge = context.ShippingCharges.Single(p => p.ShippingChargeId == id);

                                    shippingCharge.Key           = txtKey.Text;
                                    shippingCharge.Cost          = Convert.ToDecimal(txtCost.Text);
                                    shippingCharge.FriendlyLabel = txtLabel.Text;
                                    context.SubmitChanges();
                                }
                            }
                        }
                    }

                    if (deleteList.Count > 0)
                    {
                        foreach (int id in deleteList)
                        {
                            CSBusiness.Shipping.ShippingManager.RemoveShippingCharge(id);
                        }
                    }
                }
            }//end of save

            Response.Redirect("CustomShippingList.aspx");
        }