public static int AddGplusAccount(JObject profile, Model.DatabaseRepository dbr, Int64 userId, Int64 groupId, string accessToken, string refreshToken, Helper.Cache _redisCache, Helper.AppSettings settings, ILogger _logger) { int isSaved = 0; Domain.Socioboard.Models.Googleplusaccounts gplusAcc = GplusRepository.getGPlusAccount(Convert.ToString(profile["id"]), _redisCache, dbr); oAuthTokenGPlus ObjoAuthTokenGPlus = new oAuthTokenGPlus(settings.GoogleConsumerKey, settings.GoogleConsumerSecret, settings.GoogleRedirectUri); if (gplusAcc != null && gplusAcc.IsActive == false) { gplusAcc.IsActive = true; gplusAcc.UserId = userId; gplusAcc.AccessToken = accessToken; gplusAcc.RefreshToken = refreshToken; gplusAcc.EntryDate = DateTime.UtcNow; try { gplusAcc.GpUserName = profile["displayName"].ToString(); } catch { try { gplusAcc.GpUserName = profile["name"].ToString(); } catch { } } try { gplusAcc.GpProfileImage = Convert.ToString(profile["image"]["url"]); } catch { try { gplusAcc.GpProfileImage = Convert.ToString(profile["picture"]); } catch { } } gplusAcc.AccessToken = accessToken; try { gplusAcc.about = Convert.ToString(profile["tagline"]); } catch { gplusAcc.about = ""; } try { gplusAcc.college = Convert.ToString(profile["organizations"][0]["name"]); } catch { gplusAcc.college = ""; } try { gplusAcc.coverPic = Convert.ToString(profile["cover"]["coverPhoto"]["url"]); } catch { gplusAcc.coverPic = ""; } try { gplusAcc.education = Convert.ToString(profile["organizations"][0]["type"]); } catch { gplusAcc.education = ""; } try { gplusAcc.EmailId = Convert.ToString(profile["emails"][0]["value"]); } catch { gplusAcc.EmailId = ""; } try { gplusAcc.gender = Convert.ToString(profile["gender"]); } catch { gplusAcc.gender = ""; } try { gplusAcc.workPosition = Convert.ToString(profile["occupation"]); } catch { gplusAcc.workPosition = ""; } gplusAcc.LastUpdate = DateTime.UtcNow; #region Get_InYourCircles try { string _InyourCircles = ObjoAuthTokenGPlus.APIWebRequestToGetUserInfo(Globals.strGetPeopleList.Replace("[userId]", gplusAcc.GpUserId).Replace("[collection]", "visible") + "?key=" + settings.GoogleApiKey, accessToken); JObject J_InyourCircles = JObject.Parse(_InyourCircles); gplusAcc.InYourCircles = Convert.ToInt32(J_InyourCircles["totalItems"].ToString()); } catch (Exception ex) { gplusAcc.InYourCircles = 0; } #endregion #region Get_HaveYouInCircles try { string _HaveYouInCircles = ObjoAuthTokenGPlus.APIWebRequestToGetUserInfo(Globals.strGetPeopleProfile + gplusAcc.GpUserId + "?key=" + settings.GoogleApiKey, accessToken); JObject J_HaveYouInCircles = JObject.Parse(_HaveYouInCircles); gplusAcc.HaveYouInCircles = Convert.ToInt32(J_HaveYouInCircles["circledByCount"].ToString()); } catch (Exception ex) { gplusAcc.HaveYouInCircles = 0; } #endregion dbr.Update <Domain.Socioboard.Models.Googleplusaccounts>(gplusAcc); } else { gplusAcc = new Domain.Socioboard.Models.Googleplusaccounts(); gplusAcc.UserId = userId; gplusAcc.GpUserId = profile["id"].ToString(); try { gplusAcc.GpUserName = profile["displayName"].ToString(); } catch { try { gplusAcc.GpUserName = profile["name"].ToString(); } catch { } } gplusAcc.IsActive = true; gplusAcc.AccessToken = accessToken; gplusAcc.RefreshToken = refreshToken; gplusAcc.EntryDate = DateTime.UtcNow; try { gplusAcc.GpProfileImage = Convert.ToString(profile["image"]["url"]); } catch { try { gplusAcc.GpProfileImage = Convert.ToString(profile["picture"]); } catch { } } gplusAcc.AccessToken = accessToken; try { gplusAcc.about = Convert.ToString(profile["tagline"]); } catch { gplusAcc.about = ""; } try { gplusAcc.college = Convert.ToString(profile["organizations"][0]["name"]); } catch { gplusAcc.college = ""; } try { gplusAcc.coverPic = Convert.ToString(profile["cover"]["coverPhoto"]["url"]); } catch { gplusAcc.coverPic = ""; } try { gplusAcc.education = Convert.ToString(profile["organizations"][0]["type"]); } catch { gplusAcc.education = ""; } try { gplusAcc.EmailId = Convert.ToString(profile["emails"][0]["value"]); } catch { try { try { gplusAcc.EmailId = Convert.ToString(profile["email"]); } catch { } } catch { } gplusAcc.EmailId = ""; } try { gplusAcc.gender = Convert.ToString(profile["gender"]); } catch { gplusAcc.gender = ""; } try { gplusAcc.workPosition = Convert.ToString(profile["occupation"]); } catch { gplusAcc.workPosition = ""; } gplusAcc.LastUpdate = DateTime.UtcNow; #region Get_InYourCircles try { string _InyourCircles = ObjoAuthTokenGPlus.APIWebRequestToGetUserInfo(Globals.strGetPeopleList.Replace("[userId]", gplusAcc.GpUserId).Replace("[collection]", "visible") + "?key=" + settings.GoogleApiKey, accessToken); JObject J_InyourCircles = JObject.Parse(_InyourCircles); gplusAcc.InYourCircles = Convert.ToInt32(J_InyourCircles["totalItems"].ToString()); } catch (Exception ex) { gplusAcc.InYourCircles = 0; } #endregion #region Get_HaveYouInCircles try { string _HaveYouInCircles = ObjoAuthTokenGPlus.APIWebRequestToGetUserInfo(Globals.strGetPeopleProfile + gplusAcc.GpUserId + "?key=" + settings.GoogleApiKey, accessToken); JObject J_HaveYouInCircles = JObject.Parse(_HaveYouInCircles); gplusAcc.HaveYouInCircles = Convert.ToInt32(J_HaveYouInCircles["circledByCount"].ToString()); } catch (Exception ex) { gplusAcc.HaveYouInCircles = 0; } #endregion isSaved = dbr.Add <Domain.Socioboard.Models.Googleplusaccounts>(gplusAcc); } if (isSaved == 1) { List <Domain.Socioboard.Models.Googleplusaccounts> lstgplusAcc = dbr.Find <Domain.Socioboard.Models.Googleplusaccounts>(t => t.GpUserId.Equals(gplusAcc.GpUserId)).ToList(); if (lstgplusAcc != null && lstgplusAcc.Count() > 0) { isSaved = GroupProfilesRepository.AddGroupProfile(groupId, lstgplusAcc.First().GpUserId, lstgplusAcc.First().GpUserName, userId, lstgplusAcc.First().GpProfileImage, Domain.Socioboard.Enum.SocialProfileType.GPlus, dbr); //codes to delete cache _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId); _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId); if (isSaved == 1) { new Thread(delegate() { GetUserActivities(gplusAcc.GpUserId, gplusAcc.AccessToken, settings, _logger); }).Start(); } } } return(isSaved); }
private static void AddedProfileDetails(Cache redisCache, DatabaseRepository dbr, List <profilesdetail> groupProfiles, Groupprofiles profile) { switch (profile.profileType) { case SocialProfileType.Facebook: { var fbAcc = FacebookRepository.getFacebookAccount(profile.profileId, redisCache, dbr); var profileDetails = new profilesdetail { Fbaccount = fbAcc }; groupProfiles.Add(profileDetails); break; } case SocialProfileType.FacebookFanPage: { var fbPageAcc = FacebookRepository.getFacebookAccount(profile.profileId, redisCache, dbr); var profileDetails = new profilesdetail { Fbaccount = fbPageAcc }; groupProfiles.Add(profileDetails); break; } case SocialProfileType.Twitter: { var twtAcc = TwitterRepository.getTwitterAccount(profile.profileId, redisCache, dbr); var profileDetails = new profilesdetail { Twtaccount = twtAcc }; groupProfiles.Add(profileDetails); break; } case SocialProfileType.Instagram: { var insAcc = InstagramRepository.getInstagramAccount(profile.profileId, redisCache, dbr); var profileDetails = new profilesdetail { Instaaccount = insAcc }; groupProfiles.Add(profileDetails); break; } case SocialProfileType.GPlus: { var gPlusAcc = GplusRepository.getGPlusAccount(profile.profileId, redisCache, dbr); var profileDetails = new profilesdetail { Gplusaccount = gPlusAcc }; groupProfiles.Add(profileDetails); break; } case SocialProfileType.LinkedIn: { var linkedInAcc = LinkedInAccountRepository.getLinkedInAccount(profile.profileId, redisCache, dbr); var profileDetails = new profilesdetail { LinkdInaccount = linkedInAcc }; groupProfiles.Add(profileDetails); break; } case SocialProfileType.LinkedInComapanyPage: { var linkedCompanyAcc = LinkedInAccountRepository.getLinkedinCompanyPage(profile.profileId, redisCache, dbr); var profileDetails = new profilesdetail { LinkdINcompanyaccount = linkedCompanyAcc }; groupProfiles.Add(profileDetails); break; } case SocialProfileType.YouTube: { var youtubeChannel = GplusRepository.getYTChannel(profile.profileId, redisCache, dbr); var profileDetails = new profilesdetail { Ytubeaccount = youtubeChannel }; groupProfiles.Add(profileDetails); break; } case SocialProfileType.GoogleAnalytics: { var gAAcc = GplusRepository.getGAAccount(profile.profileId, redisCache, dbr); var profileDetails = new profilesdetail { GAaccount = gAAcc }; groupProfiles.Add(profileDetails); break; } case SocialProfileType.Pinterest: { var pInterestAccountDetail = PinterestRepository.getPinterestAccountDetail(profile.profileId, redisCache, dbr); var profileDetails = new profilesdetail { Pintrestaccount = pInterestAccountDetail }; groupProfiles.Add(profileDetails); break; } case SocialProfileType.GplusPage: break; case SocialProfileType.Tumblr: break; case SocialProfileType.FacebookPublicPage: break; case SocialProfileType.DropBox: break; default: throw new ArgumentOutOfRangeException(); } }