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); } } }
public MOTCartItem(hccCartItem cartItem) { try { if (cartItem.ItemType == Common.Enums.CartItemType.AlaCarte) { hccMenuItem mi = hccMenuItem.GetById(cartItem.Meal_MenuItemID.Value); MenuItem = mi; CartItem = cartItem; CartItemId = cartItem.CartItemID; OrderNumber = cartItem.OrderNumber + "-ALC"; DeliveryDate = cartItem.DeliveryDate; if (cartItem.UserProfile != null) { CustomerName = cartItem.UserProfile.ParentProfileName; ProfileName = cartItem.UserProfile.ProfileName; } ItemName = mi.Name; MealType = mi.MealType; if (cartItem.Meal_MealSizeID.HasValue) { Enums.CartItemSize size = (Enums.CartItemSize)cartItem.Meal_MealSizeID; if (size == Enums.CartItemSize.NoSize) { size = Enums.CartItemSize.RegularSize; } PortionSize = Enums.GetEnumDescription(size); } else { PortionSize = Enums.GetEnumDescription(Enums.CartItemSize.RegularSize); } Servings = cartItem.Quantity.ToString(); Preferences = hccCartItemMealPreference.GetPrefsBy(cartItem.CartItemID) .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d); Sides = "None"; if (hccMenuItem.EntreeMealTypes.Contains(MealType) && cartItem.MealSideMenuItems.Count > 0) { Sides = cartItem.GetMealSideMenuItemsAsSectionString(", "); } if (cartItem.SnapShipAddrId.HasValue) { hccAddress addr = hccAddress.GetById(cartItem.SnapShipAddrId.Value); DeliveryMethod = ((Enums.DeliveryTypes)addr.DefaultShippingTypeID).ToString(); } if (cartItem.Plan_IsAutoRenew == true) { FamilyStyle = "Yes"; } else if (cartItem.Plan_IsAutoRenew == false) { FamilyStyle = "No"; } } } catch (Exception) { throw; } }
public static List <MOTCartItem> GetFromCartCalendarForMOT(hccCartItemCalendar cartCal) { try { List <MOTCartItem> retMotItems = new List <MOTCartItem>(); List <MOTCartItem> addlMotItems = new List <MOTCartItem>(); hccCartItem cartItem = hccCartItem.GetById(cartCal.CartItemID); hccProductionCalendar prodCal = hccProductionCalendar.GetById(cartCal.CalendarID); hccProgramPlan plan = hccProgramPlan.GetById(cartItem.Plan_PlanID.Value); List <hccProgramDefaultMenu> defMenus = hccProgramDefaultMenu.GetBy(cartCal.CalendarID, plan.ProgramID, plan.NumDaysPerWeek); List <hccMenuItem> planMeals = new List <hccMenuItem>(); defMenus.ForEach(delegate(hccProgramDefaultMenu defMenu) { hccCartDefaultMenuException cartDefMenuEx = hccCartDefaultMenuException.GetBy(defMenu.DefaultMenuID, cartCal.CartCalendarID); hccMenuItem selItem; Enums.CartItemSize selPortionSize = Enums.CartItemSize.NoSize; string prefsString = string.Empty; if (cartDefMenuEx == null) { selItem = hccMenuItem.GetById(defMenu.MenuItemID); selPortionSize = (Enums.CartItemSize)defMenu.MenuItemSizeID; prefsString = "None"; } else { selItem = hccMenuItem.GetById(cartDefMenuEx.MenuItemID); selPortionSize = (Enums.CartItemSize)cartDefMenuEx.MenuItemSizeID; try { prefsString = string.Empty; List <hccPreference> prefs = hccCartDefaultMenuExPref.GetPrefsBy(cartDefMenuEx.DefaultMenuExceptID); prefsString = prefs.Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d); } catch (Exception) { throw; } } if (selPortionSize == Enums.CartItemSize.NoSize) { selPortionSize = Enums.CartItemSize.RegularSize; } MOTCartItem curMotItem = null; if (selItem != null) { if (selItem.MealType == Enums.MealTypes.BreakfastEntree || selItem.MealType == Enums.MealTypes.LunchEntree || selItem.MealType == Enums.MealTypes.DinnerEntree || selItem.MealType == Enums.MealTypes.ChildEntree || selItem.MealType == Enums.MealTypes.Beverage || selItem.MealType == Enums.MealTypes.Dessert || selItem.MealType == Enums.MealTypes.Goods || selItem.MealType == Enums.MealTypes.Miscellaneous || selItem.MealType == Enums.MealTypes.Salad || selItem.MealType == Enums.MealTypes.Snack || selItem.MealType == Enums.MealTypes.Soup || selItem.MealType == Enums.MealTypes.Supplement) { curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber && a.MealType == selItem.MealType); if (curMotItem == null || curMotItem.MealType == Enums.MealTypes.Snack) { curMotItem = new MOTCartItem { CartItem = cartItem, CartItemId = cartItem.CartItemID, CustomerName = cartItem.UserProfile.ParentProfileName, OrderNumber = cartItem.OrderNumber + "-PRG", DeliveryDate = prodCal.DeliveryDate, DayNumber = defMenu.DayNumber, ItemName = selItem.Name, MealType = selItem.MealType, PortionSize = Enums.GetEnumDescription(selPortionSize), Preferences = prefsString, ProfileName = cartItem.UserProfile != null ? cartItem.UserProfile.ProfileName : string.Empty, Servings = cartItem.Quantity.ToString(), MenuItem = selItem, Quantity = cartItem.Quantity, Sides = "None" }; if (cartItem.SnapShipAddrId.HasValue) { hccAddress addr = hccAddress.GetById(cartItem.SnapShipAddrId.Value); curMotItem.DeliveryMethod = ((Enums.DeliveryTypes)addr.DefaultShippingTypeID).ToString(); } retMotItems.Add(curMotItem); } else { curMotItem.Sides += selPortionSize + " - " + selItem.Name; } } else { // get parent entree type Enums.MealTypes parentType = Enums.MealTypes.Unknown; if (selItem.MealType == Enums.MealTypes.BreakfastSide) { parentType = Enums.MealTypes.BreakfastEntree; } else if (selItem.MealType == Enums.MealTypes.LunchSide) { parentType = Enums.MealTypes.LunchEntree; } else if (selItem.MealType == Enums.MealTypes.DinnerSide) { parentType = Enums.MealTypes.DinnerEntree; } else if (selItem.MealType == Enums.MealTypes.OtherSide) { parentType = Enums.MealTypes.OtherEntree; } else if (selItem.MealType == Enums.MealTypes.ChildSide) { parentType = Enums.MealTypes.ChildEntree; } curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber && a.MealType == parentType); if (curMotItem == null) { curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber); if (curMotItem == null) { curMotItem = new MOTCartItem { CartItem = cartItem, CartItemId = cartItem.CartItemID, CustomerName = cartItem.UserProfile.ParentProfileName, OrderNumber = cartItem.OrderNumber + "-PRG", DeliveryDate = prodCal.DeliveryDate, DayNumber = defMenu.DayNumber, ItemName = selItem.Name, MealType = selItem.MealType, PortionSize = Enums.GetEnumDescription(selPortionSize), Preferences = prefsString, ProfileName = cartItem.UserProfile != null ? cartItem.UserProfile.ProfileName : string.Empty, Servings = cartItem.Quantity.ToString(), MenuItem = selItem, Quantity = cartItem.Quantity, Sides = "None" }; if (cartItem.SnapShipAddrId.HasValue) { hccAddress addr = hccAddress.GetById(cartItem.SnapShipAddrId.Value); curMotItem.DeliveryMethod = ((Enums.DeliveryTypes)addr.DefaultShippingTypeID).ToString(); } retMotItems.Add(curMotItem); } } else { if (string.IsNullOrWhiteSpace(curMotItem.Sides)) { curMotItem.Sides = selItem.Name; if (prefsString != "None" && !string.IsNullOrWhiteSpace(prefsString)) { curMotItem.Sides += " (" + prefsString + ")"; } } else { if (curMotItem.Sides == "None") { curMotItem.Sides = selItem.Name; } else { curMotItem.Sides += ", " + selItem.Name; } if (prefsString != "None" && !string.IsNullOrWhiteSpace(prefsString)) { curMotItem.Sides += " (" + prefsString + ")"; } } } } } }); List <MOTCartItem> removeDupItems = new List <MOTCartItem>(); retMotItems.ForEach(delegate(MOTCartItem motItem) { if (motItem.MealType == Enums.MealTypes.BreakfastEntree || motItem.MealType == Enums.MealTypes.LunchEntree || motItem.MealType == Enums.MealTypes.DinnerEntree || motItem.MealType == Enums.MealTypes.ChildEntree || motItem.MealType == Enums.MealTypes.Beverage || motItem.MealType == Enums.MealTypes.Dessert || motItem.MealType == Enums.MealTypes.Goods || motItem.MealType == Enums.MealTypes.Miscellaneous || motItem.MealType == Enums.MealTypes.Salad || motItem.MealType == Enums.MealTypes.Snack || motItem.MealType == Enums.MealTypes.Soup || motItem.MealType == Enums.MealTypes.Supplement) { if (motItem.CartItem.Quantity > 1) { for (int i = 1; i <= motItem.CartItem.Quantity; i++) { MOTCartItem copyMotItem = new MOTCartItem { CartItem = motItem.CartItem, CartItemId = motItem.CartItemId, OrderNumber = motItem.OrderNumber, DeliveryDate = motItem.DeliveryDate, CustomerName = motItem.CustomerName, DayNumber = motItem.DayNumber, ItemName = motItem.ItemName, MealType = motItem.MealType, PortionSize = motItem.PortionSize, Preferences = motItem.Preferences, ProfileName = motItem.ProfileName, MenuItem = motItem.MenuItem, Index = motItem.Index, Quantity = motItem.Quantity, Sides = motItem.Sides, DeliveryMethod = motItem.DeliveryMethod, Servings = "1" //motItem.Servings }; addlMotItems.Add(copyMotItem); } removeDupItems.Add(motItem); } } }); if (addlMotItems.Count > 0) { retMotItems.AddRange(addlMotItems); } if (removeDupItems.Count > 0) { removeDupItems.ForEach(a => retMotItems.Remove(a)); } var t = retMotItems.ToList(); return(t); } catch (Exception) { throw; } }
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()); }