//[WebMethod(CacheDuration=120)] public MutualFriendsClass[] GetMutualFriendsArray(string viewer, string viewed, int count) { var mfSearch = new MutualFriendsSearch{ Viewer = viewer, Viewed = viewed }; DateTime[] time = new DateTime[5]; time[0] = DateTime.Now; var searchResults = mfSearch.GetResults(); User[] mf = (searchResults != null)? searchResults.Get(): new User[] {}; time[1] = DateTime.Now; var dic = (Dictionary<string, List<string>>)Session["MatchmakingRequestedDic"]; var reqList = dic.ContainsKey(viewed) ? (List<string>)dic[viewed] : null; IList<MutualFriendsClass> list = new List<MutualFriendsClass>(); list = mf.Select(user => new MutualFriendsClass { Name = GetDisplayName(viewer, user.Username), Username = user.Username, PhotoId = Photo.GetPrimaryOrDefaultId(user.Username), PhotoUrl = ImageHandler.CreateImageUrl( Photo.GetPrimaryOrDefaultId(user.Username), 30, 30, false, true, true), AlreadyRequested = (reqList != null && reqList.Contains(user.Username)) }).Take(count).ToList(); return list.ToArray(); }
public void GetMutualFriends(string viewer, string viewed) { var mfSearch = new MutualFriendsSearch { Viewer = viewer, Viewed = viewed }; var searchResults = mfSearch.GetResults(); User[] mf = (searchResults != null)? searchResults.Get(): new User[] {}; IList<MutualFriendsClass> list = mf.Select(user => new MutualFriendsClass {Username = user.Username, PhotoId = Photo.GetPrimaryOrDefaultId(user.Username)}).ToList(); string retval = JsonConvert.SerializeObject(list); HttpContext.Current.Response.ContentType = "application/json"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(retval); HttpContext.Current.Response.End(); }
public static IList<SearchService.MutualFriendsClass> GetMutualFriendsList(string viewer, string viewed, ImageHandler.eFacebookImageType fbImageSize) { if (HttpContext.Current.Session == null) { } var dic = (Dictionary<string, List<string>>)Global.GetSessionState()["MatchmakingRequestedDic"]; if (dic == null) { } if (!dic.ContainsKey(viewed)) dic.Add(viewed, new List<string>()); var reqList = (List<string>)dic[viewed]; DateTime[] t = new DateTime[5]; t[0] = DateTime.Now; var searchAppMF = new MutualFriendsSearch { Viewer = viewer, Viewed = viewed }; var searchAppResults = searchAppMF.GetResults(); User[] appMF = (searchAppResults != null) ? searchAppResults.Get() : new User[] { }; t[1] = DateTime.Now; IList<SearchService.MutualFriendsClass> mfList = null; //using (var db = new ezFixUpDataContext()) { mfList = appMF.Select(user => new SearchService.MutualFriendsClass { Name = UserSession.GetViewedUserDisplayedNameByUsername(viewer, user.Username), Username = user.Username, PhotoId = Photo.GetPrimaryOrDefaultId(user.Username), PhotoUrl = Photo.GetPrimaryOrDefaultId(user.Username) == 0 && user.FacebookID.HasValue ? ImageHandler.CreateFacebookImageUrl(user.FacebookID.Value,ImageHandler.eFacebookImageType.Square) : ImageHandler.CreateImageUrl(Photo.GetPrimaryOrDefaultId(user.Username), 50, 50, false, true, true), AlreadyRequested = reqList.Contains(user.Username) }).ToList(); } t[2] = DateTime.Now; if (FacebookHelper.IsCurrentSessionConnected) { var searchFacebookMF = new FacebookMutualFriendsSearch(viewer, viewed, PageBase.GetCurrentUserSession(), FacebookHelper.GetSessionFacebookApp()); var searchFacebookResults = searchFacebookMF.GetResults(); User[] fbMF = (searchFacebookResults != null) ? searchFacebookResults.Get() : new User[] { }; t[3] = DateTime.Now; //using (var db = new ezFixUpDataContext()) { IList<SearchService.MutualFriendsClass> lstFacebookMF = fbMF.Where(user => mfList.All(u => u.Username != user.Username)) .Select(user => new SearchService.MutualFriendsClass { Name = UserSession.GetViewedUserDisplayedNameByUsername(viewer, user.Username), Username = user.Username, PhotoId = 0, PhotoUrl = ImageHandler.CreateFacebookImageUrl(user.FacebookID.Value, fbImageSize), //String.Format("https://graph.facebook.com/{0}/picture?type=square",user.FacebookID), AlreadyRequested = reqList.Contains(user.Username) }).ToList(); if (lstFacebookMF != null && lstFacebookMF.Count > 0) { mfList = mfList.Union(lstFacebookMF).ToList(); } } t[4] = DateTime.Now; } return mfList; //List<SearchService.MutualFriendsClass> lstFacebookMF = searchFacebookMF.GetSavedResults(); //if (lstFacebookMF != null && lstFacebookMF.Count > 0) //{ // lstFacebookMF = lstFacebookMF.Select(f => new SearchService.MutualFriendsClass // { // Username = f.Username, // PhotoId = f.PhotoId, // PhotoUrl = f.PhotoUrl, // AlreadyRequested = reqList.Contains(f.Username) // }).ToList(); // mfList = lstAppMF.Concat(lstFacebookMF).ToList(); //} //return mfList; }