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); }
public static string DeleteProfile(long userId, long groupId, Helper.Cache _redisCache, Model.DatabaseRepository dbr, Helper.AppSettings _appSettings) { Domain.Socioboard.Models.Groups grp = dbr.Find <Domain.Socioboard.Models.Groups>(t => t.id == groupId).FirstOrDefault(); IList <Domain.Socioboard.Models.Groupprofiles> grpProfiles = dbr.Find <Groupprofiles>(t => t.groupId == groupId); if (grpProfiles.Count != 0) { foreach (Domain.Socioboard.Models.Groupprofiles grpProfile in grpProfiles) { string res = string.Empty; if (grpProfile != null) { try { switch (grpProfile.profileType) { case Domain.Socioboard.Enum.SocialProfileType.Facebook: { res = FacebookRepository.DeleteProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage: { res = FacebookRepository.DeleteProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.FacebookPublicPage: { res = FacebookRepository.DeleteProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.Twitter: { res = TwitterRepository.DeleteProfile(dbr, grpProfile.profileId, userId, _redisCache); break; } case Domain.Socioboard.Enum.SocialProfileType.LinkedIn: { res = LinkedInAccountRepository.DeleteProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.LinkedInComapanyPage: { res = LinkedInAccountRepository.DeleteCompanyPageProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.Instagram: { res = InstagramRepository.DeleteProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.GoogleAnalytics: { res = GplusRepository.DeleteProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.GPlus: { res = GplusRepository.DeleteGplusProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.YouTube: { res = GplusRepository.DeleteYoutubeChannelProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.Pinterest: { res = PinterestRepository.DeleteProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings); break; } } } catch (Exception ex) { } try { if (res.Equals("Deleted")) { dbr.Delete <Domain.Socioboard.Models.Groupprofiles>(grpProfile); // dbr.Delete<Domain.Socioboard.Models.Groups>(t => t.id == groupId); _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId); _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId); } else { if (grpProfile != null) { dbr.Delete <Domain.Socioboard.Models.Groupprofiles>(grpProfile); //dbr.Delete<Domain.Socioboard.Models.Groups>(t => t.id == groupId); _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId); _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId); } } } catch (Exception ex) { } } else { return("Issue while deleting Profile"); } } dbr.Delete <Domain.Socioboard.Models.Groups>(grp); return("Deleted"); } else { dbr.Delete <Domain.Socioboard.Models.Groups>(grp); } return("Deleted"); }
private static string DeleteGroup(long userId, string profileId, Cache _redisCache, DatabaseRepository dbr, AppSettings _appSettings, Groupprofiles grpProfile, string res) { switch (grpProfile.profileType) { case SocialProfileType.Facebook: { res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case SocialProfileType.FacebookFanPage: { res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case SocialProfileType.FacebookPublicPage: { res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case SocialProfileType.Twitter: { res = TwitterRepository.DeleteProfile(dbr, profileId, userId, _redisCache); break; } case SocialProfileType.LinkedIn: { res = LinkedInAccountRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case SocialProfileType.LinkedInComapanyPage: { res = LinkedInAccountRepository.DeleteCompanyPageProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case SocialProfileType.Instagram: { res = InstagramRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case SocialProfileType.GoogleAnalytics: { res = GplusRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case SocialProfileType.GPlus: { res = GplusRepository.DeleteGplusProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case SocialProfileType.YouTube: { res = GplusRepository.DeleteYoutubeChannelProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case SocialProfileType.Pinterest: { res = PinterestRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } } return(res); }
public static string DeleteProfile(long groupId, long userId, string profileId, Helper.Cache _redisCache, Model.DatabaseRepository dbr, Helper.AppSettings _appSettings) { Domain.Socioboard.Models.Groupprofiles grpProfile = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.groupId == groupId && t.profileId.Equals(profileId)).FirstOrDefault(); Domain.Socioboard.Models.Groups grp = dbr.Find <Domain.Socioboard.Models.Groups>(t => t.id == groupId).FirstOrDefault(); string res = string.Empty; if (grpProfile != null) { if (grp.groupName.Equals(Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName)) { switch (grpProfile.profileType) { case Domain.Socioboard.Enum.SocialProfileType.Facebook: { res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage: { res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.FacebookPublicPage: { res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.Twitter: { res = TwitterRepository.DeleteProfile(dbr, profileId, userId, _redisCache); break; } case Domain.Socioboard.Enum.SocialProfileType.LinkedIn: { res = LinkedInAccountRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.LinkedInComapanyPage: { res = LinkedInAccountRepository.DeleteCompanyPageProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.Instagram: { res = InstagramRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.GoogleAnalytics: { res = GplusRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.GPlus: { res = GplusRepository.DeleteGplusProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } } } else { Groups defaultGroup = GroupsRepository.getAllGroupsofUser(userId, _redisCache, dbr).Find(t => t.groupName.Equals(Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName)); List <Groupprofiles> defalutGroupProfiles = getGroupProfiles(defaultGroup.id, _redisCache, dbr); if (defalutGroupProfiles != null && defalutGroupProfiles.Count(t => t.profileId.Equals(profileId)) <= 0) { switch (grpProfile.profileType) { case Domain.Socioboard.Enum.SocialProfileType.Facebook: { res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage: { res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.FacebookPublicPage: { res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.Twitter: { res = TwitterRepository.DeleteProfile(dbr, profileId, userId, _redisCache); break; } case Domain.Socioboard.Enum.SocialProfileType.LinkedIn: { res = LinkedInAccountRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.LinkedInComapanyPage: { res = LinkedInAccountRepository.DeleteCompanyPageProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.Instagram: { res = InstagramRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.GoogleAnalytics: { res = GplusRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } case Domain.Socioboard.Enum.SocialProfileType.GPlus: { res = GplusRepository.DeleteGplusProfile(dbr, profileId, userId, _redisCache, _appSettings); break; } } } else { res = "Deleted"; } } if (res.Equals("Deleted")) { dbr.Delete <Domain.Socioboard.Models.Groupprofiles>(grpProfile); _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId); _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId); return("Deleted"); } else { if (grpProfile != null) { dbr.Delete <Domain.Socioboard.Models.Groupprofiles>(grpProfile); _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId); _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId); return("Deleted"); } return(res); } } else { return("Issue while deleting Profile"); } }
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(); } }