private void AddCartALCMenuItem(ListViewDataItem dataItem, hccCartItem cartItem, int mealTypeID)
        {
            var divSidesDishes = (HtmlGenericControl)dataItem.FindControl("divSidesDishes");

            if (divSidesDishes == null || !divSidesDishes.Visible)
            {
                return;
            }

            var alcMenuItem = hccCartALCMenuItem.GetByCartItemID(cartItem.CartItemID, cartItem.CartItemID);

            if (alcMenuItem == null)
            {
                alcMenuItem = new hccCartALCMenuItem
                {
                    CartItemID       = cartItem.CartItemID,
                    ParentCartItemID = cartItem.CartItemID,
                    Ordinal          = 0
                };
                alcMenuItem.Save();
            }
            //Manoj_14.04.2017
            AddCartALCMenuItem(dataItem, cartItem, "ddlSide1", 1);
            AddCartALCMenuItem(dataItem, cartItem, "ddlSide2", 2);

            CheckBindAvailableSides(dataItem, mealTypeID);
        }
        private void AddUpdateMealSideToCart(hccCartItem parentCartItem, hccMenuItem menuItem, int ordinal)
        {
            if (menuItem == null || parentCartItem == null)
            {
                throw new ArgumentException();
            }

            var alcMenuItem = hccCartALCMenuItem.GetByOrdinal(parentCartItem.CartItemID, ordinal);

            if (alcMenuItem == null)
            {
                var newItem = new hccCartItem
                {
                    CartID            = parentCartItem.CartID,
                    CreatedBy         = parentCartItem.CreatedBy,
                    CreatedDate       = DateTime.Now,
                    IsTaxable         = menuItem.IsTaxEligible,
                    ItemName          = hccCartItem.BuildCartItemName(menuItem.MealType, (Enums.CartItemSize)parentCartItem.Meal_MealSizeID, menuItem.Name, string.Empty, string.Empty, parentCartItem.DeliveryDate),//, parentCartItem.Quantity
                    ItemDesc          = menuItem.Description,
                    ItemPrice         = hccMenuItem.GetItemPriceBySize(menuItem, parentCartItem.Meal_MealSizeID),
                    ItemTypeID        = (int)Enums.CartItemType.AlaCarte,
                    DeliveryDate      = parentCartItem.DeliveryDate,
                    Meal_MenuItemID   = menuItem.MenuItemID,
                    Meal_MealSizeID   = parentCartItem.Meal_MealSizeID,
                    Meal_ShippingCost = hccDeliverySetting.GetBy(menuItem.MealType).ShipCost,
                    UserProfileID     = parentCartItem.UserProfileID,
                    Quantity          = parentCartItem.Quantity,
                    OrderNumber       = parentCartItem.OrderNumber,
                    IsCompleted       = false
                };
                newItem.Save();

                alcMenuItem = new hccCartALCMenuItem
                {
                    CartItemID       = newItem.CartItemID,
                    ParentCartItemID = parentCartItem.CartItemID,
                    Ordinal          = ordinal
                };
                alcMenuItem.Save();
            }
            else
            {
                var cartItem = hccCartItem.GetById(alcMenuItem.CartItemID);

                cartItem.Quantity        = parentCartItem.Quantity;
                cartItem.Meal_MealSizeID = parentCartItem.Meal_MealSizeID;

                if (cartItem.Meal_MenuItemID != menuItem.MenuItemID)
                {
                    cartItem.IsTaxable         = menuItem.IsTaxEligible;
                    cartItem.ItemName          = hccCartItem.BuildCartItemName(menuItem.MealType, (Enums.CartItemSize)parentCartItem.Meal_MealSizeID, menuItem.Name, string.Empty, string.Empty, parentCartItem.DeliveryDate);//, parentCartItem.Quantity
                    cartItem.ItemDesc          = menuItem.Description;
                    cartItem.ItemPrice         = hccMenuItem.GetItemPriceBySize(menuItem, parentCartItem.Meal_MealSizeID);
                    cartItem.Meal_MenuItemID   = menuItem.MenuItemID;
                    cartItem.Meal_ShippingCost = hccDeliverySetting.GetBy(menuItem.MealType).ShipCost;
                    cartItem.UserProfileID     = parentCartItem.UserProfileID;
                }
                cartItem.Save();
            }
        }
Ejemplo n.º 3
0
        private void AddUpdateCartALCMenuItem(hccCartItem parentCartItem, DropDownList ddlSideControl, int ordinal)
        {
            if (ddlSideControl == null || string.IsNullOrEmpty(ddlSideControl.SelectedValue))
            {
                return;
            }

            var menuItemId = int.Parse(ddlSideControl.SelectedValue.ToString());

            if (menuItemId == -1)
            {
                var alcMenuItem = hccCartALCMenuItem.GetByOrdinal(parentCartItem.CartItemID, ordinal);
                if (alcMenuItem != null)
                {
                    var cartItem = hccCartItem.GetById(alcMenuItem.CartItemID);
                    alcMenuItem.Delete();
                    if (cartItem != null)
                    {
                        cartItem.Delete(null);
                    }
                }
                return;
            }

            var menuItem = hccMenuItem.GetById(menuItemId);

            AddUpdateMealSideToCart(parentCartItem, menuItem, ordinal);
        }
        void cstXactGCRedeem_ServerValidate(object source, ServerValidateEventArgs args)
        {
            hccCartItem gcCartItem = hccCartItem.GetGiftBy(txtXactGCRedeem.Text);

            if (gcCartItem == null || (gcCartItem != null && gcCartItem.IsCompleted))
            {
                args.IsValid = false;
            }
        }
        void gvwCartItems_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                hccCartItem item = (hccCartItem)e.Row.DataItem;

                if (CurrentPurchaseNumberIsCancelled)
                {
                    e.Row.Cells[5].Controls.OfType <LinkButton>().First().Visible = false;
                }
                else if (item.IsCancelled)
                {
                    e.Row.Cells[5].Controls.OfType <LinkButton>().First().Text = "Un-Cancel Item";
                }
            }
        }
        public void SetCartCount()
        {
            try
            {
                MembershipUser user = Helpers.LoggedUser;
                aCart.Attributes.Remove("class");
                if (user == null || (user != null && Roles.IsUserInRole(user.UserName, "Customer")))
                {
                    aCart.Visible = true;
                    hccCart cart = null;

                    if (user == null)
                    {
                        cart = hccCart.GetCurrentCart();
                    }
                    else
                    {
                        cart = hccCart.GetCurrentCart(user);
                    }

                    if (cart != null)
                    {
                        List <hccCartItem> cartItems = hccCartItem.GetWithoutSideItemsBy(cart.CartID);
                        hccCartItem        obj       = new hccCartItem();

                        if (CartID != 0 && MealCount != 0)
                        {
                            Session["id"]    = CartID;
                            Session["meals"] = MealCount;
                        }
                        if (cartItems.Count > 0)
                        {
                            aCart.Attributes.Add("class", "cart-has-items");
                        }
                        lblCartCount.Text = cartItems.Count.ToString();
                    }
                    else
                    {
                        lblCartCount.Text = "0";
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void AddUpdateCartALCMenuItem(hccCartItem parentCartItem, DropDownList ddlSideControl, int ordinal)
        {
            if (ddlSideControl == null || string.IsNullOrEmpty(ddlSideControl.SelectedValue))
            {
                return;
            }

            var menuItemId = int.Parse(ddlSideControl.SelectedValue.ToString());

            if (menuItemId == -1)
            {
                return; // "None" selected
            }
            var menuItem = hccMenuItem.GetById(menuItemId);

            AddUpdateMealSideToCart(parentCartItem, menuItem, ordinal);
        }
        protected void SaveForm()
        {
            try
            {
                hccCart userCart = hccCart.GetCurrentCart();
                CurrentGiftCert = hccCartItem.Gift_GenerateNew(userCart.CartID);

                if (CurrentGiftCert != null)
                {
                    CurrentGiftCert.ItemPrice = decimal.Parse(txtAmount.Text.Trim());

                    //recipient info
                    CurrentGiftCert.Gift_RecipientEmail   = txtRecipEmail.Text.Trim();
                    CurrentGiftCert.Gift_RecipientMessage = txtRecipMessage.Text.Trim();
                    CurrentGiftCert.DeliveryDate          = hccProductionCalendar.GetNext4Calendars().First().DeliveryDate;
                    CurrentGiftCert.GetOrderNumber(userCart);

                    AddressRecipient.AddressType = Enums.AddressType.GiftRecipient;
                    AddressRecipient.Save();
                    CurrentGiftCert.Gift_RecipientAddressId = AddressRecipient.PrimaryKeyIndex;

                    string itemFullName = string.Format("{0} - {1} - {2} - For: {3} {4}",
                                                        "Gift Certificate", CurrentGiftCert.Gift_RedeemCode, CurrentGiftCert.ItemPrice.ToString("c"),
                                                        AddressRecipient.CurrentAddress.FirstName, AddressRecipient.CurrentAddress.LastName);

                    CurrentGiftCert.ItemName = itemFullName;

                    CurrentGiftCert.Save();

                    HealthyChef.Templates.HealthyChef.Controls.TopHeader header =
                        (HealthyChef.Templates.HealthyChef.Controls.TopHeader) this.Page.Master.FindControl("TopHeader1");

                    if (header != null)
                    {
                        header.SetCartCount();
                    }

                    ClearForm();
                    lblFeedback.Text = "Gift certificate has been added to your cart.";
                }
            }
            catch
            {
                throw;
            }
        }
        private void AddUpdateCartALCMenuItem(hccCartItem cartItem)
        {
            var alcMenuItem = hccCartALCMenuItem.GetByCartItemID(cartItem.CartItemID, cartItem.CartItemID);

            if (alcMenuItem == null)
            {
                alcMenuItem = new hccCartALCMenuItem
                {
                    CartItemID       = cartItem.CartItemID,
                    ParentCartItemID = cartItem.CartItemID,
                    Ordinal          = 0
                };
                alcMenuItem.Save();
            }

            AddUpdateCartALCMenuItem(cartItem, ddlMealSide1MenuItems, 1);
            AddUpdateCartALCMenuItem(cartItem, ddlMealSide2MenuItems, 2);
        }
        private void AddCartALCMenuItem(ListViewDataItem dataItem, hccCartItem parentCartItem, string controlId, int ordinal)
        {
            var ddlSideControl = (DropDownList)dataItem.FindControl(controlId);

            if (ddlSideControl == null || string.IsNullOrEmpty(ddlSideControl.SelectedValue))
            {
                return;
            }

            var menuItemId = int.Parse(ddlSideControl.SelectedValue.ToString());

            if (menuItemId == -1)
            {
                return; // "None" selected
            }
            var menuItem = hccMenuItem.GetById(menuItemId);

            AddMealSideToCart(parentCartItem, menuItem, ordinal);
        }
        protected void lkbRemove_Click(object sender, EventArgs e)
        {
            LinkButton  lkbRemove  = (LinkButton)sender;
            int         cartItemId = int.Parse(lkbRemove.CommandArgument);
            hccCartItem cartItem   = hccCartItem.GetById(cartItemId);

            if (cartItem != null)
            {
                hccCartItem vsItem = CurrentProfileCart.CartItems.Single(a => a.CartItemID == cartItemId);
                if (vsItem != null)
                {
                    CurrentProfileCart.CartItems.Remove(vsItem);
                }

                try
                {  // remove any potential recurring status to prevent orphaning records without a valid cartId and cartitemId
                    using (var hcE = new healthychefEntities())
                    {
                        var rOrder = hcE.hccRecurringOrders.FirstOrDefault(i => i.CartID == cartItem.CartID && i.CartItemID == cartItemId);

                        if (rOrder != null)
                        {
                            hcE.hccRecurringOrders.DeleteObject(rOrder);
                            hcE.SaveChanges();
                        }
                    }
                }
                catch (Exception) { }


                cartItem.Delete(((List <hccRecurringOrder>)Session["autorenew"]));
                OnCartItemListItemUpdated();
            }
            else
            {
                // couldnt find cart item
            }
        }
        protected void txtQuantity_TextChanged(object sender, EventArgs e)
        {
            Page.Validate("QuantityGroup");

            if (Page.IsValid)
            {
                TextBox txtQuantity = (TextBox)sender;
                //CheckBox chk = (CheckBox)sender;
                if (txtQuantity != null)
                {
                    int newQty            = int.Parse(txtQuantity.Text);
                    ListViewDataItem item = (ListViewDataItem)txtQuantity.Parent;

                    int         cartItemId = int.Parse(lvwCartItems.DataKeys[item.DataItemIndex].Value.ToString());
                    hccCartItem cartItem   = hccCartItem.GetById(cartItemId);

                    if (cartItem != null)
                    {
                        if (cartItem.ItemTypeID == 2)
                        {
                            if (newQty > 0)
                            {
                                List <hccCartItem> cartItems = hccCartItem.GetWithoutSideItemsBy(cartItem.CartID);

                                if (cartItem.AdjustQuantity(newQty))
                                {
                                    #region recurringitems adjust
                                    // If the adjusted cart item is a recurring item(s),
                                    // check the quantity of the cartitemId in the Session
                                    // Recurring order object, if greater than new quantity,
                                    // adjust the recurring values accordingly.
                                    //if (Session["autorenew"] != null)
                                    //{
                                    //    var lstRo = ((List<hccRecurringOrder>)Session["autorenew"]);
                                    //    while (lstRo.Count(x => x.CartItemID == cartItemId) > newQty)
                                    //    {
                                    //        lstRo.Remove(lstRo.Find(x => x.CartItemID == cartItemId));
                                    //    }
                                    //}
                                    #endregion

                                    OnCartItemListItemUpdated();
                                }
                            }
                            else
                            {
                                cartItem.Delete(((List <hccRecurringOrder>)Session["autorenew"]));
                                OnCartItemListItemUpdated();
                            }
                        }
                        else
                        {
                            if (newQty == 1)
                            {
                                cartItem.AdjustQuantity(newQty);
                                hccCartItem hcccartItem = new hccCartItem();
                                hcccartItem.RemoveFamilyStyle(cartItemId);
                                OnCartItemListItemUpdated();
                            }
                            else
                            {
                                cartItem.AdjustQuantity(newQty);
                                OnCartItemListItemUpdated();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public string ReplaceProgramMeals(List <DefaultMenu> defaultMenus)
        {
            try
            {
                bool tryBool;
                bool isCancel   = false;
                bool isComplete = false;
                int  cartItemId = int.Parse(this.Context.Request.QueryString["cid"]);

                hccCartItem cartItem = hccCartItem.GetById(cartItemId);
                if (cartItem != null)
                {
                    if (this.Context.Request.QueryString["can"] != null)
                    {
                        tryBool = bool.TryParse(this.Context.Request.QueryString["can"], out isCancel);
                        cartItem.IsCancelled = isCancel;
                    }

                    if (this.Context.Request.QueryString["cmplt"] != null)
                    {
                        tryBool = bool.TryParse(this.Context.Request.QueryString["cmplt"], out isComplete);
                    }
                    hccCartMenuExPref cartMenuExPref = hccCartMenuExPref.GetById(cartItem.CartItemID, defaultMenus[0].DayNumber);
                    if (cartMenuExPref == null)
                    {
                        hccCartMenuExPref hccCartMenuExPref = new hccCartMenuExPref();
                        hccCartMenuExPref.CartItemID = cartItem.CartItemID;
                        hccCartMenuExPref.DayNumber  = defaultMenus[0].DayNumber;
                        hccCartMenuExPref.IsModified = true;
                        hccCartMenuExPref.Save();
                    }
                    cartItem.Save();
                }

                decimal cals1 = 0.0m, fat1 = 0.0m, prtn1 = 0.0m, carb1 = 0.0m, fbr1 = 0.0m, sod1 = 0.0m;

                foreach (DefaultMenu defaultMenuItem in defaultMenus)
                {
                    hccCartItemCalendar cartCal = hccCartItemCalendar.GetBy(cartItem.CartItemID, defaultMenuItem.CalendarID);

                    if (cartCal != null)
                    {
                        if (isComplete != cartCal.IsFulfilled)
                        {
                            cartCal.IsFulfilled = isComplete;
                            cartCal.Save();
                        }

                        // get original defaultMenuItem for comparison of menuItem
                        hccProgramDefaultMenu origDefaultMenu =
                            hccProgramDefaultMenu.GetBy(cartCal.CalendarID, defaultMenuItem.ProgramID,
                                                        defaultMenuItem.DayNumber, defaultMenuItem.MealTypeID, defaultMenuItem.Ordinal);

                        hccCartDefaultMenuException existMenuEx = hccCartDefaultMenuException.GetBy(defaultMenuItem.DefaultMenuID, cartCal.CartCalendarID);

                        if (origDefaultMenu != null &&
                            origDefaultMenu.MenuItemID == defaultMenuItem.MenuItemID &&
                            origDefaultMenu.MenuItemSizeID == defaultMenuItem.MenuItemSizeID)
                        {
                            if (string.IsNullOrWhiteSpace(defaultMenuItem.Prefs))
                            {
                                if (existMenuEx != null)
                                {
                                    List <hccCartDefaultMenuExPref> prefs = hccCartDefaultMenuExPref.GetBy(existMenuEx.DefaultMenuExceptID);
                                    prefs.ForEach(a => a.Delete());
                                    existMenuEx.Delete();
                                }
                            }
                            else
                            {
                                if (existMenuEx == null)
                                {   // create exception menuItem
                                    existMenuEx = new hccCartDefaultMenuException
                                    {
                                        CartCalendarID = cartCal.CartCalendarID,
                                        DefaultMenuID  = defaultMenuItem.DefaultMenuID
                                    };
                                }

                                existMenuEx.MenuItemID     = defaultMenuItem.MenuItemID;
                                existMenuEx.MenuItemSizeID = defaultMenuItem.MenuItemSizeID;
                                existMenuEx.Save();

                                List <hccCartDefaultMenuExPref> prefs = hccCartDefaultMenuExPref.GetBy(existMenuEx.DefaultMenuExceptID);
                                prefs.ForEach(a => a.Delete());

                                if (!string.IsNullOrWhiteSpace(defaultMenuItem.Prefs))
                                {
                                    List <string> prefIds = defaultMenuItem.Prefs.Split(',').ToList();
                                    prefIds.ForEach(delegate(string prefId)
                                    {
                                        hccCartDefaultMenuExPref exPref = new hccCartDefaultMenuExPref
                                        {
                                            DefaultMenuExceptID = existMenuEx.DefaultMenuExceptID,
                                            PreferenceID        = int.Parse(prefId)
                                        };

                                        exPref.Save();
                                    });
                                }
                            }
                        }
                        else
                        {
                            if (existMenuEx == null)
                            {   // create exception menuItem
                                existMenuEx = new hccCartDefaultMenuException
                                {
                                    CartCalendarID = cartCal.CartCalendarID,
                                    DefaultMenuID  = defaultMenuItem.DefaultMenuID
                                };
                            }

                            existMenuEx.MenuItemID     = defaultMenuItem.MenuItemID;
                            existMenuEx.MenuItemSizeID = defaultMenuItem.MenuItemSizeID;
                            existMenuEx.Save();

                            List <hccCartDefaultMenuExPref> exPrefs = hccCartDefaultMenuExPref.GetBy(existMenuEx.DefaultMenuExceptID);
                            exPrefs.ForEach(a => a.Delete());

                            if (!string.IsNullOrWhiteSpace(defaultMenuItem.Prefs))
                            {
                                List <string> prefIds = defaultMenuItem.Prefs.Split(',').ToList();
                                prefIds.ForEach(delegate(string prefId)
                                {
                                    hccCartDefaultMenuExPref exPref = new hccCartDefaultMenuExPref
                                    {
                                        DefaultMenuExceptID = existMenuEx.DefaultMenuExceptID,
                                        PreferenceID        = int.Parse(prefId)
                                    };

                                    exPref.Save();
                                });
                            }
                        }

                        hccMenuItemNutritionData nutrition;

                        if (existMenuEx == null)
                        {
                            nutrition = hccMenuItemNutritionData.GetBy(defaultMenuItem.MenuItemID);
                        }
                        else
                        {
                            nutrition = hccMenuItemNutritionData.GetBy(existMenuEx.MenuItemID);
                        }

                        if (nutrition != null)
                        {
                            cals1 = cals1 + nutrition.Calories;
                            fat1  = fat1 + nutrition.TotalFat;
                            prtn1 = prtn1 + nutrition.Protein;
                            carb1 = carb1 + nutrition.TotalCarbohydrates;
                            fbr1  = fbr1 + nutrition.DietaryFiber;
                            sod1  = sod1 + nutrition.Sodium;
                        }
                    }
                }

                string nutri = cals1.ToString("f2") + "|" + fat1.ToString("f2") + "|" + prtn1.ToString("f2") + "|" + carb1.ToString("f2") + "|" + fbr1.ToString("f2") + "|" + sod1.ToString("f2");

                return(nutri);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        protected override void SaveForm()
        {
            try
            {
                hccCart        userCart      = hccCart.GetById(this.PrimaryKeyIndex);
                MembershipUser user          = Membership.GetUser(userCart.AspNetUserID);
                bool           isFamilyStyle = false;

                if (user != null)
                {
                    hccMenuItem menuItem = hccMenuItem.GetById(int.Parse(ddlMenuItems.SelectedValue));
                    var         itemSize = (Enums.CartItemSize)(int.Parse(ddlOptions.SelectedValue));
                    if (chkFamilyStyle.Checked)
                    {
                        isFamilyStyle = true;
                    }
                    int profileId = 0;
                    if (divProfiles.Visible)
                    {
                        profileId = int.Parse(ddlProfiles.SelectedValue);
                    }
                    else
                    {
                        profileId = hccUserProfile.GetParentProfileBy(userCart.AspNetUserID.Value).UserProfileID;
                    }

                    if (userCart != null)
                    {
                        hccCartItem cartItem = new hccCartItem
                        {
                            CreatedBy         = (Guid)Helpers.LoggedUser.ProviderUserKey,
                            CreatedDate       = DateTime.Now,
                            IsTaxable         = menuItem.IsTaxEligible,
                            ItemDesc          = menuItem.Description,
                            ItemPrice         = hccMenuItem.GetItemPriceBySize(menuItem, (int)itemSize),
                            ItemTypeID        = (int)Enums.CartItemType.AlaCarte,
                            DeliveryDate      = DateTime.Parse(ddlDeliveryDates.SelectedItem.Text),
                            Meal_MealSizeID   = (int)itemSize,
                            Meal_MenuItemID   = menuItem.MenuItemID,
                            Meal_ShippingCost = hccDeliverySetting.GetBy(menuItem.MealType).ShipCost,
                            UserProfileID     = profileId,
                            Quantity          = int.Parse(txtQuantity.Text.Trim()),
                            Plan_IsAutoRenew  = isFamilyStyle,
                            IsCompleted       = false
                        };

                        cartItem.GetOrderNumber(userCart);

                        List <hccCartItemMealPreference> prefsList = new List <hccCartItemMealPreference>();

                        foreach (ListItem item in cblPreferences.Items)
                        {
                            if (item.Selected)
                            {
                                hccCartItemMealPreference pref =
                                    new hccCartItemMealPreference {
                                    CartItemID = cartItem.CartItemID, PreferenceID = int.Parse(item.Value)
                                };
                                prefsList.Add(pref);
                            }
                        }

                        var prefsString = string.Empty;

                        if (prefsList.Count > 0)
                        {
                            prefsString = prefsList
                                          .Select(a => hccPreference.GetById(a.PreferenceID))
                                          .Select(a => a.Name).DefaultIfEmpty(string.Empty).Aggregate((a, b) => a + ", " + b);
                        }

                        cartItem.ItemName = hccCartItem.BuildCartItemName(menuItem.MealType, itemSize, menuItem.Name, GetMealSides(menuItem.MealType), prefsString, cartItem.DeliveryDate);//,cartItem.Quantity

                        hccCartItem existItem = hccCartItem.GetBy(userCart.CartID, cartItem.ItemName, profileId);

                        if (existItem == null)
                        {
                            cartItem.CartID = userCart.CartID;
                            cartItem.Save();

                            if (cartItem.CartItemID > 0)
                            {
                                prefsList.ForEach(delegate(hccCartItemMealPreference cartPref)
                                {
                                    cartPref.CartItemID = cartItem.CartItemID;
                                    cartPref.Save();
                                });
                            }

                            AddUpdateCartALCMenuItem(cartItem);
                            OnSaved(new ControlSavedEventArgs(cartItem.CartItemID));
                            chkFamilyStyle.Checked = false;
                        }
                        else
                        {
                            existItem.Quantity += cartItem.Quantity;
                            if (existItem.AdjustQuantity(existItem.Quantity))
                            {
                                AddUpdateCartALCMenuItem(existItem);
                                OnSaved(new ControlSavedEventArgs(existItem.CartItemID));
                                chkFamilyStyle.Checked = false;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void btnAddToCartClick(object sender, EventArgs e)
        {
            bool itemAdded = false;

            try
            {
                Button           btnAddToCart = (Button)sender;
                ListViewDataItem dataItem     = (ListViewDataItem)btnAddToCart.Parent;
                int            menuItemId     = int.Parse(lvwMealItems.DataKeys[dataItem.DataItemIndex].Value.ToString());
                hccMenuItem    menuItem       = hccMenuItem.GetById(menuItemId);
                hccCart        userCart       = hccCart.GetCurrentCart();
                MembershipUser user           = Helpers.LoggedUser;
                int            profileId      = GetProfileId(dataItem);
                int            sizeId         = GetSizeId(btnAddToCart);

                hccCartItem newItem = new hccCartItem
                {
                    CartID            = userCart.CartID,
                    CreatedBy         = (user == null ? Guid.Empty : (Guid)user.ProviderUserKey),
                    CreatedDate       = DateTime.Now,
                    IsTaxable         = menuItem.IsTaxEligible,
                    ItemDesc          = menuItem.Description,
                    ItemPrice         = hccMenuItem.GetItemPriceBySize(menuItem, sizeId),
                    ItemTypeID        = (int)Enums.CartItemType.AlaCarte,
                    DeliveryDate      = CurrentDeliveryDate,
                    Meal_MenuItemID   = menuItem.MenuItemID,
                    Meal_MealSizeID   = sizeId,
                    Meal_ShippingCost = hccDeliverySetting.GetBy(menuItem.MealType).ShipCost,
                    UserProfileID     = profileId,
                    Quantity          = GetQuantity(dataItem),
                    IsCompleted       = false
                };

                newItem.GetOrderNumber(userCart);

                List <CheckBox>     prefChks = new List <CheckBox>();
                List <RepeaterItem> rptPrefs = dataItem.FindControl("rptMealPrefs").Controls.OfType <RepeaterItem>().ToList();
                rptPrefs.ForEach(delegate(RepeaterItem ri) { prefChks.AddRange(ri.Controls.OfType <CheckBox>().Where(a => a.Checked)); });
                string prefsString = string.Empty;
                List <hccCartItemMealPreference> cartPrefs = new List <hccCartItemMealPreference>();

                foreach (CheckBox chkPref in prefChks)
                {
                    int           prefId = int.Parse(chkPref.Attributes["value"]);
                    hccPreference pref   = hccPreference.GetById(prefId);

                    if (pref != null)
                    {
                        if (string.IsNullOrWhiteSpace(prefsString))
                        {
                            prefsString += pref.Name;
                        }
                        else
                        {
                            prefsString += ", " + pref.Name;
                        }

                        cartPrefs.Add(new hccCartItemMealPreference {
                            CartItemID = newItem.CartItemID, PreferenceID = prefId
                        });
                    }
                }

                //newItem.ItemName = hccCartItem.BuildCartItemName(menuItem.MealType, (Enums.CartItemSize)sizeId, menuItem.Name, GetMealSides(dataItem), prefsString, newItem.DeliveryDate, newItem.Quantity);
                newItem.ItemName = hccCartItem.BuildCartItemName(menuItem.MealType, (Enums.CartItemSize)sizeId, menuItem.Name, GetMealSides(dataItem), prefsString, newItem.DeliveryDate);//, newItem.Quantity

                hccCartItem existItem = hccCartItem.GetBy(userCart.CartID, newItem.ItemName, profileId);

                if (existItem == null)
                {
                    newItem.Save();
                    cartPrefs.ForEach(delegate(hccCartItemMealPreference cartPref) { cartPref.CartItemID = newItem.CartItemID; cartPref.Save(); });
                }
                else
                {
                    existItem.Quantity += newItem.Quantity;
                    existItem.AdjustQuantity(existItem.Quantity);
                }

                AddCartALCMenuItem(dataItem, existItem ?? newItem, menuItem.MealTypeID);

                itemAdded = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (itemAdded)
            {
                HealthyChef.Templates.HealthyChef.Controls.TopHeader header =
                    (HealthyChef.Templates.HealthyChef.Controls.TopHeader) this.Page.Master.FindControl("TopHeader1");

                if (header != null)
                {
                    header.SetCartCount();
                }
            }
        }
        protected override void SaveForm()
        {
            try
            {
                hccLedger ledger = new hccLedger
                {
                    AspNetUserID      = CurrentAspNetUserId,
                    CreatedBy         = (Guid)Helpers.LoggedUser.ProviderUserKey,
                    CreatedDate       = DateTime.Now,
                    Description       = txtXactDesc.Text.Trim(),
                    TransactionTypeID = int.Parse(ddlXactTypes.SelectedValue)
                };

                if (ledger.TransactionType == Enums.LedgerTransactionType.RedeemGiftCertificate)
                {
                    hccCartItem gcCartItem   = hccCartItem.GetGiftBy(txtXactGCRedeem.Text);
                    bool        updateLedger = false;

                    if (gcCartItem != null)
                    {
                        gcCartItem.Gift_RedeemedBy   = CurrentAspNetUserId;
                        gcCartItem.Gift_RedeemedDate = DateTime.Now;
                        gcCartItem.Save();
                        updateLedger = true;
                    }
                    else
                    {
                        ImportedGiftCert cert = ImportedGiftCert.GetBy(txtXactGCRedeem.Text);
                        if (cert != null)
                        {
                            cert.used_by   = gcCartItem.UserProfileID;
                            cert.date_used = DateTime.Now.ToString();
                            cert.is_used   = "Y";
                            cert.Save();
                            updateLedger = true;
                        }
                    }

                    if (updateLedger)
                    {
                        ledger.TotalAmount    = gcCartItem.ItemPrice;
                        ledger.GiftRedeemCode = gcCartItem.Gift_RedeemCode;
                        ledger.Description    = "Gift Certificate Redemption: " + ledger.GiftRedeemCode;
                    }
                    else
                    {
                        ledger = null;
                    }
                }
                else
                {
                    ledger.TotalAmount = decimal.Parse(txtXactAmount.Text.Trim());
                }

                hccUserProfile profile = hccUserProfile.GetParentProfileBy(CurrentAspNetUserId);

                if (profile != null)
                {
                    // check against last entry for duplicate
                    hccLedger lastEntry        = hccLedger.GetByMembershipID(profile.MembershipID, null).OrderByDescending(a => a.CreatedDate).FirstOrDefault();
                    bool      isDuplicateEntry = false;

                    if (ledger != null)
                    {
                        if (lastEntry != null &&
                            ledger.CreatedBy == lastEntry.CreatedBy &&
                            ledger.CreditFromBalance == lastEntry.CreditFromBalance &&
                            ledger.Description == lastEntry.Description &&
                            ledger.PaymentDue == lastEntry.PaymentDue &&
                            ledger.TransactionTypeID == lastEntry.TransactionTypeID &&
                            ledger.TotalAmount == lastEntry.TotalAmount)
                        {
                            isDuplicateEntry = true;
                        }

                        if (!isDuplicateEntry)
                        {
                            switch (ledger.TransactionType)
                            {
                            case Enums.LedgerTransactionType.HCCAccountCredit:
                            case Enums.LedgerTransactionType.RedeemGiftCertificate:
                                profile.AccountBalance = profile.AccountBalance + ledger.TotalAmount;
                                break;

                            case Enums.LedgerTransactionType.HCCAccountDebit:
                                profile.AccountBalance = profile.AccountBalance - ledger.TotalAmount;
                                break;

                            case Enums.LedgerTransactionType.Purchase:
                            case Enums.LedgerTransactionType.Return:
                                ledger.PaymentDue = ledger.TotalAmount;
                                break;

                            default: break;
                            }

                            ledger.PostBalance = profile.AccountBalance;
                            ledger.Save();
                            profile.Save();

                            this.Bind();
                            OnSaved(new ControlSavedEventArgs(CurrentAspNetUserId));

                            txtXactAmount.Text   = string.Empty;
                            txtXactDesc.Text     = string.Empty;
                            txtXactGCRedeem.Text = string.Empty;
                            ddlXactTypes.ClearSelection();
                        }
                        else
                        {
                            lblXactFeedback.Text = "This appears to be a duplicate transaction. If it is not a duplicate, please provide a comment to differentiate this transaction from the last.";
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        //public string GetProgramImage(string programName)
        //{
        //    var fileName = "/userfiles/images/programs/" + programName.Replace(" ", "-") + ".jpg";

        //    if (!File.Exists(Server.MapPath(fileName)))
        //        return "";

        //    return "<img width='150' height='126' alt='' src='/userfiles/images/programs/" + programName.Replace(" ", "-") + ".jpg' class='left' />";
        //}

        protected void btn_add_to_cart_Click(object sender, EventArgs e)
        {
            try
            {
                Page.Validate("AddToCartGroup");

                if (Page.IsValid)
                {
                    hccCart userCart = hccCart.GetCurrentCart();

                    //Define form variables
                    int itemId   = Convert.ToInt32(Request.Form["plan_type"]);
                    int optionId = ((Request.Form["plan_option"] == null) ? 0 : Convert.ToInt32(Request.Form["plan_option"]));

                    //Select chosen Program Plan
                    hccProgramPlan plan = hccProgramPlan.GetById(itemId);
                    if (plan == null)
                    {
                        throw new Exception("ProgramPlan not found: " + itemId.ToString());
                    }

                    hccProgram       prog   = hccProgram.GetById(plan.ProgramID);
                    hccProgramOption option = hccProgramOption.GetBy(plan.ProgramID).Where(a => a.ProgramOptionID == optionId).SingleOrDefault();

                    int      numDays      = plan.NumDaysPerWeek * plan.NumWeeks;
                    int      numMeals     = numDays * plan.MealsPerDay;
                    decimal  dailyPrice   = plan.PricePerDay + option.OptionValue;
                    decimal  itemPrice    = numDays * dailyPrice;
                    DateTime deliveryDate = DateTime.Parse(ddl_delivery_date.SelectedValue);

                    MembershipUser user = Helpers.LoggedUser;

                    hccCartItem newItem = new hccCartItem
                    {
                        CartID        = userCart.CartID,
                        CreatedBy     = (user == null ? Guid.Empty : (Guid)user.ProviderUserKey),
                        CreatedDate   = DateTime.Now,
                        IsTaxable     = plan.IsTaxEligible,
                        ItemDesc      = plan.Description,
                        NumberOfMeals = numMeals,
                        //ItemName = string.Format("{0} - {1} - {2} - {3} & {4}", (prog == null ? string.Empty : prog.Name), plan.Name, option.OptionText, deliveryDate.ToShortDateString(), numMeals),
                        ItemName             = string.Format("{0} - {1} - {2} - {3}", (prog == null ? string.Empty : prog.Name), plan.Name, option.OptionText, deliveryDate.ToShortDateString()),
                        ItemPrice            = itemPrice,
                        ItemTypeID           = (int)Enums.CartItemType.DefinedPlan,
                        Plan_IsAutoRenew     = false, //chx_renew.Checked,
                        Plan_PlanID          = itemId,
                        Plan_ProgramOptionID = optionId,
                        DeliveryDate         = deliveryDate,
                        Quantity             = int.Parse(txt_quantity.Text),
                        UserProfileID        = ((ddlProfiles.Items.Count == 0) ? 0 : Convert.ToInt32(ddlProfiles.SelectedValue)),
                        IsCompleted          = false
                    };
                    Meals obj = new Meals();
                    obj.CartID    = newItem.CartID;
                    obj.MealCount = newItem.NumberOfMeals;
                    obj.NoOfWeeks = plan.NumWeeks;

                    var ID    = obj.CartID;
                    var Meal  = obj.MealCount;
                    var Weeks = obj.NoOfWeeks;

                    HealthyChef.Templates.HealthyChef.Controls.TopHeader header =
                        (HealthyChef.Templates.HealthyChef.Controls.TopHeader) this.Page.Master.FindControl("TopHeader1");
                    if (header != null)
                    {
                        header.MealsCountVal(ID, Meal);
                    }

                    newItem.GetOrderNumber(userCart);
                    int profileId = 0;
                    if (divProfiles.Visible)
                    {
                        profileId = int.Parse(ddlProfiles.SelectedValue);
                    }
                    else
                    {
                        if (CartUserASPNetId != Guid.Empty)
                        {
                            profileId = hccUserProfile.GetParentProfileBy(CartUserASPNetId).UserProfileID;
                        }
                    }

                    if (profileId > 0)
                    {
                        newItem.UserProfileID = profileId;
                    }

                    hccCartItem existItem = hccCartItem.GetBy(userCart.CartID, newItem.ItemName, profileId);

                    if (existItem == null)
                    {
                        newItem.Save();

                        hccProductionCalendar cal;

                        for (int i = 0; i < plan.NumWeeks; i++)
                        {
                            cal = hccProductionCalendar.GetBy(newItem.DeliveryDate.AddDays(7 * i));

                            if (cal != null)
                            {
                                hccCartItemCalendar cartCal = new hccCartItemCalendar {
                                    CalendarID = cal.CalendarID, CartItemID = newItem.CartItemID
                                };
                                cartCal.Save();
                            }
                            else
                            {
                                BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise(
                                    "No production calendar found for Delivery Date: " + newItem.DeliveryDate.AddDays(7 * i).ToShortDateString(), this);
                            }
                        }
                    }
                    else
                    {
                        existItem.AdjustQuantity(existItem.Quantity + newItem.Quantity);
                    }

                    //Recurring Order Record
                    if (cbxRecurring.Checked)
                    {
                        List <hccRecurringOrder> lstRo = null;
                        if (Session["autorenew"] != null)
                        {
                            lstRo = ((List <hccRecurringOrder>)Session["autorenew"]);
                        }
                        else
                        {
                            lstRo = new List <hccRecurringOrder>();
                        }

                        //var filter = cartItemsRecurring.Where(ci => ci.ItemType == Enums.CartItemType.DefinedPlan);

                        //for(var i = 0; i < int.Parse(txt_quantity.Text); i++)
                        //{
                        lstRo.Add(new hccRecurringOrder
                        {
                            CartID         = userCart.CartID,
                            CartItemID     = newItem.CartItemID,
                            UserProfileID  = newItem.UserProfileID,
                            AspNetUserID   = userCart.AspNetUserID,
                            PurchaseNumber = userCart.PurchaseNumber,
                            TotalAmount    = newItem.ItemPrice
                        });
                        Session["autorenew"] = lstRo;
                        //}
                    }

                    HealthyChef.Templates.HealthyChef.Controls.TopHeader header1 =
                        (HealthyChef.Templates.HealthyChef.Controls.TopHeader) this.Page.Master.FindControl("TopHeader1");

                    if (header1 != null)
                    {
                        header.SetCartCount();
                    }

                    //Redirect user to Program Selection screen
                    Response.Redirect("~/meal-programs.aspx");
                    //multi_programs.ActiveViewIndex = 0;
                    //litMessage.Text = "Your Meal Program has been added to your cart.";
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected override void SaveForm()
        {
            try
            {
                hccCart        userCart = hccCart.GetById(this.PrimaryKeyIndex);
                MembershipUser user     = Membership.GetUser(userCart.AspNetUserID);

                if (user != null)
                {
                    hccProgramPlan selPlan = hccProgramPlan.GetById(int.Parse(ddlPlans.SelectedValue));

                    if (selPlan != null)
                    {
                        List <hccProgramOption> progOptions = hccProgramOption.GetBy(selPlan.ProgramID);
                        hccProgramOption        option      = progOptions.Where(a => a.ProgramOptionID == (int.Parse(ddlOptions.SelectedValue))).SingleOrDefault();
                        hccProgram prog = hccProgram.GetById(selPlan.ProgramID);

                        int     numDays    = selPlan.NumDaysPerWeek * selPlan.NumWeeks;
                        decimal dailyPrice = selPlan.PricePerDay + option.OptionValue;
                        decimal itemPrice  = numDays * dailyPrice;
                        int     profileId  = 0;
                        //bool autoRenew = chkAutoRenew.Checked;
                        string   itemFullName = string.Empty;
                        DateTime startDate    = DateTime.Parse(ddlStartDates.SelectedItem.Text);

                        itemFullName = string.Format("{0} - {1} - {2} - {3}",
                                                     prog == null ? string.Empty : prog.Name, selPlan.Name, option.OptionText, startDate.ToShortDateString());

                        if (divProfiles.Visible)
                        {
                            profileId = int.Parse(ddlProfiles.SelectedValue);
                        }
                        else
                        {
                            profileId = hccUserProfile.GetParentProfileBy(userCart.AspNetUserID.Value).UserProfileID;
                        }

                        if (userCart != null && selPlan != null)
                        {
                            int         currentQty = int.Parse(txtQuantity.Text.Trim());
                            hccCartItem existItem  = hccCartItem.GetBy(userCart.CartID, itemFullName, profileId);

                            if (existItem == null)
                            {
                                hccCartItem planItem = new hccCartItem
                                {
                                    CartID               = userCart.CartID,
                                    CreatedBy            = (Guid)Membership.GetUser().ProviderUserKey,
                                    CreatedDate          = DateTime.Now,
                                    IsTaxable            = selPlan.IsTaxEligible,
                                    ItemDesc             = selPlan.Description,
                                    ItemName             = itemFullName,
                                    ItemPrice            = itemPrice,
                                    ItemTypeID           = (int)Enums.CartItemType.DefinedPlan,
                                    Plan_IsAutoRenew     = false, //autoRenew,
                                    Plan_PlanID          = selPlan.PlanID,
                                    Plan_ProgramOptionID = option.ProgramOptionID,
                                    DeliveryDate         = startDate,
                                    UserProfileID        = profileId,
                                    Quantity             = currentQty,
                                    IsCompleted          = false
                                };

                                planItem.GetOrderNumber(userCart);
                                planItem.Save();

                                hccProductionCalendar cal;

                                for (int i = 0; i < selPlan.NumWeeks; i++)
                                {
                                    cal = hccProductionCalendar.GetBy(planItem.DeliveryDate.AddDays(7 * i));

                                    if (cal != null)
                                    {
                                        hccCartItemCalendar cartCal = new hccCartItemCalendar {
                                            CalendarID = cal.CalendarID, CartItemID = planItem.CartItemID, IsFulfilled = false
                                        };
                                        cartCal.Save();
                                    }
                                    else
                                    {
                                        BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise(
                                            "No production calendar found for Delivery Date: " + planItem.DeliveryDate.AddDays(7 * i).ToShortDateString(), this);
                                    }
                                }


                                if (cbxRecurring.Checked)
                                {
                                    var cartItemsRecurring = hccCartItem.GetBy(userCart.CartID);
                                    var filter             = cartItemsRecurring.Where(ci => ci.ItemType == Enums.CartItemType.DefinedPlan);
                                    var roItem             = new hccRecurringOrder();
                                    roItem.CartID         = planItem.CartID;
                                    roItem.CartItemID     = planItem.CartItemID;
                                    roItem.UserProfileID  = planItem.UserProfileID;
                                    roItem.AspNetUserID   = userCart.AspNetUserID;
                                    roItem.PurchaseNumber = userCart.PurchaseNumber;
                                    roItem.TotalAmount    = Math.Round(Convert.ToDecimal(Convert.ToDouble(planItem.ItemPrice) - Convert.ToDouble(planItem.ItemPrice) * 0.05), 2);
                                    roItem.Save();
                                    if (planItem != null)

                                    {
                                        planItem.Plan_IsAutoRenew = true;
                                        planItem.Save();
                                    }

                                    //foreach (var recurringOrder in filter.Select(item => new hccRecurringOrder
                                    //{
                                    //    CartID = item.CartID,
                                    //    CartItemID = item.CartItemID,
                                    //    UserProfileID = item.UserProfileID,
                                    //    AspNetUserID = userCart.AspNetUserID,
                                    //    PurchaseNumber = userCart.PurchaseNumber,
                                    //    TotalAmount = userCart.TotalAmount
                                    //}))
                                    //{
                                    //    recurringOrder.Save();
                                    //}
                                }
                                OnSaved(new ControlSavedEventArgs(planItem.CartItemID));
                                cbxRecurring.Checked = false;
                            }
                            else
                            {
                                if (existItem.AdjustQuantity(existItem.Quantity + currentQty))
                                {
                                    OnSaved(new ControlSavedEventArgs(existItem.CartItemID));
                                }
                                cbxRecurring.Checked = false;
                            }
                        }
                    }
                }
                //Page.Response.Redirect(Page.Request.Url.ToString()+ "#tabs9", true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 19
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (rdoCustomerType.SelectedIndex == 0)
                {
                    //Check to see that the e-mail address hasn't already been taken
                    var users = (from MembershipUser u in Membership.GetAllUsers()
                                 where u.Email == txtEmail.Text.Trim()
                                 select new { Email = u.Email }).ToList();

                    if (users.Count == 0)
                    {
                        usrctrlRegister.Email      = txtEmail.Text.Trim();
                        multiViews.ActiveViewIndex = (int)LoginView.Registration;
                        Page.Title = "Account Sign Up";
                    }
                    else
                    {
                        litMessage.Text = "The e-mail address you entered is already in use.";
                    }
                }
                else
                {
                    string userName = Membership.GetUserNameByEmail(txtEmail.Text.Trim());

                    if (userName == null)
                    {
                        userName = txtEmail.Text.Trim();
                    }

                    if (Membership.ValidateUser(userName, txtPassword.Text.Trim()))
                    {
                        MembershipUser user  = Membership.GetUser(userName);
                        string []      roles = Roles.GetRolesForUser(userName);
                        if (user != null)
                        {
                            // ensure user has Customer record in db
                            hccCart unloggedCart = hccCart.GetCurrentCart();
                            hccCart loggedCart   = hccCart.GetCurrentCart(user);

                            if (unloggedCart != null)
                            {
                                hccUserProfile parentProfile = hccUserProfile.GetParentProfileBy((Guid)user.ProviderUserKey);

                                if (parentProfile != null) // no profile for user OR is Admin and admin's dont have profiles
                                {
                                    List <hccCartItem> unloggedcartItems = hccCartItem.GetBy(unloggedCart.CartID);
                                    List <hccCartItem> loggedcartItems   = hccCartItem.GetBy(loggedCart.CartID);

                                    unloggedcartItems.ToList().ForEach(delegate(hccCartItem item)
                                    {
                                        hccCartItem modelItem = loggedcartItems.FirstOrDefault(a => a.UserProfileID == parentProfile.UserProfileID &&
                                                                                               a.DeliveryDate == item.DeliveryDate);

                                        if (modelItem != null)
                                        {
                                            item.OrderNumber = modelItem.OrderNumber;
                                        }
                                        else
                                        {
                                            item.GetOrderNumber(loggedCart);
                                        }

                                        item.UserProfileID = parentProfile.UserProfileID;

                                        if (item.ItemType == Enums.CartItemType.GiftCard)
                                        {
                                            if (item.Gift_IssuedTo == null || item.Gift_IssuedTo == Guid.Empty)
                                            {
                                                item.Gift_IssuedTo   = parentProfile.MembershipID;
                                                item.Gift_IssuedDate = DateTime.Now;
                                            }
                                        }


                                        item.CartID = loggedCart.CartID;
                                        item.Save();
                                    });

                                    unloggedCart.StatusID = (int)Enums.CartStatus.Cancelled;
                                    unloggedCart.Save();
                                }
                            }
                        }
                        if (Request.QueryString["fc"] != null)
                        {
                            FormsAuthentication.SetAuthCookie(userName, true);
                            Response.Redirect("~/cart.aspx?confirm=1", true);
                        }
                        else
                        {
                            // Was user redirected from meal programs due to recurring selection
                            if (Request.QueryString["rp"] != null)
                            {
                                FormsAuthentication.SetAuthCookie(userName, true);
                                Response.Redirect("~/details/" + Request.QueryString["rp"] + "?rc=true");
                            }
                            else
                            {
                                FormsAuthentication.RedirectFromLoginPage(userName, true);
                            }
                        }
                    }
                    else
                    {
                        MembershipUser user = Membership.GetUser(userName);

                        if (user == null || !Membership.ValidateUser(userName, txtPassword.Text.Trim()))
                        {
                            litMessage.Text = "Login Attempt Failed.  Email/password combination not recognized.  Please re-enter your email address and account password.  If you have forgotten your password, please click the link below or call customer service at 866-575-2433 for assistance.";
                        }
                        else if (!user.IsApproved)
                        {
                            litMessage.Text = "That account has been deactivated. Please contact customer service at 866-575-2433 for assistance.";
                        }
                        else if (user.IsLockedOut)
                        { //password lock-out
                            litMessage.Text = "That account is locked out. Please contact customer service at 866-575-2433 for assistance.";
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void ChkAutoRenew_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                CheckBox         chbActive   = (CheckBox)sender;
                ListViewDataItem item        = (ListViewDataItem)chbActive.Parent;
                TextBox          txtQuantity = lvwCartItems.Items[item.DataItemIndex].FindControl("txtQuantity") as TextBox;

                if (chbActive.Text != null)
                {
                    int               cartitemid  = Convert.ToInt32(chbActive.Text);
                    hccCartItem       hcccartItem = hccCartItem.GetById(cartitemid);
                    hccRecurringOrder IsExistingrecurringorder = null;
                    if (hcccartItem.ItemTypeID == 2)
                    {
                        if (hcccartItem != null)
                        {
                            IsExistingrecurringorder = hccRecurringOrder.GetByCartItemId(hcccartItem.CartItemID);
                        }
                        else
                        {
                            IsExistingrecurringorder = null;
                        }

                        if (IsExistingrecurringorder != null)
                        {
                            IsExistingrecurringorder.Delete();
                            if (hcccartItem != null)
                            {
                                hcccartItem.Plan_IsAutoRenew = false;
                                hcccartItem.DiscountAdjPrice = Convert.ToDecimal("0.00");
                                hcccartItem.DiscountPerEach  = Convert.ToDecimal("0.00");
                                hcccartItem.Save();
                            }
                            lblfeedback.Visible = true;
                            lblfeedback.Text    = "Auto renew Item Deleted Successfully";
                        }
                        else
                        {
                            hccCart hccCart = hccCart.GetById(hcccartItem.CartID);
                            if (hccCart != null)
                            {
                                hccRecurringOrder hccrecurringOrder = new hccRecurringOrder
                                {
                                    CartID         = hcccartItem.CartID,
                                    CartItemID     = hcccartItem.CartItemID,
                                    UserProfileID  = hcccartItem.UserProfileID,
                                    AspNetUserID   = hccCart.AspNetUserID,
                                    PurchaseNumber = hccCart.PurchaseNumber,
                                    TotalAmount    = Math.Round(Convert.ToDecimal(Convert.ToDouble(hcccartItem.ItemPrice) - Convert.ToDouble(hcccartItem.ItemPrice) * 0.05), 2)
                                };
                                hccrecurringOrder.Save();

                                if (hcccartItem != null)
                                {
                                    hcccartItem.Plan_IsAutoRenew = true;
                                    hcccartItem.DiscountAdjPrice = Convert.ToDecimal(hcccartItem.ItemPrice);
                                    hcccartItem.DiscountPerEach  = Convert.ToDecimal(Convert.ToDouble(hcccartItem.ItemPrice) * 0.05);
                                    // lblProfileSubTotalAdj.Text = (this.CurrentProfileCart.SubTotalNA - (this.CurrentProfileCart.SubDiscountAmount+ (hcccartItem.DiscountPerEach))).ToString("c");
                                    hcccartItem.Save();
                                }
                                lblfeedback.Visible = true;
                                lblfeedback.Text    = "Auto renew Item Created Successfully";
                            }
                        }
                    }
                    else
                    {
                        if (chbActive.Checked == true && Convert.ToInt32(txtQuantity.Text) <= 1)
                        {
                            chbActive.Checked = false;
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Family style requires atleast 2 servings. Please increase the quantity to apply Family Style')", true);
                        }
                        else
                        {
                            if (hcccartItem != null)
                            {
                                if (chbActive.Checked == true)
                                {
                                    hcccartItem.Plan_IsAutoRenew = true;
                                    hcccartItem.DiscountAdjPrice = Convert.ToDecimal(hcccartItem.ItemPrice);
                                    hcccartItem.DiscountPerEach  = Math.Round(Convert.ToDecimal(Convert.ToDouble(hcccartItem.ItemPrice) * 0.1), 2);
                                }
                                else
                                {
                                    hcccartItem.Plan_IsAutoRenew = false;
                                    hcccartItem.DiscountAdjPrice = Convert.ToDecimal("0.00");
                                    hcccartItem.DiscountPerEach  = Convert.ToDecimal("0.00");
                                }
                                hcccartItem.Save();
                            }
                        }
                    }
                }
                else
                {
                    lblfeedback.Visible = true;
                    lblfeedback.Text    = "There is no records found";
                }
                OnCartItemListItemUpdated();
                //Page.Response.Redirect(Page.Request.Url.ToString() + "#tabs9", true);
            }
            catch (Exception E)
            {
                lblfeedback.Visible = true;
                lblfeedback.Text    = "Error in deleting cart item " + E.Message;
            }
        }