private void SetupFeaturedGroups() { aqufitEntities entities = new aqufitEntities(); // CA - We have encoded the number of members in a Groups::MainGroupKey ... this is an easy way to pick out featured groups.. IQueryable<Group> featureQuery = entities.UserSettings.OfType<Group>().Include("Image").Include("Places").Where(g => g.MainGroupKey > 10 ); int gcount = featureQuery.Count(); int skip = new Random().Next(gcount-1); Group feature = featureQuery.OrderBy( g => g.Id ).Skip(skip).First(); atiFGProfileImg.Settings = feature; hrefGroupName.HRef = hrefGroupLink2.HRef = ResolveUrl("~/") + "Group/" + feature.UserName; hrefGroupName.InnerHtml = feature.UserFirstName; Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance; Affine.Data.json.LeaderBoardWOD[] all = dataMan.CalculatCrossFitLeaderBoard(feature.Id); System.Web.Script.Serialization.JavaScriptSerializer jsSerial = new System.Web.Script.Serialization.JavaScriptSerializer(); RadAjaxManager1.ResponseScripts.Add("$(function(){ Aqufit.Page." + atiLeaderBoard2.ID + ".loadLeaderBoardFromJson('" + jsSerial.Serialize(all) + "'); });"); // TODO: cache this grabbing of the friend ids from the stream service long[] friendIds = entities.UserFriends.Where(f => (f.SrcUserSettingKey == feature.Id || f.DestUserSettingKey == feature.Id) && (f.Relationship >= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER)).Select(f => (f.SrcUserSettingKey == feature.Id ? f.DestUserSettingKey : f.SrcUserSettingKey)).ToArray(); IQueryable<Affine.Data.User> friends = entities.UserSettings.OfType<User>().Where(Affine.Utils.Linq.LinqUtils.BuildContainsExpression<User, long>(s => s.Id, friendIds)).OrderBy(s => s.Id); int fcount = friends.Count(); UserSettings[] firendSettings = null; if (fcount > 6) { Random rand = new Random((int)DateTime.Now.Millisecond); skip = rand.Next(fcount - 6); firendSettings = friends.Skip(skip).Take(6).ToArray(); } else { firendSettings = friends.Take(6).ToArray(); } atiFriendsPhotos.FriendKeyList = firendSettings; atiFriendsPhotos.User = feature; atiFriendsPhotos.FriendCount = fcount; atiFriendsPhotos.FriendListLink = ResolveUrl("~/") + feature.UserName + "/Friends"; if( feature.Places.Count > 0 ){ Place place = feature.Places.FirstOrDefault(); litGroupDescription.Text += "<span>" + place.Street + "<br />"+place.City+", "+place.Region+", "+place.Country+"</span>"; litGroupDescription.Text += "<span>"+place.Description+"</span>"; } WebService.StreamService streamService = new WebService.StreamService(); string json = streamService.getActiveGroups(0, 10); ScriptManager.RegisterStartupScript(this, Page.GetType(), "Groups", "$(function(){ Aqufit.Page.atiGroupList.generateStreamDom('" + json + "'); });", true); }