protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //BindDDLS(); try { if (Request.QueryString["id"] != null && !string.IsNullOrWhiteSpace(Request.QueryString["id"])) { int id = int.Parse(Request.QueryString["id"].ToString()); hccCart cart = hccCart.GetById(id); if (cart != null) { txtSearchPurchaseNum.Text = cart.PurchaseNumber.ToString(); btnSearch_Click(this, new EventArgs()); } } } catch (Exception) { throw; } } }
protected void lkbSelect_Click(object sender, EventArgs e) { LinkButton lkbSelect = (LinkButton)sender; ListViewDataItem lvdi = (ListViewDataItem)lkbSelect.Parent; hccCart cart = hccCart.GetById(int.Parse(lvwPurchaseHistory.DataKeys[lvdi.DataItemIndex].Value.ToString())); this.PrimaryKeyIndex = cart.CartID; HtmlTableRow trStatus = (HtmlTableRow)lvdi.FindControl("trStatus"); HtmlTableRow trDetail = (HtmlTableRow)lvdi.FindControl("trDetails"); LinkButton lkbPrint = (LinkButton)trDetail.FindControl("lkbPrint"); if (Roles.IsUserInRole(Helpers.LoggedUser.UserName, "Administrators")) { trStatus.Attributes.Remove("style"); } trDetail.Visible = !trDetail.Visible; trStatus.Visible = trDetail.Visible; if (lkbSelect.Text == "Details") { trDetail.Cells[0].InnerHtml = cart.ToHtml(); } lkbSelect.Text = trDetail.Visible ? "Hide" : "Details"; lkbPrint.Visible = trDetail.Visible; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { MembershipUser user = Helpers.LoggedUser; if (user != null) { CurrentCart = hccCart.GetCurrentCart(user); } else { CurrentCart = hccCart.GetCurrentCart(); } if (CurrentCart != null) { CartDisplay1.CurrentCartId = CurrentCart.CartID; CartDisplay1.Bind(); } } catch (Exception ex) { throw ex; } } }
public void GetOrderNumber(hccCart cart) { try { if (cart != null) { if (this.OrderNumber == null || !this.OrderNumber.Contains(cart.PurchaseNumber.ToString())) { List <hccCartItem> cartItems = hccCartItem.GetBy(cart.CartID); if (cartItems.Count == 0) { this.OrderNumber = cart.PurchaseNumber.ToString() + "-01"; } else { cartItems.ForEach(delegate(hccCartItem existItem) { if (this.UserProfile != null) { if ((this.UserProfile.UseParentShipping || this.UserProfile.ShippingAddressID == existItem.UserProfile.ShippingAddressID) && this.DeliveryDate == existItem.DeliveryDate) { this.OrderNumber = existItem.OrderNumber; } } else { if (this.DeliveryDate == existItem.DeliveryDate) { this.OrderNumber = existItem.OrderNumber; } } }); if (string.IsNullOrWhiteSpace(this.OrderNumber) || !this.OrderNumber.Contains(cart.PurchaseNumber.ToString())) { string minOrderNumber = string.Empty; minOrderNumber = cartItems.Max(a => a.OrderNumber); if (string.IsNullOrWhiteSpace(minOrderNumber)) { this.OrderNumber = cart.PurchaseNumber.ToString() + "-01"; } else { string ord = minOrderNumber.Split(new char[] { '-' })[1]; this.OrderNumber = cart.PurchaseNumber.ToString() + "-" + ((int.Parse(ord)) + 1).ToString("d2"); } } } } } } catch (Exception ex) { throw ex; } }
protected override void SaveForm() { try { //if (CurrentCartItemID > 0) // CurrentGiftCert = hccCartItem.GetById(CurrentCartItemID); //else // CurrentGiftCert = hccCartItem.Gift_GenerateNew(this.PrimaryKeyIndex); if (CurrentGiftCert != null) { hccCart userCart = hccCart.GetById(this.PrimaryKeyIndex); if (userCart != 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; if (ShowSentToRecipCheckbox) { CurrentGiftCert.IsCompleted = chkSentToRecip.Checked; } CurrentGiftCert.Save(); this.OnSaved(new ControlSavedEventArgs(CurrentGiftCert.CartItemID)); } } } catch { throw; } }
public UsedCoupon(hccCart cart) { DateUsed = cart.PurchaseDate.Value; if (cart.CouponID.HasValue) { hccCoupon coup = hccCoupon.GetById(cart.CouponID.Value); if (coup != null) { CouponInfo = coup.ToString(); } } PurchaseInfo = cart.ToString(); }
void SaveLedger(hccLedger ledger, hccCart CurrentCart, hccUserProfile profile) { ledger = new hccLedger { PaymentDue = CurrentCart.PaymentDue, TotalAmount = CurrentCart.TotalAmount, AspNetUserID = CurrentCart.AspNetUserID.Value, AsscCartID = CurrentCart.CartID, CreatedBy = (Guid)Helpers.LoggedUser.ProviderUserKey, CreatedDate = DateTime.Now, Description = "Cart Order Payment - Purchase Number: " + CurrentCart.PurchaseNumber.ToString() + " - from re-snapshot of order.", TransactionTypeID = (int)Enums.LedgerTransactionType.Purchase }; if (CurrentCart.IsTestOrder) { ledger.Description += " - Test Mode"; } if (CurrentCart.CreditAppliedToBalance > 0) { profile.AccountBalance = profile.AccountBalance - CurrentCart.CreditAppliedToBalance; ledger.CreditFromBalance = CurrentCart.CreditAppliedToBalance; } hccLedger lastLedger = hccLedger.GetByMembershipID(profile.MembershipID, null).OrderByDescending(a => a.CreatedDate).FirstOrDefault(); bool isDuplicateLedger = false; if (lastLedger != null) { if (ledger.CreatedBy == lastLedger.CreatedBy && ledger.CreditFromBalance == lastLedger.CreditFromBalance && ledger.Description == lastLedger.Description && ledger.PaymentDue == lastLedger.PaymentDue && ledger.TransactionTypeID == lastLedger.TransactionTypeID && ledger.TotalAmount == lastLedger.TotalAmount) { isDuplicateLedger = true; } } if (!isDuplicateLedger) { ledger.PostBalance = profile.AccountBalance; ledger.Save(); profile.Save(); } }
public static List <hccCartItem> GeCartItemsByPurchaseNumber(int purchaseNumber) { try { using (var cont = new healthychefEntities()) { hccCart cart = cont.hccCarts.Where(c => c.PurchaseNumber == purchaseNumber).Single(); var Listofcartitems = cont.hccCartItems.Where(c => c.CartID == cart.CartID).ToList(); return(Listofcartitems); } } catch (Exception ex) { throw ex; } }
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; } }
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; } }
void rblItemType_SelectedIndexChanged(object sender, EventArgs e) { MenuItemAddToCart1.Clear(); ProgramPlanAddToCart1.Clear(); GiftCertEdit1.Clear(); if (this.PrimaryKeyIndex > 0 && CurrentCart == null) { hccUserProfile profile = hccUserProfile.GetById(this.PrimaryKeyIndex); CurrentCart = hccCart.GetCurrentCart(profile.ASPUser); } if (CurrentCart != null) { switch (rblItemType.SelectedValue) { case "1": pnlAlaCarte.Visible = true; pnlProgramPlan.Visible = false; pnlGiftCard.Visible = false; MenuItemAddToCart1.PrimaryKeyIndex = CurrentCart.CartID; MenuItemAddToCart1.Bind(); break; case "2": pnlAlaCarte.Visible = false; pnlProgramPlan.Visible = true; pnlGiftCard.Visible = false; ProgramPlanAddToCart1.PrimaryKeyIndex = CurrentCart.CartID; ProgramPlanAddToCart1.Bind(); break; case "3": pnlAlaCarte.Visible = false; pnlProgramPlan.Visible = false; pnlGiftCard.Visible = true; GiftCertEdit1.PrimaryKeyIndex = CurrentCart.CartID; GiftCertEdit1.Bind(); break; default: break; } } }
void BindddlProfiles() { // get all profiles under the CartUserASPNetId hccCart userCart = hccCart.GetById(this.PrimaryKeyIndex); List <hccUserProfile> memberProfiles = hccUserProfile.GetBy(userCart.AspNetUserID.Value, true); if (memberProfiles.Count > 1) { ddlProfiles.DataSource = memberProfiles; ddlProfiles.DataTextField = "ProfileName"; ddlProfiles.DataValueField = "UserProfileID"; ddlProfiles.DataBind(); ddlProfiles.Items.Insert(0, new ListItem("Select a Profile...", "-1")); divProfiles.Visible = true; rfvProfiles.ValidationGroup = this.ValidationGroup; } }
protected void lvwPurchaseHistory_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem) { HiddenField hdnCartId = (HiddenField)e.Item.FindControl("hdnCartId"); HiddenField hdnStatus = (HiddenField)e.Item.FindControl("hdnStatus"); hccCart cart = (hccCart)e.Item.DataItem; if (hdnCartId != null) { hdnCartId.Value = cart.CartID.ToString(); } if (hdnStatus != null) { hdnStatus.Value = cart.StatusID.ToString(); } } }
public static hccCartItem Gift_GenerateNew(int cartId) { try { string redeemCode = Guid.NewGuid().ToString().Substring(0, 8).ToUpper(); while (RedeemCodeExists(redeemCode)) { redeemCode = Guid.NewGuid().ToString().Substring(0, 8).ToUpper(); } hccCartItem giftCert = new hccCartItem { CartID = cartId, ItemTypeID = (int)Enums.CartItemType.GiftCard, IsTaxable = false, Quantity = 1, CreatedBy = (Helpers.LoggedUser == null ? Guid.Empty : (Guid)Helpers.LoggedUser.ProviderUserKey), CreatedDate = DateTime.Now, IsCompleted = false, Gift_RedeemCode = redeemCode }; hccCart userCart = hccCart.GetById(cartId); if (userCart.AspNetUserID.HasValue && userCart.AspNetUserID.Value != Guid.Empty) { hccUserProfile prof = hccUserProfile.GetParentProfileBy(userCart.AspNetUserID.Value); if (prof != null) { giftCert.UserProfileID = prof.UserProfileID; } giftCert.Gift_IssuedTo = userCart.AspNetUserID; giftCert.Gift_IssuedDate = DateTime.Now; } return(giftCert); } catch (Exception ex) { throw ex; } }
void btnCancelPurchase_Click(object sender, EventArgs e) { try { hccCart cart = hccCart.GetBy(CurrentPurchaseNumber); if (cart != null) { bool doCancel = (btnCancelPurchase.Text == "Void Transaction"); List <hccCartItem> items = hccCartItem.GetBy(cart.CartID); items.ForEach(delegate(hccCartItem item) { item.IsCancelled = doCancel; item.Save(); }); cart.StatusID = doCancel ? (int)Common.Enums.CartStatus.Cancelled : (int)Common.Enums.CartStatus.Paid; cart.Save(); CurrentPurchaseNumberIsCancelled = doCancel; if (doCancel) { btnCancelPurchase.Text = "Un-Cancel"; } else { btnCancelPurchase.Text = "Void Transaction"; } BindGvwOrderNumbers(); BindgvwCartItems(); } } catch (Exception) { throw; } }
protected override void LoadForm() { try { if (this.PrimaryKeyIndex > 0 && CurrentCart == null) { hccUserProfile profile = hccUserProfile.GetById(this.PrimaryKeyIndex); CurrentCart = hccCart.GetCurrentCart(profile.ASPUser); } if (CurrentCart != null) { CartDisplay1.CurrentCartId = CurrentCart.CartID; CartDisplay1.Bind(); } } catch (Exception) { throw; } }
public void SetCartCount() { try { MembershipUser user = Helpers.LoggedUser; if (user == null || (user != null && Roles.IsUserInRole(user.UserName, "Customer"))) { aCart.Visible = true; hccCart cart = null; if (user == null) { cart = hccCart.GetCurrentCart(); } // commented out DBall 10-14-2013 //else // cart = hccCart.GetCurrentCart(user); if (cart != null) { List <hccCartItem> cartItems = hccCartItem.GetWithoutSideItemsBy(cart.CartID); lblCartCount.Text = cartItems.Count.ToString(); } else { lblCartCount.Text = "0"; } } else { } } catch (Exception) { throw; } }
void gvwOrderNumbers_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { //bool doCancel = gvwOrderNumbers.Rows[e.RowIndex].Cells[4].Controls.OfType<LinkButton>().First().Text == "Cancel All Items"; //string ordNum = gvwOrderNumbers.DataKeys[e.RowIndex].Value.ToString(); hccCart cart = hccCart.GetBy(CurrentPurchaseNumber); if (cart != null) { List <hccCartItem> cartitems = hccCartItem.GetBy(cart.CartID); //List<hccCartItem> ordItems = cartitems.Where(a => a.OrderNumber == ordNum).ToList(); //ordItems.ForEach(delegate(hccCartItem item) { item.IsCancelled = doCancel; item.Save(); }); if (cartitems.Count(a => !a.IsCancelled) == 0) { cart.StatusID = (int)Common.Enums.CartStatus.Cancelled; cart.Save(); } else { cart.StatusID = (int)Common.Enums.CartStatus.Paid; cart.Save(); } BindGvwOrderNumbers(); BindgvwCartItems(); } } 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); 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 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; } }
public string UpdateCarts(List <UpdateCartItem> carts) { try { UpdateCartItem updatecart = carts[0]; hccCart CurrentCart = hccCart.GetById(updatecart.cartId); hccUserProfile ownerProfile = CurrentCart.OwnerProfile; hccAddress snapBillAddr = null; List <hccCartItem> cartItems = null; bool isAuthNet = false; hccLedger ledger = null; string retVal = string.Empty; if (CurrentCart != null && ownerProfile != null) { hccAddress billAddr = null; hccUserProfilePaymentProfile activePaymentProfile = ownerProfile.ActivePaymentProfile; if (updatecart.updateStatus && CurrentCart.StatusID != updatecart.statusId) { CurrentCart.StatusID = updatecart.statusId; CurrentCart.ModifiedBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.ModifiedDate = DateTime.Now; if (updatecart.statusId == (int)Enums.CartStatus.Paid) { if (!CurrentCart.PurchaseBy.HasValue) { CurrentCart.PurchaseBy = (Guid)Helpers.LoggedUser.ProviderUserKey; } if (!CurrentCart.PurchaseDate.HasValue) { CurrentCart.PurchaseDate = DateTime.Now; } } CurrentCart.Save(); } if (updatecart.updateAddresses) // re-snap addresses { if (ownerProfile.BillingAddressID.HasValue) { billAddr = hccAddress.GetById(ownerProfile.BillingAddressID.Value); if (billAddr != null) { snapBillAddr = new hccAddress { Address1 = billAddr.Address1, Address2 = billAddr.Address2, AddressTypeID = (int)Enums.AddressType.BillingSnap, City = billAddr.City, Country = billAddr.Country, DefaultShippingTypeID = billAddr.DefaultShippingTypeID, FirstName = billAddr.FirstName, IsBusiness = billAddr.IsBusiness, LastName = billAddr.LastName, Phone = billAddr.Phone, PostalCode = billAddr.PostalCode, State = billAddr.State, ProfileName = ownerProfile.ProfileName }; snapBillAddr.Save(); } } else { retVal += "Profile has no billing address on record."; } if (cartItems == null) { cartItems = hccCartItem.GetBy(CurrentCart.CartID); } cartItems.ForEach(delegate(hccCartItem ci) { hccAddress shipAddr = null; if (snapBillAddr != null) { ci.SnapBillAddrId = snapBillAddr.AddressID; } if (ci.UserProfile == null) { ci.UserProfileID = ownerProfile.UserProfileID; } if (ci.UserProfile.ShippingAddressID.HasValue) { shipAddr = hccAddress.GetById(ci.UserProfile.ShippingAddressID.Value); } if (shipAddr != null) { hccAddress snapShipAddr = new hccAddress { Address1 = shipAddr.Address1, Address2 = shipAddr.Address2, AddressTypeID = (int)Enums.AddressType.ShippingSnap, City = shipAddr.City, Country = shipAddr.Country, DefaultShippingTypeID = shipAddr.DefaultShippingTypeID, FirstName = shipAddr.FirstName, IsBusiness = shipAddr.IsBusiness, LastName = shipAddr.LastName, Phone = shipAddr.Phone, PostalCode = shipAddr.PostalCode, State = shipAddr.State, ProfileName = ci.UserProfile.ProfileName }; snapShipAddr.Save(); ci.SnapShipAddrId = snapShipAddr.AddressID; } ci.Save(); }); } if (updatecart.rerunAuthNet) { CurrentCart.StatusID = (int)Enums.CartStatus.Unfinalized; CurrentCart.PurchaseBy = null; CurrentCart.PurchaseDate = null; if (ownerProfile != null) { AuthNetConfig ANConfig = new AuthNetConfig(); if (ANConfig.Settings.TestMode) { CurrentCart.IsTestOrder = true; } if (CurrentCart.PaymentDue > 0.00m) { try { // if total balance remains CustomerInformationManager cim = new CustomerInformationManager(); if (activePaymentProfile != null) { AuthorizeNet.Order order = new AuthorizeNet.Order(ownerProfile.AuthNetProfileID, activePaymentProfile.AuthNetPaymentProfileID, null); // charge CIM account with PaymentDue balance order.Amount = CurrentCart.PaymentDue; order.InvoiceNumber = CurrentCart.PurchaseNumber.ToString(); order.Description = "Healthy Chef Creations Purchase #" + CurrentCart.PurchaseNumber.ToString(); AuthorizeNet.IGatewayResponse rsp = cim.AuthorizeAndCapture(order); try { CurrentCart.AuthNetResponse = rsp.ResponseCode + "|" + rsp.Approved.ToString() + "|" + rsp.AuthorizationCode + "|" + rsp.InvoiceNumber + "|" + rsp.Message + "|" + rsp.TransactionID + "|" + rsp.Amount.ToString() + "|" + rsp.CardNumber; } catch (Exception) { } if (rsp.ResponseCode.StartsWith("1")) { CurrentCart.ModifiedBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.ModifiedDate = DateTime.Now; CurrentCart.PurchaseBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.PurchaseDate = DateTime.Now; CurrentCart.PaymentProfileID = activePaymentProfile.PaymentProfileID; CurrentCart.StatusID = (int)Enums.CartStatus.Paid; isAuthNet = true; } CurrentCart.Save(); } else { return("No active payment profile."); } } catch (Exception ex) { if (ex is InvalidOperationException) { if (CurrentCart.IsTestOrder) { CurrentCart.ModifiedBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.ModifiedDate = DateTime.Now; CurrentCart.PaymentProfileID = activePaymentProfile.PaymentProfileID; CurrentCart.AuthNetResponse = ex.Message; CurrentCart.StatusID = (int)Enums.CartStatus.Unfinalized; CurrentCart.Save(); } else { BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise(ex.Message, this, ex); } } else { throw; } } } else { // no balance left to pay on order, set as paid CurrentCart.AuthNetResponse = "Paid with account balance."; CurrentCart.ModifiedBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.ModifiedDate = DateTime.Now; CurrentCart.PurchaseBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.PurchaseDate = DateTime.Now; CurrentCart.StatusID = (int)Enums.CartStatus.Paid; CurrentCart.Save(); } } } if (updatecart.createLedgerEntry) { if (ledger == null) { ledger = hccLedger.GetBy(CurrentCart.CartID); } if (ledger == null) { SaveLedger(ledger, CurrentCart, ownerProfile); } } if (updatecart.createNewSnapshot) { if (((Enums.CartStatus)CurrentCart.StatusID) == Enums.CartStatus.Paid) { if (ledger == null) { ledger = hccLedger.GetBy(CurrentCart.CartID); } if (ledger == null) // it still equals null { SaveLedger(ledger, CurrentCart, ownerProfile); } // create snapshot here hccCartSnapshot snap = new hccCartSnapshot { CartId = CurrentCart.CartID, MembershipId = ownerProfile.MembershipID, LedgerId = ledger.LedgerID, AccountBalance = ownerProfile.AccountBalance, AuthNetProfileId = ownerProfile.AuthNetProfileID, CreatedBy = (Guid)Helpers.LoggedUser.ProviderUserKey, CreatedDate = DateTime.Now, DefaultCouponId = ownerProfile.DefaultCouponId, Email = ownerProfile.ASPUser.Email, FirstName = ownerProfile.FirstName, LastName = ownerProfile.LastName, ProfileName = ownerProfile.ProfileName }; if (isAuthNet) { if (activePaymentProfile != null) { snap.AuthNetPaymentProfileId = activePaymentProfile.AuthNetPaymentProfileID; snap.CardTypeId = activePaymentProfile.CardTypeID; snap.CCLast4 = activePaymentProfile.CCLast4; snap.ExpMon = activePaymentProfile.ExpMon; snap.ExpYear = activePaymentProfile.ExpYear; snap.NameOnCard = activePaymentProfile.NameOnCard; } else { return("No active payment profile."); } } else { snap.AuthNetPaymentProfileId = string.Empty; snap.CardTypeId = 0; snap.CCLast4 = string.Empty; snap.ExpMon = 0; snap.ExpYear = 0; snap.NameOnCard = string.Empty; } snap.Save(); if (billAddr == null && ownerProfile.BillingAddressID.HasValue) { billAddr = hccAddress.GetById(ownerProfile.BillingAddressID.Value); } if (billAddr != null) { snapBillAddr = new hccAddress { Address1 = billAddr.Address1, Address2 = billAddr.Address2, AddressTypeID = billAddr.AddressTypeID, City = billAddr.City, Country = billAddr.Country, DefaultShippingTypeID = billAddr.DefaultShippingTypeID, FirstName = billAddr.FirstName, IsBusiness = billAddr.IsBusiness, LastName = billAddr.LastName, Phone = billAddr.Phone, PostalCode = billAddr.PostalCode, State = billAddr.State, ProfileName = ownerProfile.ProfileName }; snapBillAddr.Save(); } else { retVal += "Profile has no billing address on record."; } // copy and replace of all addresses for snapshot if (cartItems == null) { cartItems = hccCartItem.GetBy(CurrentCart.CartID); } cartItems.ToList().ForEach(delegate(hccCartItem ci) { if (snapBillAddr != null) { ci.SnapBillAddrId = snapBillAddr.AddressID; } hccAddress shipAddr = null; if (ci.UserProfile.ShippingAddressID.HasValue) { shipAddr = hccAddress.GetById(ci.UserProfile.ShippingAddressID.Value); } if (shipAddr != null) { hccAddress snapShipAddr = new hccAddress { Address1 = shipAddr.Address1, Address2 = shipAddr.Address2, AddressTypeID = shipAddr.AddressTypeID, City = shipAddr.City, Country = shipAddr.Country, DefaultShippingTypeID = shipAddr.DefaultShippingTypeID, FirstName = shipAddr.FirstName, IsBusiness = shipAddr.IsBusiness, LastName = shipAddr.LastName, Phone = shipAddr.Phone, PostalCode = shipAddr.PostalCode, State = shipAddr.State, ProfileName = ci.UserProfile.ProfileName }; snapShipAddr.Save(); ci.SnapShipAddrId = snapShipAddr.AddressID; } else { retVal += "Profile has no billing address on record."; } ci.Save(); }); } } if (updatecart.sendCustomerEmail) { try { Email.EmailController ec = new Email.EmailController(); ec.SendMail_OrderConfirmationMerchant(ownerProfile.FirstName + " " + ownerProfile.LastName, CurrentCart.ToHtml(), CurrentCart.CartID); } catch (Exception ex) { BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise("Send Merchant Mail Failed", this, ex); } } if (updatecart.sendMerchantEmail) { try { Email.EmailController ec = new Email.EmailController(); ec.SendMail_OrderConfirmationCustomer(ownerProfile.ASPUser.Email, ownerProfile.FirstName + " " + ownerProfile.LastName, CurrentCart.ToHtml()); } catch (Exception ex) { BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise("Send customer Mail Failed", this, ex); } } if (updatecart.repairCartCals) { if (cartItems == null) { cartItems = hccCartItem.GetBy(CurrentCart.CartID); } // wrap in programs cartItems.ForEach(delegate(hccCartItem ci) { if (ci.ItemType == Enums.CartItemType.DefinedPlan) { hccProgramPlan cp = hccProgramPlan.GetById(ci.Plan_PlanID.Value); if (cp != null) { for (int i = 0; i < cp.NumWeeks; i++) { hccProductionCalendar cal; cal = hccProductionCalendar.GetBy(ci.DeliveryDate.AddDays(7 * i)); if (cal != null) { hccCartItemCalendar existCal = hccCartItemCalendar.GetBy(ci.CartItemID, cal.CalendarID); if (existCal == null) { hccCartItemCalendar cartCal = new hccCartItemCalendar { CalendarID = cal.CalendarID, CartItemID = ci.CartItemID, IsFulfilled = false }; cartCal.Save(); } } else { BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise( "No production calendar found for Delivery Date: " + ci.DeliveryDate.AddDays(7 * i).ToShortDateString(), this); } } } } }); } if (updatecart.reCalcItemTax) { try { if (cartItems == null) { cartItems = hccCartItem.GetBy(CurrentCart.CartID); } List <ProfileCart> CurrentProfileCarts = new List <ProfileCart>(); if (cartItems.Count > 0) { hccUserProfile parentProfile = hccUserProfile.GetParentProfileBy(CurrentCart.AspNetUserID.Value); //List<hccProductionCalendar> pc = new List<hccProductionCalendar>(); foreach (hccCartItem cartItem in cartItems) { ProfileCart profCart; int shippingAddressId; //if (!pc.Exists(a => a.DeliveryDate == cartItem.DeliveryDate)) // pc.Add(hccProductionCalendar.GetBy(cartItem.DeliveryDate)); //hccProductionCalendar cpc = pc.SingleOrDefault(a => a.DeliveryDate == cartItem.DeliveryDate); //if (cpc != null && (cpc.OrderCutOffDate.AddDays(1) >= DateTime.Now || (HttpContext.Current.Request.Url.OriginalString.Contains("Admin")))) //{ if (cartItem.UserProfile != null && (cartItem.UserProfile.UseParentShipping || cartItem.UserProfile.ShippingAddressID.HasValue)) { if (cartItem.UserProfile.UseParentShipping) { shippingAddressId = parentProfile.ShippingAddressID.Value; } else { shippingAddressId = cartItem.UserProfile.ShippingAddressID.Value; } profCart = CurrentProfileCarts .SingleOrDefault(a => a.ShippingAddressId == shippingAddressId && a.DeliveryDate == cartItem.DeliveryDate); } else { profCart = CurrentProfileCarts .SingleOrDefault(a => a.ShippingAddressId == 0 && a.DeliveryDate == cartItem.DeliveryDate); shippingAddressId = 0; } if (profCart == null) { profCart = new ProfileCart(shippingAddressId, cartItem.DeliveryDate); CurrentProfileCarts.Add(profCart); } profCart.CartItems.Add(cartItem); //} //else //{ // //cartItem.Delete(); // //lblFeedbackCart.Text = "Item(s) removed from cart due to expiration of availability."; //} } } //// display totals CurrentCart.CalculateTotals(CurrentProfileCarts); } catch (Exception ex) { BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise("Attempt to recalculate taz for cart items failed.", this, ex); } } } return("Cart Updated: " + DateTime.Now); } catch (Exception ex) { throw ex; } }
public static List <PackingSlip> GeneratePackingSlips(DateTime deliveryDate) { List <PackingSlip> outSlips = new List <PackingSlip>(); List <AggrCartItem> agItems = hccCartItem.Search(null, null, null, deliveryDate, true, false); foreach (AggrCartItem agItem in agItems) { hccCart cart = hccCart.GetBy(agItem.CartItem.OrderNumber); if (cart != null && (cart.Status == Enums.CartStatus.Paid || cart.Status == Enums.CartStatus.Fulfilled)) { PackingSlip existItem = outSlips.SingleOrDefault(a => a.OrderNumber == agItem.CartItem.OrderNumber); if (existItem == null) { PackingSlip ps = new PackingSlip { OrderNumber = agItem.CartItem.OrderNumber, DeliveryDay = agItem.DeliveryDate.DayOfWeek.ToString(), DeliveryDate = agItem.DeliveryDate.ToShortDateString() }; //if (agItem.CartItem.UserProfile.ParentProfileID.HasValue) // ps.SpecialInstructions = hccUserProfileNote.GetBy(agItem.CartItem.UserProfile.ParentProfileID.Value, Enums.UserProfileNoteTypes.ShippingNote, null) // .Select(a => a.Note).DefaultIfEmpty(string.Empty).Aggregate((b, c) => b + ", " + c); string n1 = hccUserProfileNote.GetBy(agItem.CartItem.UserProfile.UserProfileID, Enums.UserProfileNoteTypes.ShippingNote, null) .Select(a => a.Note).DefaultIfEmpty(string.Empty).Aggregate((b, c) => b + ", " + c); if (!string.IsNullOrWhiteSpace(n1)) { if (!string.IsNullOrWhiteSpace(ps.SpecialInstructions)) { ps.SpecialInstructions += ", " + n1; } else { ps.SpecialInstructions += n1; } } if (agItem.CartSnap != null) { ps.LastName = agItem.CartSnap.LastName; ps.FirstName = agItem.CartSnap.FirstName; ps.OrderProfile = agItem.CartSnap.ProfileName; ps.Customer = ps.LastName + ", " + ps.FirstName; } else { ps.LastName = agItem.CartItem.UserProfile.ParentProfileName; ps.Customer = ps.LastName; ps.OrderProfile = agItem.CartItem.UserProfile.ProfileName; } if (agItem.CartItem != null) { if (agItem.CartItem.Plan_IsAutoRenew == true && agItem.CartItem.ItemTypeID == 1) { ps.IsFamily = "Yes"; } else if (agItem.CartItem.Plan_IsAutoRenew == false && agItem.CartItem.ItemTypeID == 1) { ps.IsFamily = "No"; } else { ps.IsFamily = "N/A"; } } if (agItem.CartItem.SnapShipAddrId.HasValue) { hccAddress shipAddr = hccAddress.GetById(agItem.CartItem.SnapShipAddrId.Value); ps.DeliveryAddress = shipAddr.ToString(); ps.DeliveryAddress += shipAddr.IsBusiness ? "<b>Business Address</b>" : "<b>Residential Address</b>"; ps.DeliveryMethod = Enums.GetEnumDescription(((Enums.DeliveryTypes)shipAddr.DefaultShippingTypeID)); } if (agItem.CartItem.ItemType == Enums.CartItemType.DefinedPlan) { hccProductionCalendar pc = hccProductionCalendar.GetBy(agItem.DeliveryDate); hccProgramPlan pg = hccProgramPlan.GetById(agItem.CartItem.Plan_PlanID.Value); int defMenuCount = hccProgramDefaultMenu.GetBy(pc.CalendarID, pg.ProgramID) .Where(a => a.MenuItemID > 0 && a.DayNumber <= pg.NumDaysPerWeek).Count(); ps.ItemsCount += agItem.TotalQuantity * defMenuCount; } else { ps.ItemsCount += agItem.TotalQuantity; } // NEW ASSUMPTION: No packing sheet should be printed if no cart items exist. if (ps.ItemsCount > 0) { outSlips.Add(ps); } } else { if (agItem.CartItem.ItemType == Enums.CartItemType.DefinedPlan) { hccProductionCalendar pc = hccProductionCalendar.GetBy(agItem.DeliveryDate); hccProgramPlan pg = hccProgramPlan.GetById(agItem.CartItem.Plan_PlanID.Value); int defMenuCount = hccProgramDefaultMenu.GetBy(pc.CalendarID, pg.ProgramID) .Where(a => a.MenuItemID > 0 && a.DayNumber <= pg.NumDaysPerWeek).Count(); existItem.ItemsCount += agItem.TotalQuantity * defMenuCount; } else { existItem.ItemsCount += agItem.TotalQuantity; } } } } return(outSlips.OrderBy(a => a.LastName).ThenBy(a => a.FirstName).ThenBy(a => a.OrderNumber).ToList()); }
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 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; } }
private void ProcessNewOrder(int cartId) { //bool dupTransaction = false; hccCart CurrentCart = null; try { // TODO: Check the cart for more then one recurring item CurrentCart = hccCart.GetById(cartId); hccUserProfile profile = hccUserProfile.GetParentProfileBy(CurrentCart.AspNetUserID.Value); hccAddress billAddr = null; var ppName = hccUserProfile.GetParentProfileBy((Guid)hccCart.GetById(cartId).AspNetUserID).ParentProfileName; var pName = hccUserProfile.GetParentProfileBy((Guid)hccCart.GetById(cartId).AspNetUserID).ASPUser.Email; //if (CurrentCart.StatusID == (int)Enums.CartStatus.Unfinalized) if (CurrentCart.StatusID == (int)Enums.CartStatus.Unfinalized) { if (profile != null) { AuthNetConfig ANConfig = new AuthNetConfig(); hccUserProfilePaymentProfile activePaymentProfile = profile.ActivePaymentProfile; bool isDuplicateTransaction = false; bool isAuthNet = false; if (ANConfig.Settings.TestMode) { CurrentCart.IsTestOrder = true; } // Check for existing account balance, calculate total balance if (CurrentCart.PaymentDue > 0.00m) { try { // if total balance remains CustomerInformationManager cim = new CustomerInformationManager(); if (activePaymentProfile != null) { // do not validate, per Duncan, YouTrack HC1-339 //string valProfile = cim.ValidateProfile(profile.AuthNetProfileID, // activePaymentProfile.AuthNetPaymentProfileID, AuthorizeNet.ValidationMode.TestMode); AuthorizeNet.Order order = new AuthorizeNet.Order(profile.AuthNetProfileID, activePaymentProfile.AuthNetPaymentProfileID, null); // charge CIM account with PaymentDue balance order.Amount = CurrentCart.PaymentDue; order.InvoiceNumber = CurrentCart.PurchaseNumber.ToString(); order.Description = "Healthy Chef Creations Purchase #" + CurrentCart.PurchaseNumber.ToString(); // Add a PO number to make purchases unique as subsequent transactions with the same amount are rejected by Auth.net as duplicate // order.PONumber = "PO" + CurrentCart.PurchaseNumber.ToString(); AuthorizeNet.IGatewayResponse rsp = cim.AuthorizeAndCapture(order); try { CurrentCart.AuthNetResponse = rsp.ResponseCode + "|" + rsp.Approved.ToString() + "|" + rsp.AuthorizationCode + "|" + rsp.InvoiceNumber + "|" + rsp.Message + "|" + rsp.TransactionID + "|" + rsp.Amount.ToString() + "|" + rsp.CardNumber; } catch (Exception) { } if (rsp.ResponseCode.StartsWith("1")) { CurrentCart.ModifiedBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.ModifiedDate = DateTime.Now; CurrentCart.PurchaseBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.PurchaseDate = DateTime.Now; CurrentCart.PaymentProfileID = activePaymentProfile.PaymentProfileID; CurrentCart.StatusID = (int)Enums.CartStatus.Paid; isAuthNet = true; } else if (rsp.Message.Contains("E00027")) // Duplicate transaction { order = new AuthorizeNet.Order(profile.AuthNetProfileID, activePaymentProfile.AuthNetPaymentProfileID, null) { Amount = CurrentCart.PaymentDue - .01m, // Subtract a penny from payment to make the value distinct InvoiceNumber = CurrentCart.PurchaseNumber.ToString(), Description = "Healthy Chef Creations Purchase #" + CurrentCart.PurchaseNumber.ToString() }; // charge CIM account with PaymentDue balance rsp = cim.AuthorizeAndCapture(order); try { CurrentCart.AuthNetResponse = rsp.ResponseCode + "|" + rsp.Approved.ToString() + "|" + rsp.AuthorizationCode + "|" + rsp.InvoiceNumber + "|" + rsp.Message + "|" + rsp.TransactionID + "|" + rsp.Amount.ToString() + "|" + rsp.CardNumber; if (rsp.ResponseCode.StartsWith("1")) { //CurrentCart.PaymentDue = CurrentCart.PaymentDue - .01m; CurrentCart.ModifiedBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.ModifiedDate = DateTime.Now; CurrentCart.PurchaseBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.PurchaseDate = DateTime.Now; CurrentCart.PaymentProfileID = activePaymentProfile.PaymentProfileID; CurrentCart.StatusID = (int)Enums.CartStatus.Paid; isAuthNet = true; } else { lblConfirmFeedback.Text += "Authorize.Net " + rsp.Message + @" (" + ppName + @", " + pName + @")" + @"<br />"; // CurrentCart.AuthNetResponse; lblConfirmFeedback.ForeColor = System.Drawing.Color.Red; } } catch (Exception) { } } else { lblConfirmFeedback.Text += "Authorize.Net " + rsp.Message + @" (" + ppName + @", " + pName + @")" + @"<br />"; // CurrentCart.AuthNetResponse; lblConfirmFeedback.ForeColor = System.Drawing.Color.Red; } CurrentCart.Save(); } else { lblConfirmFeedback.Text += "No payment profile found." + @" (" + ppName + @", " + pName + @")" + @"<br />"; } } catch (Exception ex) { lblConfirmFeedback.Text += "Authorize.Net " + ex.Message + @" (" + ppName + @", " + pName + @")" + @"<br />"; lblConfirmFeedback.ForeColor = System.Drawing.Color.Red; if (ex is InvalidOperationException) { if (CurrentCart.IsTestOrder) { CurrentCart.ModifiedBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.ModifiedDate = DateTime.Now; CurrentCart.PaymentProfileID = activePaymentProfile.PaymentProfileID; CurrentCart.AuthNetResponse = ex.Message; CurrentCart.StatusID = (int)Enums.CartStatus.Unfinalized; CurrentCart.Save(); } else { BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise(ex.Message, this, ex); lblConfirmFeedback.Visible = true; lblConfirmFeedback.Text += "Authorize.Net " + ex.Message + @" (" + ppName + @", " + pName + @")" + @"<br />"; lblConfirmFeedback.ForeColor = System.Drawing.Color.Red; } } else { throw; } } } else { // no balance left to pay on order, set as paid CurrentCart.AuthNetResponse = "Paid with account balance."; CurrentCart.ModifiedBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.ModifiedDate = DateTime.Now; CurrentCart.PurchaseBy = (Guid)Helpers.LoggedUser.ProviderUserKey; CurrentCart.PurchaseDate = DateTime.Now; CurrentCart.StatusID = (int)Enums.CartStatus.Paid; CurrentCart.Save(); } if ((Enums.CartStatus)CurrentCart.StatusID == Enums.CartStatus.Paid) //&& !isDuplicateTransaction { hccLedger ledger = new hccLedger { //PaymentDue = dupTransaction ? CurrentCart.PaymentDue : CurrentCart.PaymentDue - .01m, //TotalAmount = dupTransaction ? CurrentCart.TotalAmount : CurrentCart.TotalAmount - .01m, PaymentDue = CurrentCart.PaymentDue, TotalAmount = CurrentCart.TotalAmount, AspNetUserID = CurrentCart.AspNetUserID.Value, AsscCartID = CurrentCart.CartID, CreatedBy = (Guid)Helpers.LoggedUser.ProviderUserKey, CreatedDate = DateTime.Now, Description = "Cart Order Payment - Purchase Number: " + CurrentCart.PurchaseNumber.ToString(), TransactionTypeID = (int)Enums.LedgerTransactionType.Purchase }; if (CurrentCart.IsTestOrder) { ledger.Description += " - Test Mode"; } if (CurrentCart.CreditAppliedToBalance > 0) { profile.AccountBalance = profile.AccountBalance - CurrentCart.CreditAppliedToBalance; ledger.CreditFromBalance = CurrentCart.CreditAppliedToBalance; } hccLedger lastLedger = hccLedger.GetByMembershipID(profile.MembershipID, null) .OrderByDescending(a => a.CreatedDate) .FirstOrDefault(); bool isDuplicateLedger = false; if (lastLedger != null) { if (ledger.CreatedBy == lastLedger.CreatedBy && ledger.CreditFromBalance == lastLedger.CreditFromBalance && ledger.Description == lastLedger.Description && ledger.PaymentDue == lastLedger.PaymentDue && ledger.TransactionTypeID == lastLedger.TransactionTypeID && ledger.TotalAmount == lastLedger.TotalAmount) { isDuplicateLedger = true; } } if (!isDuplicateLedger) { ledger.PostBalance = profile.AccountBalance; ledger.Save(); profile.Save(); // create snapshot here hccCartSnapshot snap = new hccCartSnapshot { CartId = cartId, MembershipId = profile.MembershipID, LedgerId = ledger.LedgerID, AccountBalance = profile.AccountBalance, AuthNetProfileId = profile.AuthNetProfileID, CreatedBy = (Guid)Helpers.LoggedUser.ProviderUserKey, CreatedDate = DateTime.Now, DefaultCouponId = profile.DefaultCouponId, Email = profile.ASPUser.Email, FirstName = profile.FirstName, LastName = profile.LastName, ProfileName = profile.ProfileName, AuthNetPaymentProfileId = (isAuthNet == true ? activePaymentProfile.AuthNetPaymentProfileID : string.Empty), CardTypeId = (isAuthNet == true ? activePaymentProfile.CardTypeID : 0), CCLast4 = (isAuthNet == true ? activePaymentProfile.CCLast4 : string.Empty), ExpMon = (isAuthNet == true ? activePaymentProfile.ExpMon : 0), ExpYear = (isAuthNet == true ? activePaymentProfile.ExpYear : 0), NameOnCard = (isAuthNet == true ? activePaymentProfile.NameOnCard : string.Empty) }; snap.Save(); hccUserProfile parentProfile = hccUserProfile.GetParentProfileBy(CurrentCart.AspNetUserID.Value); if (parentProfile.BillingAddressID.HasValue) { billAddr = hccAddress.GetById(parentProfile.BillingAddressID.Value); } hccAddress snapBillAddr = new hccAddress { Address1 = billAddr.Address1, Address2 = billAddr.Address2, AddressTypeID = (int)Enums.AddressType.BillingSnap, City = billAddr.City, Country = billAddr.Country, DefaultShippingTypeID = billAddr.DefaultShippingTypeID, FirstName = billAddr.FirstName, IsBusiness = billAddr.IsBusiness, LastName = billAddr.LastName, Phone = billAddr.Phone, PostalCode = billAddr.PostalCode, State = billAddr.State, ProfileName = parentProfile.ProfileName }; snapBillAddr.Save(); // copy and replace of all addresses for snapshot List <hccCartItem> cartItems = hccCartItem.GetBy(CurrentCart.CartID); cartItems.ToList().ForEach(delegate(hccCartItem ci) { hccAddress shipAddr = null; if (ci.UserProfile.ShippingAddressID.HasValue) { shipAddr = hccAddress.GetById(ci.UserProfile.ShippingAddressID.Value); } if (shipAddr != null) { hccAddress snapShipAddr = new hccAddress { Address1 = shipAddr.Address1, Address2 = shipAddr.Address2, AddressTypeID = (int)Enums.AddressType.ShippingSnap, City = shipAddr.City, Country = shipAddr.Country, DefaultShippingTypeID = shipAddr.DefaultShippingTypeID, FirstName = shipAddr.FirstName, IsBusiness = shipAddr.IsBusiness, LastName = shipAddr.LastName, Phone = shipAddr.Phone, PostalCode = shipAddr.PostalCode, State = shipAddr.State, ProfileName = ci.UserProfile.ProfileName }; snapShipAddr.Save(); ci.SnapShipAddrId = snapShipAddr.AddressID; } ci.SnapBillAddrId = snapBillAddr.AddressID; ci.Save(); }); try { Email.EmailController ec = new Email.EmailController(); ec.SendMail_OrderConfirmationMerchant(profile.FirstName + " " + profile.LastName, CurrentCart.ToHtml(), cartId); ec.SendMail_OrderConfirmationCustomer(profile.ASPUser.Email, profile.FirstName + " " + profile.LastName, CurrentCart.ToHtml()); } catch (Exception ex) { BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise("Send Mail Failed", this, ex); } //throw; } //if (IsForPublic) //{ // Response.Redirect(string.Format("~/cart/order-confirmation.aspx?pn={0}&tl={1}&tx={2}&ts={3}&ct={4}&st={5}&cy={6}", // CurrentCart.PurchaseNumber, CurrentCart.TotalAmount, CurrentCart.TaxableAmount, CurrentCart.ShippingAmount, // billAddr.City, billAddr.State, billAddr.Country), false); //} //else //{ // CurrentCart = hccCart.GetCurrentCart(profile.ASPUser); // CurrentCartId = CurrentCart.CartID; // pnlCartDisplay.Visible = true; // pnlConfirm.Visible = false; // Clear(); // Bind(); //} //OnCartSaved(new CartEventArgs(CurrentCartId)); } } //else //{ // BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise("Duplicate transaction attempted: " + CurrentCart.PurchaseNumber.ToString(), this, new Exception("Duplicate transaction attempted by:" + Helpers.LoggedUser.UserName)); //} } else { Response.Redirect("~/login.aspx", true); } } //else //{ //if (IsForPublic) //{ // //Response.Redirect("~/cart/order-confirmation.aspx?cid=" + CurrentCartId.ToString(), false); // Response.Redirect(string.Format("~/cart/order-confirmation.aspx?pn={0}&tl={1}&tx={2}&ts={3}&ct={4}&st={5}&cy={6}", // CurrentCart.PurchaseNumber, CurrentCart.TotalAmount, CurrentCart.TaxableAmount, CurrentCart.ShippingAmount, // billAddr.City, billAddr.State, billAddr.Country), false); //} //else //{ // CurrentCart = hccCart.GetCurrentCart(profile.ASPUser); // CurrentCartId = CurrentCart.CartID; // pnlCartDisplay.Visible = true; // pnlConfirm.Visible = false; // Clear(); // Bind(); // OnCartSaved(new CartEventArgs(CurrentCartId)); //} //} } catch (Exception ex) { BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise(ex.Data + " " + ex.InnerException, this, new Exception("Recurring order error in method ProcessNewOrder: " + Helpers.LoggedUser.UserName)); } }
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(); } } }
void BindGvwOrderNumbers() { try { CurrentPurchaseNumber = int.Parse(txtPurchaseNumber.Text.Trim()); hccCart cart = hccCart.GetBy(CurrentPurchaseNumber); if (cart != null) { if (cart.Status == Common.Enums.CartStatus.Paid) { btnCancelPurchase.Visible = true; //btnCancelPurchase.Text = "Cancel Entire Purchase"; btnCancelPurchase.Text = "Void Transaction"; } else if (cart.Status == Common.Enums.CartStatus.Cancelled) { CurrentPurchaseNumberIsCancelled = true; if (cart.PurchaseDate.HasValue) { btnCancelPurchase.Visible = true; btnCancelPurchase.Text = "Un-Cancel"; } } lblPurchaseStatus.Text = string.Format("Purchase #{0} - Customer: {1} - Status: {2}", cart.PurchaseNumber, cart.OwnerProfile == null ? "Anonymous" : cart.OwnerProfile.FullName, cart.Status); lblOrdNumsLegend.Text = "Order Numbers for Purchase #: " + cart.PurchaseNumber; pnlPurchase.Visible = true; List <hccCartItem> items = hccCartItem.GetBy(cart.CartID); List <string> ordNums = items.Select(a => a.OrderNumber).Distinct().ToList(); List <Tuple <string, int, bool> > orders = new List <Tuple <string, int, bool> >(); // orderNum, itemCnt, isCancelled ordNums.ForEach(delegate(string ordNum) { int cnt = items.Count(a => a.OrderNumber == ordNum); int cntNotCancelled = items.Count(a => a.OrderNumber == ordNum && !a.IsCancelled); orders.Add(new Tuple <string, int, bool>(ordNum, cnt, (cntNotCancelled == 0))); }); //gvwOrderNumbers.DataSource = orders; //gvwOrderNumbers.DataBind(); //gvwOrderNumbers.Visible = true; } else { pnlPurchase.Visible = false; lblFeedback.Text = "Purchase not found."; } } catch (Exception) { throw; } }