コード例 #1
0
        private void AddTodaysMagazineToCart()
        {
            int quantity;
            MyHLShoppingCart myShoppingCart = ShoppingCart;

            List <ShoppingCartItem_V01> products = new List <ShoppingCartItem_V01>();

            // if( this.ViewState["primaryCount"] == null )
            this.ViewState["primaryCount"] = int.Parse(this.tbQuantity.Text.Trim());

            //Add the donation amount to cart
            if (this.ViewState["primaryCount"] != null)
            {
                quantity = int.Parse(this.ViewState["primaryCount"].ToString());

                if (!HLConfigManager.Configurations.DOConfiguration.ModifyTodaysMagazineQuantity &&
                    (quantity <= 0 || quantity > (int)HLConfigManager.Configurations.DOConfiguration.TodayMagazineMax))
                {
                    lblError.Visible = true;
                    lblError.Text    = string.Format(MyHL_ErrorMessage.AddTodayMagazineMax + HLConfigManager.Configurations.DOConfiguration.TodayMagazineMax.ToString() + ".");
                }
                else if (HLConfigManager.Configurations.DOConfiguration.ModifyTodaysMagazineQuantity &&
                         (quantity <= 0 || quantity > myShoppingCart.TodaysMagaZineQuantity))
                {
                    lblError.Visible = true;
                    lblError.Text    = string.Format(MyHL_ErrorMessage.AddTodayMagazineMax + myShoppingCart.TodaysMagaZineQuantity.ToString() + ".");
                }
                else
                {
                    if (HLConfigManager.Configurations.DOConfiguration.TodayMagazineSku != null)
                    {
                        try
                        {
                            myShoppingCart.DeleteTodayMagazine(GetSelectedSKU());

                            ProductsBase.AddTodayMagazine(quantity, GetSelectedSKU());
                            IEnumerable <string> ruleResultMessages =
                                (from r in ShoppingCart.RuleResults
                                 where r.Result == RulesResult.Failure && r.RuleName == "SkuLimitation Rules"
                                 select r.Messages[0]);
                            if (null != ruleResultMessages && ruleResultMessages.Count() > 0)
                            {
                                lblError.Text    = ruleResultMessages.Distinct().ToList().First();
                                lblError.Visible = true;
                                todayMagazinePanel.Update();
                                return;
                            }

                            DisplayTodaysMagazine(MyHL_ErrorMessage.AddTodayMagazine);
                            todayMagazinePanel.Update();
                            // lblError.Visible = true;
                            // lblError.Text = string.Format(MyHL_ErrorMessage.AddTodayMagazine);
                        }
                        catch (Exception ex)
                        {
                            LoggerHelper.Error("TodaysMagazine Can not be added to cart!\n" + ex.ToString());
                        }
                    }
                }
            }

            //Add the donation amount to cart
            if (this.ViewState["secondaryCount"] != null)
            {
                quantity = int.Parse(this.ViewState["secondaryCount"].ToString());

                if (quantity <= 0 || (!HLConfigManager.Configurations.DOConfiguration.ModifyTodaysMagazineQuantity && quantity > (int)HLConfigManager.Configurations.DOConfiguration.TodayMagazineMax) ||
                    (HLConfigManager.Configurations.DOConfiguration.ModifyTodaysMagazineQuantity && quantity > myShoppingCart.TodaysMagaZineQuantity))
                {
                    lblError.Visible = true;
                    lblError.Text    = string.Format(MyHL_ErrorMessage.AddTodayMagazineMax + HLConfigManager.Configurations.DOConfiguration.TodayMagazineMax.ToString() + ".");
                }
                else
                {
                    if (HLConfigManager.Configurations.DOConfiguration.TodayMagazineSecondarySku != null)
                    {
                        try
                        {
                            myShoppingCart.DeleteTodayMagazine(GetSelectedSKU());
                            ProductsBase.AddTodayMagazine(quantity, GetSelectedSKU());
                            DisplayTodaysMagazine(MyHL_ErrorMessage.AddTodayMagazine);
                            todayMagazinePanel.Update();
                        }
                        catch (Exception ex)
                        {
                            LoggerHelper.Error("TodaysMagazine Can not be added to cart!\n" + ex.ToString());
                        }
                    }
                }
            }
        }