//static healthychefEntities cont //{ // get { return healthychefEntities.Default; } //} public void Save() { try { using (var cont = new healthychefEntities()) { System.Data.EntityKey key = cont.CreateEntityKey("hccMenuItemIngredients", this); object oldObj; if (cont.TryGetObjectByKey(key, out oldObj)) { cont.ApplyCurrentValues("hccMenuItemIngredients", this); } else { cont.hccMenuItemIngredients.AddObject(this); } cont.SaveChanges(); } } catch (Exception) { throw; } }
public void Delete() { try { using (var cont = new healthychefEntities()) { System.Data.EntityKey key = cont.CreateEntityKey("hccProgramDefaultMenuExPrefs", this); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { List <hccProgramDefaultMenuExPref> items = cont.hccProgramDefaultMenuExPrefs .Where(a => a.DefaultMenuId == this.DefaultMenuId).ToList(); if (items.Count > 0) { foreach (var item in items) { cont.hccProgramDefaultMenuExPrefs.DeleteObject(item); cont.SaveChanges(); } } } } } catch (Exception) { throw; } }
//static healthychefEntities cont //{ // get { return healthychefEntities.Default; } //} public void Save() { try { using (var cont = new healthychefEntities()) { System.Data.EntityKey key = cont.CreateEntityKey("hccProgramDefaultMenus", this); object oldObj; if (cont.TryGetObjectByKey(key, out oldObj)) { cont.ApplyCurrentValues("hccProgramDefaultMenus", this); } else { cont.hccProgramDefaultMenus.AddObject(this); } cont.SaveChanges(); //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, this); } } catch { throw; } }
//static healthychefEntities cont //{ // get { return healthychefEntities.Default; } //} public void Save() { try { using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey("hccMenuItemPreferences", this); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.ApplyCurrentValues(key.EntitySetName, this); } else { cont.hccMenuItemPreferences.AddObject(this); } cont.SaveChanges(); } } catch (Exception) { throw; } }
//static healthychefEntities cont //{ // get { return healthychefEntities.Default; } //} public void Save() { try { using (var cont = new healthychefEntities()) { System.Data.EntityKey key = cont.CreateEntityKey("hccCartDefaultMenuExPrefs", this); object oldObj; if (cont.TryGetObjectByKey(key, out oldObj)) { cont.ApplyCurrentValues("hccCartDefaultMenuExPrefs", this); } else { cont.hccCartDefaultMenuExPrefs.AddObject(this); } cont.SaveChanges(); } } catch { throw; } }
//static healthychefEntities cont //{ // get // { // if (System.Web.HttpContext.Current != null) // return healthychefEntities.Default; // else // return new healthychefEntities(WebConfigurationManager.ConnectionStrings["healthychefEntities"].ConnectionString); // } //} /// <summary> /// Saves this user to the database. If this user hasn't been created yet /// this user will be added to the database. /// </summary> public void Save() { try { using (var cont = new healthychefEntities(WebConfigurationManager.ConnectionStrings["healthychefEntities"].ConnectionString)) { System.Data.EntityKey key = cont.CreateEntityKey("hccUserProfiles", this); object oldObj; if (cont.TryGetObjectByKey(key, out oldObj)) { cont.ApplyCurrentValues("hccUserProfiles", this); } else { cont.hccUserProfiles.AddObject(this); } cont.SaveChanges(); //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, this); } } catch { throw; } }
public void Delete() { try { using (var cont = new healthychefEntities()) { System.Data.EntityKey key = cont.CreateEntityKey("hccCartDefaultMenuExPrefs", this); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { hccCartDefaultMenuExPref item = cont.hccCartDefaultMenuExPrefs .Where(a => a.MenuExPrefID == this.MenuExPrefID).SingleOrDefault(); if (item != null) { cont.hccCartDefaultMenuExPrefs.DeleteObject(item); cont.SaveChanges(); } } } } catch (Exception) { throw; } }
protected void btnDeleteOnCommand(object sender, CommandEventArgs e) { using (var hcE = new healthychefEntities()) { var cartId = int.Parse(e.CommandArgument.ToString().Split('_')[0]); var cartItemId = int.Parse(e.CommandArgument.ToString().Split('_')[1]); var rOrder = hcE.hccRecurringOrders.FirstOrDefault(i => i.CartID == cartId && i.CartItemID == cartItemId); hcE.hccRecurringOrders.DeleteObject(rOrder); hcE.SaveChanges(); //lvAllRecurringOrders.DataSource = hcE.hcc_RecurringOrderByDeliveryDate().ToList(); //lvAllRecurringOrders.DataBind(); } }
//static healthychefEntities cont //{ // get { return healthychefEntities.Default; } //} public int Save() { try { using (var cont = new healthychefEntities()) { System.Data.EntityKey key = cont.CreateEntityKey("hccProductionCalendars", this); object oldObj; if (cont.TryGetObjectByKey(key, out oldObj)) { cont.ApplyCurrentValues("hccProductionCalendars", this); } else { cont.hccProductionCalendars.AddObject(this); } cont.SaveChanges(); return(this.CalendarID); } } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException is SqlException) { try { if (ex.InnerException.Message.Contains("Cannot insert duplicate key row")) { return(GetBy(this.DeliveryDate).CalendarID); } else { throw; } } catch (Exception) { throw; } } else { throw ex; } } }
protected void btnDeleteOnCommand(object sender, CommandEventArgs e) { using (var hcE = new healthychefEntities()) { var cartId = int.Parse(e.CommandArgument.ToString().Split('_')[0]); var cartItemId = int.Parse(e.CommandArgument.ToString().Split('_')[1]); var rOrder = hcE.hccRecurringOrders.FirstOrDefault(i => i.CartID == cartId && i.CartItemID == cartItemId); hcE.hccRecurringOrders.DeleteObject(rOrder); hcE.SaveChanges(); Page_PreInit(sender, e); } }
public void RemoveItems() { try { using (var cont = new healthychefEntities()) { var t = cont.hccMenus.SingleOrDefault(a => a.MenuID == this.MenuID); List <hccMenuItem> items = t.hccMenuItems.ToList(); items.ForEach(a => t.hccMenuItems.Remove(a)); cont.SaveChanges(); } } catch { throw; } }
public void Delete() { try { using (var cont = new healthychefEntities()) { System.Data.EntityKey key = cont.CreateEntityKey("hccProgramDefaultMenus", this); object oldObj; if (cont.TryGetObjectByKey(key, out oldObj)) { cont.hccProgramDefaultMenus.DeleteObject((hccProgramDefaultMenu)oldObj); } cont.SaveChanges(); } } catch { throw; } }
public static void DeleteByCartId(int CartId) { try { using (var cont = new healthychefEntities()) { hccRecurringOrder item = cont.hccRecurringOrders .Where(a => a.CartID == CartId).SingleOrDefault(); if (item != null) { cont.hccRecurringOrders.DeleteObject(item); cont.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public void AddItems(List <hccMenuItem> addItems) { try { using (var cont = new healthychefEntities()) { var t = cont.hccMenus.SingleOrDefault(a => a.MenuID == this.MenuID); addItems.ForEach(delegate(hccMenuItem addItem) { cont.AttachTo("hccMenuItems", addItem); t.hccMenuItems.Add(addItem); }); cont.SaveChanges(); } } catch { throw; } }
public void Delete() { try { using (var cont = new healthychefEntities()) { var d = cont.hccCartItemMealPreferences .SingleOrDefault(a => a.CartItemID == this.CartItemID && a.PreferenceID == this.PreferenceID); if (d != null) { cont.hccCartItemMealPreferences.DeleteObject(d); cont.SaveChanges(); } } } catch (Exception) { throw; } }
public void Delete() { try { using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey(this.EntityKey.EntitySetName, this); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.hccMenuItemIngredients.DeleteObject((hccMenuItemIngredient)originalItem); cont.SaveChanges(); } } } catch (Exception) { throw; } }
public void Delete() { try { using (var cont = new healthychefEntities()) { hccIngredientAllergen t = cont.hccIngredientAllergens .Where(a => a.AllergenID == this.AllergenID && a.IngredientID == this.IngredientID) .SingleOrDefault(); if (t != null) { cont.hccIngredientAllergens.DeleteObject(t); cont.SaveChanges(); } } } catch (Exception) { throw; } }
public void Delete() { try { using (var cont = new healthychefEntities()) { hccUserProfilePreference t = cont.hccUserProfilePreferences .Where(a => a.PreferenceID == this.PreferenceID && a.UserProfileID == this.UserProfileID) .SingleOrDefault(); if (t != null) { cont.hccUserProfilePreferences.DeleteObject(t); cont.SaveChanges(); } } } catch (Exception) { throw; } }
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 } }
public void Delete() { try { using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey(this.EntityKey.EntitySetName, this); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.hccMenuItemPreferences.DeleteObject((hccMenuItemPreference)originalItem); cont.SaveChanges(); //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, cont.hccMenuItemPreferences); } } } catch (Exception) { throw; } }
/// <summary> /// Deletes alc menu item of cart from the database. /// </summary> /// <exception cref="System.Exception">re-thrown exception</exception> /// <returns>Returns void.</returns> public void Delete() { try { using (var cont = new healthychefEntities()) { var key = cont.CreateEntityKey("hccCartALCMenuItems", this); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { var cartItem = (hccCartALCMenuItem)originalItem; cont.hccCartALCMenuItems.DeleteObject(cartItem); cont.SaveChanges(); } } } catch (Exception) { throw; } }
public static void Import(out int count) { using (StreamWriter writer = new StreamWriter(@"C:\HCCCustomerOutput.txt")) { Console.SetOut(writer); count = 0; List <string> errorReport = new List <string>(); try { List <ImportedCustomer> impCusts = GetAll(); foreach (ImportedCustomer impCust in impCusts) { Console.WriteLine(count + " : "); if (!impCust.IsValid) { impCust.Email = "admin" + count.ToString() + "@healthychefcreations.com"; } else if (impCust.Email.Contains("info@healthychef") || impCust.Email.Contains("thehealthyassistant@earthlink")) { impCust.Email = "admin" + count.ToString() + "@healthychefcreations.com"; } Console.WriteLine(impCust.Email); if (impCust.IsValid) { count++; string userName = impCust.Email.Trim().Split('@')[0] + DateTime.Now.ToString("yyyyMMddHHmmtt"); string password = OrderNumberGenerator.GenerateOrderNumber("?#?#?#?#"); string aspUserName = Membership.GetUserNameByEmail(impCust.Email.Trim()); MembershipUser newUser = null; if (!string.IsNullOrWhiteSpace(aspUserName)) { newUser = Membership.GetUser(aspUserName); } MembershipCreateStatus createResult = MembershipCreateStatus.UserRejected; if (newUser == null) { newUser = Membership.CreateUser(userName, password, impCust.Email.Trim(), "import", "import", true, out createResult); if (newUser != null) { Console.WriteLine(newUser.UserName + "New user."); } } else { Console.WriteLine(newUser.UserName + " Existing user."); createResult = MembershipCreateStatus.Success; } if (newUser != null) { if (createResult == MembershipCreateStatus.Success) { //Assign Customer role to newUser try { if (!Roles.IsUserInRole(newUser.UserName, "Customer")) { Roles.AddUserToRole(newUser.UserName, "Customer"); Console.WriteLine(newUser.UserName + " Role assigned."); } } catch (Exception ex) { Console.WriteLine(newUser.UserName + " =Assign role failed." + ex.Message + ex.StackTrace); } //Send E-mail notification to account user //HealthyChef.Email.EmailController ec = new HealthyChef.Email.EmailController(); //ec.SendMail_NewUserConfirmation(email, password); //Create a Healthy Chef profile for this new user hccUserProfile newProfile = hccUserProfile.GetBy((Guid)newUser.ProviderUserKey).SingleOrDefault(a => !a.ParentProfileID.HasValue); if (newProfile == null) { try { newProfile = new hccUserProfile { MembershipID = (Guid)newUser.ProviderUserKey, CreatedBy = (Membership.GetUser() == null ? Guid.Empty : (Guid)Membership.GetUser().ProviderUserKey), CreatedDate = DateTime.Now, AccountBalance = 0.00m, IsActive = true, FirstName = impCust.FirstName.Trim(), LastName = impCust.LastName.Trim(), ProfileName = impCust.FirstName.Trim() }; //Save all hccProfile information using (var cont = new healthychefEntities()) { System.Data.EntityKey key = cont.CreateEntityKey("hccUserProfiles", newProfile); object oldObj; if (cont.TryGetObjectByKey(key, out oldObj)) { cont.ApplyCurrentValues("hccUserProfiles", newProfile); } else { cont.hccUserProfiles.AddObject(newProfile); } cont.SaveChanges(); } //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, newProfile); Console.WriteLine(newUser.UserName + " New profile."); } catch (Exception) { Console.WriteLine("=" + newUser.UserName + " Save Profile failed."); } } else { Console.WriteLine(newUser.UserName + " Existing profile."); createResult = MembershipCreateStatus.Success; } if (newProfile != null && newProfile.UserProfileID > 0) { if (impCust.OtherDeliveryInfo != null && !string.IsNullOrWhiteSpace(impCust.OtherDeliveryInfo)) { hccUserProfileNote shipNote = new hccUserProfileNote { DateCreated = DateTime.Now, DisplayToUser = false, UserProfileID = newProfile.UserProfileID, IsActive = true, Note = impCust.OtherDeliveryInfo, NoteTypeID = (int)Enums.UserProfileNoteTypes.ShippingNote }; using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey("hccUserProfileNotes", shipNote); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.ApplyCurrentValues(key.EntitySetName, shipNote); } else { cont.hccUserProfileNotes.AddObject(shipNote); } cont.SaveChanges(); } } if (impCust.HowDidYouHear != null && !string.IsNullOrWhiteSpace(impCust.HowDidYouHear)) { hccUserProfileNote hearNote = new hccUserProfileNote { DateCreated = DateTime.Now, DisplayToUser = false, UserProfileID = newProfile.UserProfileID, IsActive = true, Note = impCust.HowDidYouHear, NoteTypeID = (int)Enums.UserProfileNoteTypes.GeneralNote }; using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey("hccUserProfileNotes", hearNote); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.ApplyCurrentValues(key.EntitySetName, hearNote); } else { cont.hccUserProfileNotes.AddObject(hearNote); } cont.SaveChanges(); } } try { //save Shipping Address hccAddress shipAddr = null; if (newProfile.ShippingAddressID.HasValue) { shipAddr = hccAddress.GetById(newProfile.ShippingAddressID.Value); } if (shipAddr != null) { try { newProfile.ShippingAddressID = null; //Save all hccProfile information using (var cont = new healthychefEntities()) { System.Data.EntityKey key1 = cont.CreateEntityKey("hccUserProfiles", newProfile); object oldObj1; if (cont.TryGetObjectByKey(key1, out oldObj1)) { cont.ApplyCurrentValues("hccUserProfiles", newProfile); } else { cont.hccUserProfiles.AddObject(newProfile); } cont.SaveChanges(); } //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, newProfile); using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey("hccAddresses", shipAddr); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.AttachTo(shipAddr.EntityKey.EntitySetName, shipAddr); cont.DeleteObject(shipAddr); } cont.SaveChanges(); } shipAddr = null; } catch (Exception ex) { Console.WriteLine(newUser.UserName + " =Delete old shipping address failed." + ex.Message + ex.StackTrace); } } if (shipAddr == null) { shipAddr = new hccAddress(); } if (impCust.ShippingAddress1 != null) { shipAddr.Address1 = (string.IsNullOrWhiteSpace(impCust.ShippingAddress1) ? "" : impCust.ShippingAddress1.Trim()); } else { shipAddr.Address1 = ""; } if (impCust.ShippingAddress2 != null) { shipAddr.Address2 = (string.IsNullOrWhiteSpace(impCust.ShippingAddress2) ? "" : impCust.ShippingAddress2.Trim()); } else { shipAddr.Address2 = ""; } if (impCust.ShippingAddress3 != null) { shipAddr.Address2 += " " + (string.IsNullOrWhiteSpace(impCust.ShippingAddress3) ? "" : impCust.ShippingAddress3.Trim()); } shipAddr.AddressTypeID = (int)Enums.AddressType.Shipping; if (impCust.ShippingCity != null) { shipAddr.City = (string.IsNullOrWhiteSpace(impCust.ShippingCity) ? "" : impCust.ShippingCity.Trim()); } else { shipAddr.City = ""; } shipAddr.Country = "US"; if (impCust.FirstName != null) { shipAddr.FirstName = (string.IsNullOrWhiteSpace(impCust.FirstName) ? "" : impCust.FirstName.Trim()); } else { shipAddr.FirstName = ""; } shipAddr.IsBusiness = false; if (impCust.LastName != null) { shipAddr.LastName = (string.IsNullOrWhiteSpace(impCust.LastName) ? "" : impCust.LastName.Trim()); } else { shipAddr.LastName = ""; } if (impCust.Phone1 != null) { shipAddr.Phone = (string.IsNullOrWhiteSpace(impCust.Phone1) ? "" : impCust.Phone1.Trim()); } else { shipAddr.Phone = ""; } if (impCust.Phone1Ext != null) { shipAddr.Phone += (string.IsNullOrWhiteSpace(impCust.Phone1Ext.Trim()) ? "" : " x" + impCust.Phone1Ext.Trim()); } else { shipAddr.Phone = ""; } if (impCust.ShippingZipCode != null) { shipAddr.PostalCode = (string.IsNullOrWhiteSpace(impCust.ShippingZipCode) ? "" : impCust.ShippingZipCode.Trim()); } else { shipAddr.PostalCode = ""; } if (impCust.ShippingState != null) { shipAddr.State = (string.IsNullOrWhiteSpace(impCust.ShippingState) ? "" : impCust.ShippingState.Trim()); } else { shipAddr.State = ""; } if (impCust.ShipMethod == null) { shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.Delivery; } else if (impCust.ShipMethod.Trim() == "F") { shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.Delivery; } else if (impCust.ShipMethod.Trim() == "P") { shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.LocalPickUp; } else if (impCust.ShipMethod.Trim() == "D") { shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.LocalDelivery; } else { shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.Delivery; } if (shipAddr != null) { try { using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey("hccAddresses", shipAddr); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.hccAddresses.ApplyCurrentValues((hccAddress)originalItem); } else { cont.hccAddresses.AddObject(shipAddr); } cont.SaveChanges(); } //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, shipAddr); } catch (Exception ex) { Console.WriteLine(newUser.UserName + " =Shipping address save failed." + ex.Message + ex.StackTrace); } } if (shipAddr != null && shipAddr.AddressID > 0) { newProfile.ShippingAddressID = shipAddr.AddressID; } else { newProfile.ShippingAddressID = null; } using (var cont = new healthychefEntities()) { System.Data.EntityKey upkey = cont.CreateEntityKey("hccUserProfiles", newProfile); object oldObj; if (cont.TryGetObjectByKey(upkey, out oldObj)) { cont.ApplyCurrentValues("hccUserProfiles", newProfile); } else { cont.hccUserProfiles.AddObject(newProfile); } cont.SaveChanges(); } Console.WriteLine(newUser.UserName + " Shipping address saved."); } catch (Exception ex) { Console.WriteLine(newUser.UserName + " =Shipping address not created." + ex.Message + ex.StackTrace); } } else { Console.WriteLine("User Profile for user: "******" ID not created."); } } else { Console.WriteLine("=New user for user: "******" not created."); } } else { Console.WriteLine(createResult.ToString() + " : " + impCust.Email); } } else { count++; Console.WriteLine("=Customer: " + impCust.FirstName + " " + impCust.LastName + " has no email address."); } } } catch (Exception ex) { Console.WriteLine("=" + ex.Message + " : " + ex.StackTrace); } } }
/// <summary> /// Deletes the hccCartItem object. /// </summary> /// <exception cref="System.Exception">re-thrown exception</exception> /// <returns>Returns void.</returns> public void Delete(List <hccRecurringOrder> recurringItemList) { try { using (var cont = new healthychefEntities()) { System.Data.EntityKey key = cont.CreateEntityKey("hccCartItems", this); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { hccCartItem cartItem = (hccCartItem)originalItem; if (((Enums.CartItemType)cartItem.ItemTypeID) == Enums.CartItemType.AlaCarte) { List <hccCartItemMealPreference> prefs = hccCartItemMealPreference.GetBy(cartItem.CartItemID); prefs.ForEach(a => a.Delete()); } else if (((Enums.CartItemType)cartItem.ItemTypeID) == Enums.CartItemType.DefinedPlan) { List <hccCartItemMealPreference> prefs = hccCartItemMealPreference.GetBy(cartItem.CartItemID); prefs.ForEach(a => a.Delete()); List <hccCartItemCalendar> cartCals = hccCartItemCalendar.GetByCartItemID(cartItem.CartItemID); cartCals.ForEach(delegate(hccCartItemCalendar cartCal) { List <hccCartDefaultMenuException> menuExs = hccCartDefaultMenuException.GetBy(cartCal.CartCalendarID); foreach (var defaultmenu in menuExs) { int defaultmenexceptionid = defaultmenu.DefaultMenuExceptID; var cartDefaultMenuExPref = hccCartDefaultMenuExPref.GetBy(defaultmenexceptionid); if (cartDefaultMenuExPref.Count() > 0) { cartDefaultMenuExPref.ForEach(a => a.Delete()); } } menuExs.ForEach(a => a.Delete()); }); cartCals.ForEach(delegate(hccCartItemCalendar cartCal) { cartCal.Delete(); }); } if (HttpContext.Current.Session["id"] != null && HttpContext.Current.Session["meals"] != null) { cartItem.CartID = (int)HttpContext.Current.Session["id"]; cartItem.NumberOfMeals = (int)HttpContext.Current.Session["meals"]; } var hcccartMenuExPrefs = hccCartMenuExPref.GetByCartItem(cartItem.CartItemID); if (hcccartMenuExPrefs.Count() > 0) { hcccartMenuExPrefs.ForEach(a => a.Delete()); } cont.hccCartItems.DeleteObject(cartItem); cont.SaveChanges(); // Check for recurring items if (recurringItemList != null) { var itemDeleted = recurringItemList.Find(x => x.CartID == this.CartID && x.CartItemID == this.CartItemID); recurringItemList.Remove(itemDeleted); } } } } catch (Exception ex) { throw ex; } }