public static IEnumerable <SelectListItem> ValueListSelect(this HtmlHelper htmlHelper) { ValueList valueListModel = htmlHelper.ViewData.Model as ValueList; int selectedValueListId = 0; if (valueListModel != null) { selectedValueListId = valueListModel.ValueListId; } IQueryable <ValueList> query = null; Models.BaseClasses.ClientRecord parentModel = htmlHelper.ViewData.ModelMetadata.Container as Models.BaseClasses.ClientRecord; if (parentModel != null && parentModel.ClientId != 0) { query = htmlHelper.GStoreDb().ValueLists.Where(vl => vl.ClientId == parentModel.ClientId); } else { query = htmlHelper.GStoreDb().ValueLists.All(); } List <ValueList> valueLists = query.ApplyDefaultSort().ToList(); return(valueLists.Select(vl => new SelectListItem() { Value = vl.ValueListId.ToString(), Text = vl.Name + " [" + vl.ValueListId + "]" + (vl.IsActiveBubble() ? "" : " [INACTIVE]") + " Client '" + vl.Client.Name + "' [" + vl.ClientId + "]" + " items: " + vl.ValueListItems.Count(), Selected = vl.ValueListId == selectedValueListId })); }
/// <summary> /// Will check for parameter client id, then viewdata["ClientId"] then parent record client id /// </summary> /// <param name="htmlHelper"></param> /// <param name="clientId"></param> /// <returns></returns> public static IEnumerable <SelectListItem> StoreFrontList(this HtmlHelper htmlHelper, int?clientId) { if (!clientId.HasValue) { clientId = htmlHelper.ViewData["ClientId"] as int?; if (!clientId.HasValue) { Models.BaseClasses.ClientRecord parentModel = htmlHelper.ViewData.ModelMetadata.Container as Models.BaseClasses.ClientRecord; clientId = 0; if (parentModel != null) { clientId = parentModel.ClientId; } else { UserProfile parentUserProfile = htmlHelper.ViewData.ModelMetadata.Container as UserProfile; if (parentUserProfile != null) { clientId = parentUserProfile.ClientId ?? 0; } } } } IQueryable <StoreFront> query = htmlHelper.GStoreDb().StoreFronts.Where(c => c.ClientId == clientId); int?selectedStoreFrontId = htmlHelper.ViewData.Model as int?; List <StoreFront> storeFronts = query.ApplyDefaultSort().ToList(); return(storeFronts.Select(s => new SelectListItem() { Value = s.StoreFrontId.ToString(), Selected = (selectedStoreFrontId.HasValue && selectedStoreFrontId.Value == s.StoreFrontId), Text = (s.CurrentConfigOrAny() == null ? "Store Front Id " + s.StoreFrontId : s.CurrentConfigOrAny().Name) + " [" + s.StoreFrontId + "]" + (s.IsActiveBubble() ? "" : " [INACTIVE]") + " - Client " + s.Client.Name + "[" + s.ClientId + "]" + (s.Client.IsActiveDirect() ? "" : " [INACTIVE]") }).ToList()); }