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; } }
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; } }