public RadComboBoxData GetCompanyNames(RadComboBoxContext context) { List<ComboBoxItemData> data = GetData(context.Text); RadComboBoxData comboData = new RadComboBoxData(); int itemOffset = context.NumberOfItems; int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Count); comboData.EndOfItems = endOffset == data.Count; List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(endOffset - itemOffset); for (int i = itemOffset; i < endOffset; i++) { RadComboBoxItemData itemData = new RadComboBoxItemData(); itemData.Text = data[i].CompanyName; itemData.Value = data[i].CompanyId.ToString(); itemData.Attributes["Branch"] = data[i].BranchName; itemData.Attributes["Site"] = data[i].SiteName; result.Add(itemData); } comboData.Message = GetStatusMessage(endOffset, data.Count); comboData.Items = result.ToArray(); return comboData; }
public RadComboBoxData GetComboItems([FromBody]RadComboBoxContext context) { string text = ""; int numberOfItems = 0; foreach (var item in context) { JToken token = JObject.Parse(item.Value.ToString()); text = (string)token.SelectToken("Text"); numberOfItems = (int)token.SelectToken("NumberOfItems"); } List<Product> products = GetProducts(text); RadComboBoxData comboData = new RadComboBoxData(); int itemOffset = numberOfItems; int endOffset = Math.Min(itemOffset + ItemsPerRequest, products.Count); comboData.EndOfItems = endOffset == products.Count; List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(); for (int i = itemOffset; i < endOffset; i++) { RadComboBoxItemData itemData = new RadComboBoxItemData(); itemData.Text = products[i].Name; itemData.Value = products[i].Id.ToString(); result.Add(itemData); } comboData.Message = GetStatusMessage(endOffset, products.Count); comboData.Items = result.ToArray(); return comboData; }
public RadComboBoxData GetRoutesOnDemand(RadComboBoxContext context) { List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems); RadComboBoxData comboData = new RadComboBoxData(); try { int itemsPerRequest = 10; int itemOffset = context.NumberOfItems; int endOffset = itemOffset + itemsPerRequest; long ProfileUserSettingsId = Convert.ToInt64(context["UserSettingsId"]); aqufitEntities entities = new aqufitEntities(); UserSettings UserSettings = entities.UserSettings.FirstOrDefault(u => u.Id == ProfileUserSettingsId); IQueryable<MapRoute> mapRoutesQuery = string.IsNullOrEmpty(context.Text) ? entities.User2MapRouteFav.Include("MapRoutes").Where(r => r.UserSettingsKey == ProfileUserSettingsId).Select(r => r.MapRoute).OrderBy(w => w.Name) : entities.User2MapRouteFav.Include("MapRoutes").Where(r => r.UserSettingsKey == ProfileUserSettingsId).Select(r => r.MapRoute).Where(r => r.Name.ToLower().StartsWith(context.Text)).OrderBy(r => r.Name); int length = mapRoutesQuery.Count(); MapRoute[] mapRoutes = mapRoutesQuery.Skip(itemOffset).Take(itemsPerRequest).ToArray(); string mapIcon = ResolveUrl("~/DesktopModules/ATI_Base/resources/images/iMap.png"); if (itemOffset == 0) { RadComboBoxItemData item = new RadComboBoxItemData(); item.Text = "<img src=\"" + mapIcon + "\" /> Add New Map"; item.Value = "{'Id':0, 'Dist':'0'}"; result.Add(item); } Affine.Utils.UnitsUtil.MeasureUnit unit = UserSettings.DistanceUnits != null ? Affine.Utils.UnitsUtil.ToUnit(Convert.ToInt32(UserSettings.DistanceUnits)) : Affine.Utils.UnitsUtil.MeasureUnit.UNIT_MILES; string unitName = Affine.Utils.UnitsUtil.unitToStringName(unit); foreach (MapRoute mr in mapRoutes) { double dist = Affine.Utils.UnitsUtil.systemDefaultToUnits(mr.RouteDistance, unit); dist = Math.Round(dist, 2); RadComboBoxItemData item = new RadComboBoxItemData(); item.Text = "<img src=\"" + Affine.Utils.ImageUtil.GetGoogleMapsStaticImage(mr, 200, 150) + "\" />" + Affine.Utils.Web.WebUtils.FromWebSafeString(mr.Name) + " (" + dist + " " + unitName + ")"; item.Value = "{ 'Id':" + mr.Id + ", 'Dist':" + mr.RouteDistance + "}"; result.Add(item); } if (endOffset > length) { endOffset = length; } if (endOffset == length) { comboData.EndOfItems = true; } else { comboData.EndOfItems = false; } if (length > 0) { comboData.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), length); } else { comboData.Message = "No matches"; } comboData.Items = result.ToArray(); } catch (Exception ex) { comboData.Message = ex.Message; } return comboData; }
public RadComboBoxData GetGroupSearch(RadComboBoxContext context) { List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems); RadComboBoxData comboData = new RadComboBoxData(); if (!string.IsNullOrWhiteSpace(context.Text)) { try { const int TAKE = 15; aqufitEntities entities = new aqufitEntities(); int itemOffset = context.NumberOfItems; IQueryable<Group> friends = entities.UserSettings.OfType<Group>().OrderBy(w => w.UserName); friends = friends.Where(w => w.UserName.ToLower().Contains(context.Text) || w.UserFirstName.ToLower().Contains(context.Text)); int length = friends.Count(); friends = friends.Skip(itemOffset).Take(TAKE); Group[] groups = friends.ToArray(); foreach (Group g in groups) { RadComboBoxItemData item = new RadComboBoxItemData(); item.Text = g.UserFirstName; item.Value = " { 'Address': '', 'GroupKey':" + g.Id + ", 'Lat':" + g.DefaultMapLat + ", 'Lng':" + g.DefaultMapLng + " , 'Name':'" + g.UserFirstName + "', 'UserName':'******'", "") + "', 'UserKey':" + g.UserKey + ", 'ImageId':0, 'Description':'' }"; // item.ImageUrl = ResolveUrl("~/DesktopModules/ATI_Base/services/images/profile.aspx") + "?u=" + g.UserKey + "&p=" + g.PortalKey; result.Add(item); } int endOffset = Math.Min(itemOffset + TAKE + 1, length); if (endOffset > length) { endOffset = length; } if (endOffset == length) { comboData.EndOfItems = true; } else { comboData.EndOfItems = false; } if (length > 0) { comboData.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), length); } else { comboData.Message = "No matches"; } comboData.Items = result.ToArray(); } catch (Exception ex) { comboData.Message = ex.Message; } } else { comboData.Message = "Type to search"; } return comboData; }
public RadComboBoxData GetFlexFWDSearch(RadComboBoxContext context) { List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems); RadComboBoxData comboData = new RadComboBoxData(); if (!string.IsNullOrWhiteSpace(context.Text)) { try { int itemsPerRequest = 10; int itemOffset = context.NumberOfItems; int endOffset = itemOffset + itemsPerRequest; long ProfileUserSettingsId = Convert.ToInt64(context["UserSettingsId"]); aqufitEntities entities = new aqufitEntities(); //UserSettings profileSettings = entities.UserSettings.OfType<User>().FirstOrDefault(u => u.UserKey == PortalSettings.Current.UserId && u.PortalKey == PortalSettings.Current.PortalId); IQueryable<UserSettings> friends = entities.UserSettings.Where(u => u.PortalKey == PortalSettings.Current.PortalId).OrderBy(w => w.UserName); friends = friends.Where(w => w.UserName.ToLower().StartsWith(context.Text) || w.UserFirstName.ToLower().StartsWith(context.Text) || w.UserLastName.ToLower().StartsWith(context.Text)); int length = friends.Count(); var users = friends.Skip(itemOffset).Take(itemsPerRequest).Select(u => new {Id = u.Id, Type = (u is User ? "User" : "Group"), UserKey = u.UserKey, PortalKey = u.PortalKey, UserFirstName = u.UserFirstName, UserLastName = u.UserLastName, UserName = u.UserName }).ToArray(); foreach (var u in users) { RadComboBoxItemData item = new RadComboBoxItemData(); if (u.Type == "User") { item.Text = "<img style=\"float: left;\" src=\"" + StreamService.ResolveUrl("~/DesktopModules/ATI_Base/services/images/profile.aspx") + "?u=" + u.UserKey + "&p=" + u.PortalKey + "\" /><span class=\"atiTmItem\">" + u.UserName + "<br /> (" + u.UserFirstName + " " + u.UserLastName + ")</span>"; item.Value = "{ Type:'USER', Val:'" + u.UserName + "'}"; } else { item.Text = "<img style=\"float: left;\" src=\"" + StreamService.ResolveUrl("~/DesktopModules/ATI_Base/services/images/profile.aspx") + "?us=" + u.Id + "\" /><span class=\"atiTmItem\">" + u.UserFirstName + "</span>"; item.Value = "{ Type:'GROUP', Val:'" + u.UserName + "'}"; } result.Add(item); } if (endOffset > length) { endOffset = length; } if (endOffset == length) { comboData.EndOfItems = true; } else { comboData.EndOfItems = false; } if (length > 0) { comboData.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), length); } else { comboData.Message = "No matches"; } comboData.Items = result.ToArray(); } catch (Exception ex) { comboData.Message = ex.Message; } } else { comboData.Message = "Type to search"; } return comboData; }
public RadComboBoxData GetExerciseListOnDemand(RadComboBoxContext context) { List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems); RadComboBoxData comboData = new RadComboBoxData(); try { int itemsPerRequest = 15; int itemOffset = context.NumberOfItems; int endOffset = itemOffset + itemsPerRequest; aqufitEntities entities = new aqufitEntities(); IQueryable<Exercise> erercisesQuery = string.IsNullOrEmpty(context.Text) ? entities.Exercises.OrderBy(e => e.Name) : entities.Exercises.Where(e => e.Name.ToLower().StartsWith(context.Text)).OrderBy(e => e.Name); int length = erercisesQuery.Count(); Exercise[] exercises = erercisesQuery.Skip(itemOffset).Take(itemsPerRequest).ToArray(); foreach (Exercise exer in exercises) { RadComboBoxItemData item = new RadComboBoxItemData(); item.Text = exer.Name; item.Value = "" + exer.Id; result.Add(item); } if (endOffset > length) { endOffset = length; } if (endOffset == length) { comboData.EndOfItems = true; } else { comboData.EndOfItems = false; } if (length > 0) { comboData.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), length); } else { comboData.Message = "No matches"; } comboData.Items = result.ToArray(); } catch (Exception ex) { comboData.Message = ex.Message; } return comboData; }
public RadComboBoxData GetWorkoutsOnDemand(RadComboBoxContext context) { List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems); RadComboBoxData comboData = new RadComboBoxData(); try { int itemsPerRequest = 10; int itemOffset = context.NumberOfItems; int endOffset = itemOffset + itemsPerRequest; long ProfileUserSettingsId = Convert.ToInt64(context["UserSettingsId"]); aqufitEntities entities = new aqufitEntities(); UserSettings UserSettings = entities.UserSettings.FirstOrDefault(u => u.Id == ProfileUserSettingsId); if (itemOffset == 0) { RadComboBoxItemData item = new RadComboBoxItemData(); item.Text = "Create a New Workout"; item.Value = "{'Id':0, 'Type':'0'}"; result.Add(item); } IQueryable<WOD> wods = entities.User2WODFav.Where(w => w.UserSetting.Id == UserSettings.Id).Select(w => w.WOD); wods = wods.Union<WOD>(entities.WODs.Where(w => w.Standard > 0)); wods.Select(w => w.WODType).ToArray(); // hydrate WODTypes long[] groupIds = null; groupIds = entities.UserFriends.Where(f => (f.SrcUserSettingKey == UserSettings.Id || f.DestUserSettingKey == UserSettings.Id) && f.Relationship >= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER).Select(f => f.SrcUserSettingKey == UserSettings.Id ? f.DestUserSettingKey : f.SrcUserSettingKey).ToArray(); // OK this is a bit of a trick... this query hydrates only the "WODSchedule" in the above WOD query.. so we will get the wods we are looking for.. IEnumerable<WODSchedule>[] workoutSchedule = entities.UserSettings.OfType<Group>().Where(LinqUtils.BuildContainsExpression<UserSettings, long>(us => us.Id, groupIds)).Select(g => g.WODSchedules.Where(ws => ws.HideTillDate.HasValue && DateTime.Now.CompareTo(ws.HideTillDate.Value) < 0)).ToArray(); string lowerTxt = context.Text.ToLower(); if (!string.IsNullOrWhiteSpace(context.Text)) { wods = wods.Where(w => w.Name.ToLower().Contains(lowerTxt) || w.WODSchedules.Where(ws => ws.HideTillDate.HasValue && DateTime.Now.CompareTo(ws.HideTillDate.Value) < 0).Any(ws => ws.HiddenName.ToLower().Contains(lowerTxt))).OrderBy(w => w.Name); } else { wods = wods.OrderByDescending(w => w.CreationDate); } int length = wods.Count(); wods = wods.Skip(itemOffset).Take(itemsPerRequest); WOD[] wodList = wods.ToArray(); for (int i = 0; i < wodList.Length; i++) { WOD w = wodList[i]; if (w.WODSchedules != null && w.WODSchedules.Count > 0) { WODSchedule ws = w.WODSchedules.OrderByDescending(s => s.HideTillDate).First(); if (ws.HideTillDate.HasValue && DateTime.Now.CompareTo(ws.HideTillDate.Value) < 0) { if (string.IsNullOrWhiteSpace(context.Text)) { result.Add(new RadComboBoxItemData() { Text = Affine.Utils.Web.WebUtils.FromWebSafeString(ws.HiddenName), Value = "{ 'Id':" + w.Id + ", 'Type':" + w.WODType.Id + "}" }); if (w.Standard > 0 || w.WODSchedules.Count > 1) { // CA - here is what is going on here. If the workout is suppost to be hidden until a date (common for crossfit gyms) then we just put a date name like up // top. But if it is a standard WOD (or a wod that they have done before (w.WODSchedules.Count > 1) then we still need to add the WOD result.Add(new RadComboBoxItemData() { Text = Affine.Utils.Web.WebUtils.FromWebSafeString(w.Name), Value = "{ 'Id':" + w.Id + ", 'Type':" + w.WODType.Id + "}" }); } } else if (ws.HiddenName.ToLower().StartsWith(lowerTxt)) { result.Add(new RadComboBoxItemData() { Text = Affine.Utils.Web.WebUtils.FromWebSafeString(ws.HiddenName), Value = "{ 'Id':" + w.Id + ", 'Type':" + w.WODType.Id + "}" }); } } else { result.Add(new RadComboBoxItemData() { Text = Affine.Utils.Web.WebUtils.FromWebSafeString(w.Name), Value = "{ 'Id':" + w.Id + ", 'Type':" + w.WODType.Id + "}" }); } } else { result.Add(new RadComboBoxItemData() { Text = Affine.Utils.Web.WebUtils.FromWebSafeString(w.Name), Value = "{ 'Id':" + w.Id + ", 'Type':" + w.WODType.Id + "}" }); } } if (endOffset > length) { endOffset = length; } if (endOffset == length) { comboData.EndOfItems = true; } else { comboData.EndOfItems = false; } if (length > 0) { comboData.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), length); } else { comboData.Message = "No matches"; } comboData.Items = result.ToArray(); } catch (Exception ex) { comboData.Message = ex.Message; } return comboData; }
public static RadComboBoxData GetFieldNames(RadComboBoxContext context) { var fields = new List<string>(); if (HttpContext.Current.Session["Fields"] != null) { fields = (List<string>) HttpContext.Current.Session["Fields"]; } var data = (from f in fields where f.ToLower().Contains(context.Text.ToLower()) select f).ToList(); var comboData = new RadComboBoxData(); var itemOffset = context.NumberOfItems; var endOffset = Math.Min(itemOffset + 10, data.Count); comboData.EndOfItems = endOffset == data.Count; var result = new List<RadComboBoxItemData>(endOffset - itemOffset); for (var i = itemOffset; i < endOffset; i++) { var itemData = new RadComboBoxItemData {Text = data.ElementAt(i), Value = data.ElementAt(i)}; result.Add(itemData); } comboData.Message = GetStatusMessage(endOffset, data.Count); comboData.Items = result.ToArray(); return comboData; }