public static string AddInstagramAccount(string client_id, string client_secret, string redirect_uri, string code, long userId, long groupId, Model.DatabaseRepository dbr, ILogger _logger, Helper.Cache _redisCache, Helper.AppSettings _appSettings)
        {
            string           ret      = string.Empty;
            oAuthInstagram   objInsta = new oAuthInstagram();
            ConfigurationIns configi  = new ConfigurationIns("https://api.instagram.com/oauth/authorize/", client_id, client_secret, redirect_uri, "https://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram   _api     = new oAuthInstagram();

            _api = oAuthInstagram.GetInstance(configi);
            AccessToken access = new AccessToken();

            access = _api.AuthGetAccessToken(code);
            UserController objusercontroller = new UserController();

            if (access != null)
            {
                Domain.Socioboard.Models.Instagramaccounts Instagramaccounts = new Domain.Socioboard.Models.Instagramaccounts();
                Domain.Socioboard.Models.Instagramaccounts objInstagramAccount;
                #region InstagramAccount
                InstagramResponse <User> objuser = objusercontroller.GetUserDetails(access.user.id, access.access_token);

                objInstagramAccount             = new Domain.Socioboard.Models.Instagramaccounts();
                objInstagramAccount.AccessToken = access.access_token;
                objInstagramAccount.InstagramId = access.user.id;
                try
                {
                    objInstagramAccount.bio = access.user.bio;
                }
                catch {
                    objInstagramAccount.bio = "";
                }
                try
                {
                    objInstagramAccount.ProfileUrl = access.user.profile_picture;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.InsUserName = access.user.username;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.TotalImages = objuser.data.counts.media;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.FollowedBy = objuser.data.counts.followed_by;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.Followers = objuser.data.counts.follows;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                objInstagramAccount.UserId     = userId;
                objInstagramAccount.IsActive   = true;
                objInstagramAccount.lastUpdate = DateTime.UtcNow;
                if (objInstagramAccount.InstagramId != null)
                {
                    Instagramaccounts = Api.Socioboard.Repositories.InstagramRepository.getInstagramAccount(objInstagramAccount.InstagramId, _redisCache, dbr);
                    if (Instagramaccounts != null && Instagramaccounts.IsActive == true)
                    {
                        return("This Account is added by some body else.");
                    }
                }
                else
                {
                    return("Issue while fetching instagram userId");
                }

                if (Instagramaccounts == null)
                {
                    int isSaved = dbr.Add <Domain.Socioboard.Models.Instagramaccounts>(objInstagramAccount);
                    if (isSaved == 1)
                    {
                        List <Domain.Socioboard.Models.Instagramaccounts> lstinsAcc = dbr.Find <Domain.Socioboard.Models.Instagramaccounts>(t => t.InstagramId.Equals(objInstagramAccount.InstagramId)).ToList();
                        if (lstinsAcc != null && lstinsAcc.Count() > 0)
                        {
                            isSaved = GroupProfilesRepository.AddGroupProfile(groupId, lstinsAcc.First().InstagramId, lstinsAcc.First().InsUserName, userId, lstinsAcc.First().ProfileUrl, Domain.Socioboard.Enum.SocialProfileType.Instagram, dbr);
                            if (isSaved == 1)
                            {
                                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);

                                GetInstagramSelfFeeds(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _appSettings);
                                GetInstagramUserDetails(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _redisCache, dbr);
                                GetInstagramFollowing(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                GetInstagramFollower(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                new Thread(delegate()
                                {
                                    GetInstagramPostLikes(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                    GetInstagramPostComments(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _appSettings);
                                }).Start();

                                return("Added_Successfully");
                            }
                        }
                    }
                }
                else
                {
                    objInstagramAccount.id = Instagramaccounts.id;
                    int isSaved = dbr.Update <Domain.Socioboard.Models.Instagramaccounts>(objInstagramAccount);
                    if (isSaved == 1)
                    {
                        List <Domain.Socioboard.Models.Instagramaccounts> lstinsAcc = dbr.Find <Domain.Socioboard.Models.Instagramaccounts>(t => t.InstagramId.Equals(objInstagramAccount.InstagramId)).ToList();
                        if (lstinsAcc != null && lstinsAcc.Count() > 0)
                        {
                            isSaved = GroupProfilesRepository.AddGroupProfile(groupId, lstinsAcc.First().InstagramId, lstinsAcc.First().InsUserName, userId, lstinsAcc.First().ProfileUrl, Domain.Socioboard.Enum.SocialProfileType.Instagram, dbr);
                            if (isSaved == 1)
                            {
                                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);


                                //todo : codes to update feeds
                                GetInstagramSelfFeeds(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _appSettings);
                                GetInstagramUserDetails(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _redisCache, dbr);
                                GetInstagramFollowing(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                GetInstagramFollower(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                new Thread(delegate()
                                {
                                    GetInstagramPostLikes(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                    GetInstagramPostComments(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _appSettings);
                                }).Start();



                                return("Added_Successfully");
                            }
                        }
                    }
                }
            }
            return("issue in access token fetching");

            #endregion
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public static int AddGaSites(string profiledata, long userId, long groupId, Helper.Cache _redisCache, Helper.AppSettings _appSettings, Model.DatabaseRepository dbr, IHostingEnvironment _appEnv)
        {
            int       isSaved    = 0;
            Analytics _Analytics = new Analytics(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri);

            Domain.Socioboard.Models.GoogleAnalyticsAccount _GoogleAnalyticsAccount;
            string[] GAdata = Regex.Split(profiledata, "<:>");
            _GoogleAnalyticsAccount = Repositories.GplusRepository.getGAAccount(GAdata[5], _redisCache, dbr);

            if (_GoogleAnalyticsAccount != null && _GoogleAnalyticsAccount.IsActive == false)
            {
                try
                {
                    _GoogleAnalyticsAccount.UserId          = userId;
                    _GoogleAnalyticsAccount.IsActive        = true;
                    _GoogleAnalyticsAccount.EntryDate       = DateTime.UtcNow;
                    _GoogleAnalyticsAccount.EmailId         = GAdata[4];
                    _GoogleAnalyticsAccount.GaAccountId     = GAdata[2];
                    _GoogleAnalyticsAccount.GaAccountName   = GAdata[3];
                    _GoogleAnalyticsAccount.GaWebPropertyId = GAdata[7];
                    _GoogleAnalyticsAccount.GaProfileId     = GAdata[5];
                    _GoogleAnalyticsAccount.GaProfileName   = GAdata[6];
                    _GoogleAnalyticsAccount.AccessToken     = GAdata[0];
                    _GoogleAnalyticsAccount.RefreshToken    = GAdata[1];
                    _GoogleAnalyticsAccount.WebsiteUrl      = GAdata[8];
                    string visits    = string.Empty;
                    string pageviews = string.Empty;
                    try
                    {
                        string  analytics = _Analytics.getAnalyticsData(GAdata[5], "ga:visits,ga:pageviews", DateTime.UtcNow.AddDays(-7).ToString("yyyy-MM-dd"), DateTime.UtcNow.ToString("yyyy-MM-dd"), GAdata[0]);
                        JObject JData     = JObject.Parse(analytics);
                        visits    = JData["totalsForAllResults"]["ga:visits"].ToString();
                        pageviews = JData["totalsForAllResults"]["ga:pageviews"].ToString();
                    }
                    catch (Exception ex)
                    {
                        visits    = "0";
                        pageviews = "0";
                    }
                    _GoogleAnalyticsAccount.Views         = Double.Parse(pageviews);
                    _GoogleAnalyticsAccount.Visits        = Double.Parse(visits);
                    _GoogleAnalyticsAccount.ProfilePicUrl = "https://www.socioboard.com/Contents/Socioboard/images/analytics_img.png";
                    _GoogleAnalyticsAccount.EntryDate     = DateTime.UtcNow;
                }
                catch (Exception ex)
                {
                }
                dbr.Update <Domain.Socioboard.Models.GoogleAnalyticsAccount>(_GoogleAnalyticsAccount);
            }
            else
            {
                try
                {
                    _GoogleAnalyticsAccount                 = new Domain.Socioboard.Models.GoogleAnalyticsAccount();
                    _GoogleAnalyticsAccount.UserId          = userId;
                    _GoogleAnalyticsAccount.IsActive        = true;
                    _GoogleAnalyticsAccount.EntryDate       = DateTime.UtcNow;
                    _GoogleAnalyticsAccount.EmailId         = GAdata[4];
                    _GoogleAnalyticsAccount.GaAccountId     = GAdata[2];
                    _GoogleAnalyticsAccount.GaAccountName   = GAdata[3];
                    _GoogleAnalyticsAccount.GaWebPropertyId = GAdata[7];
                    _GoogleAnalyticsAccount.GaProfileId     = GAdata[5];
                    _GoogleAnalyticsAccount.GaProfileName   = GAdata[6];
                    _GoogleAnalyticsAccount.AccessToken     = GAdata[0];
                    _GoogleAnalyticsAccount.RefreshToken    = GAdata[1];
                    _GoogleAnalyticsAccount.WebsiteUrl      = GAdata[8];
                    string visits    = string.Empty;
                    string pageviews = string.Empty;
                    try
                    {
                        string  analytics = _Analytics.getAnalyticsData(GAdata[5], "ga:visits,ga:pageviews", DateTime.UtcNow.AddDays(-7).ToString("yyyy-MM-dd"), DateTime.UtcNow.ToString("yyyy-MM-dd"), GAdata[0]);
                        JObject JData     = JObject.Parse(analytics);
                        visits    = JData["totalsForAllResults"]["ga:visits"].ToString();
                        pageviews = JData["totalsForAllResults"]["ga:pageviews"].ToString();
                    }
                    catch (Exception ex)
                    {
                        visits    = "0";
                        pageviews = "0";
                    }
                    _GoogleAnalyticsAccount.Views         = Double.Parse(pageviews);
                    _GoogleAnalyticsAccount.Visits        = Double.Parse(visits);
                    _GoogleAnalyticsAccount.ProfilePicUrl = "https://www.socioboard.com/Themes/Socioboard/Contents/img/analytics_img.png";
                    _GoogleAnalyticsAccount.EntryDate     = DateTime.UtcNow;
                }
                catch (Exception ex)
                {
                }
                isSaved = dbr.Add <Domain.Socioboard.Models.GoogleAnalyticsAccount>(_GoogleAnalyticsAccount);
            }

            if (isSaved == 1)
            {
                List <Domain.Socioboard.Models.GoogleAnalyticsAccount> lstgaAcc = dbr.Find <Domain.Socioboard.Models.GoogleAnalyticsAccount>(t => t.GaProfileId.Equals(_GoogleAnalyticsAccount.GaProfileId)).ToList();
                if (lstgaAcc != null && lstgaAcc.Count() > 0)
                {
                    isSaved = GroupProfilesRepository.AddGroupProfile(groupId, lstgaAcc.First().GaProfileId, lstgaAcc.First().GaProfileName, userId, lstgaAcc.First().ProfilePicUrl, Domain.Socioboard.Enum.SocialProfileType.GoogleAnalytics, dbr);
                    //codes to delete cache
                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                }
            }
            return(isSaved);
        }
        public static int AddLinkedInAccount(oAuthLinkedIn _oauth, dynamic profile, Model.DatabaseRepository dbr, Int64 userId, Int64 groupId, string accessToken, Helper.Cache _redisCache, Helper.AppSettings settings, ILogger _logger)
        {
            int isSaved = 0;

            Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount = Repositories.LinkedInAccountRepository.getLinkedInAccount(profile.id.ToString(), _redisCache, dbr);
            if (_LinkedInAccount != null && _LinkedInAccount.IsActive == false)
            {
                _LinkedInAccount.IsActive    = true;
                _LinkedInAccount.UserId      = userId;
                _LinkedInAccount.EmailId     = profile.email.ToString();
                _LinkedInAccount.OAuthToken  = accessToken;
                _LinkedInAccount.Connections = Convert.ToInt32(profile.connections.ToString());
                _LinkedInAccount.LastUpdate  = DateTime.UtcNow;
                isSaved = dbr.Update <Domain.Socioboard.Models.LinkedInAccount>(_LinkedInAccount);
            }
            else
            {
                _LinkedInAccount = new Domain.Socioboard.Models.LinkedInAccount();
                _LinkedInAccount.LinkedinUserId = profile.id.ToString();
                _LinkedInAccount.IsActive       = true;
                _LinkedInAccount.UserId         = userId;
                _LinkedInAccount.Connections    = Convert.ToInt32(profile.connections.ToString());
                _LinkedInAccount.LastUpdate     = DateTime.UtcNow;
                try
                {
                    _LinkedInAccount.EmailId = profile.email.ToString();
                }
                catch (Exception ex)
                {
                }
                _LinkedInAccount.LinkedinUserName = profile.first_name.ToString() + profile.last_name.ToString();
                _LinkedInAccount.OAuthToken       = _oauth.Token;
                _LinkedInAccount.OAuthSecret      = _oauth.TokenSecret;
                _LinkedInAccount.OAuthVerifier    = _oauth.Verifier;
                try
                {
                    _LinkedInAccount.ProfileImageUrl = profile.picture_url.ToString();
                }
                catch (Exception ex)
                {
                }
                try
                {
                    _LinkedInAccount.ProfileUrl = profile.profile_url.ToString();
                }
                catch (Exception ex)
                {
                }
                isSaved = dbr.Add <Domain.Socioboard.Models.LinkedInAccount>(_LinkedInAccount);
                if (isSaved == 1)
                {
                    List <Domain.Socioboard.Models.LinkedInAccount> lstliAcc = dbr.Find <Domain.Socioboard.Models.LinkedInAccount>(t => t.LinkedinUserId.Equals(_LinkedInAccount.LinkedinUserId)).ToList();
                    if (lstliAcc != null && lstliAcc.Count() > 0)
                    {
                        isSaved = GroupProfilesRepository.AddGroupProfile(groupId, lstliAcc.First().LinkedinUserId, lstliAcc.First().LinkedinUserName, userId, lstliAcc.First().ProfileImageUrl, Domain.Socioboard.Enum.SocialProfileType.LinkedIn, dbr);
                        if (isSaved == 1)
                        {
                            _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                            _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                        }
                    }
                }
            }
            return(isSaved);
        }
        public static int AddLinkedInCompantPage(oAuthLinkedIn _oauth, dynamic profile, Model.DatabaseRepository dbr, Int64 userId, Int64 groupId, string accesstoken, Helper.Cache _redisCache, Helper.AppSettings _appSettings, ILogger _logger)
        {
            int isSaved = 0;

            Domain.Socioboard.Models.LinkedinCompanyPage _LinkedInAccount = Repositories.LinkedInAccountRepository.getLinkedinCompanyPage(profile.Pageid.ToString(), _redisCache, dbr);
            if (_LinkedInAccount != null && _LinkedInAccount.IsActive == false)
            {
                _LinkedInAccount.IsActive         = true;
                _LinkedInAccount.UserId           = userId;
                _LinkedInAccount.EmailDomains     = profile.EmailDomains.ToString();
                _LinkedInAccount.OAuthToken       = accesstoken;
                _LinkedInAccount.LinkedinPageName = profile.name.ToString();
                _LinkedInAccount.lastUpdate       = DateTime.UtcNow;
                try
                {
                    string NuberOfFollower = profile.num_followers.ToString();
                    _LinkedInAccount.NumFollowers = Convert.ToInt16(NuberOfFollower);
                }
                catch { }
                try
                {
                    _LinkedInAccount.CompanyType = profile.company_type.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.LogoUrl = profile.logo_url.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.SquareLogoUrl = profile.square_logo_url.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.BlogRssUrl = profile.blog_rss_url.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.UniversalName = profile.universal_name.ToString();
                }
                catch { }
                isSaved = dbr.Update <Domain.Socioboard.Models.LinkedinCompanyPage>(_LinkedInAccount);
            }
            else
            {
                _LinkedInAccount = new Domain.Socioboard.Models.LinkedinCompanyPage();
                _LinkedInAccount.LinkedinPageId = profile.Pageid.ToString();
                _LinkedInAccount.IsActive       = true;
                _LinkedInAccount.UserId         = userId;
                _LinkedInAccount.lastUpdate     = DateTime.UtcNow;
                try
                {
                    _LinkedInAccount.EmailDomains = profile.EmailDomains.ToString();
                }
                catch (Exception ex)
                {
                }
                _LinkedInAccount.LinkedinPageName = profile.name.ToString();
                _LinkedInAccount.OAuthToken       = _oauth.Token;
                _LinkedInAccount.OAuthSecret      = _oauth.TokenSecret;
                _LinkedInAccount.OAuthVerifier    = _oauth.Verifier;
                try
                {
                    _LinkedInAccount.Description = profile.description.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.FoundedYear = profile.founded_year.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.EndYear = profile.end_year.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.Locations = profile.locations.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.Specialties = profile.Specialties.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.WebsiteUrl = profile.website_url.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.Status = profile.status.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.EmployeeCountRange = profile.employee_count_range.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.Industries = profile.industries.ToString();
                }
                catch { }
                try
                {
                    string NuberOfFollower = profile.num_followers.ToString();
                    _LinkedInAccount.NumFollowers = Convert.ToInt16(NuberOfFollower);
                }
                catch { }
                try
                {
                    _LinkedInAccount.CompanyType = profile.company_type.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.LogoUrl = profile.logo_url.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.SquareLogoUrl = profile.square_logo_url.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.BlogRssUrl = profile.blog_rss_url.ToString();
                }
                catch { }
                try
                {
                    _LinkedInAccount.UniversalName = profile.universal_name.ToString();
                }
                catch { }
                isSaved = dbr.Add <Domain.Socioboard.Models.LinkedinCompanyPage>(_LinkedInAccount);
                if (isSaved == 1)
                {
                    List <Domain.Socioboard.Models.LinkedinCompanyPage> lstliAcc = dbr.Find <Domain.Socioboard.Models.LinkedinCompanyPage>(t => t.LinkedinPageId.Equals(_LinkedInAccount.LinkedinPageId)).ToList();
                    if (lstliAcc != null && lstliAcc.Count() > 0)
                    {
                        isSaved = GroupProfilesRepository.AddGroupProfile(groupId, lstliAcc.First().LinkedinPageId, lstliAcc.First().LinkedinPageName, userId, lstliAcc.First().LogoUrl, Domain.Socioboard.Enum.SocialProfileType.LinkedInComapanyPage, dbr);
                        if (isSaved == 1)
                        {
                            _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                            _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                            new Thread(delegate()
                            {
                                LinkedInAccountRepository.SaveLinkedInCompanyPageFeed(_oauth, lstliAcc.First().LinkedinPageId, lstliAcc.First().UserId, _appSettings);
                            }).Start();
                        }
                    }
                }
            }
            return(isSaved);
        }
Beispiel #6
0
        public static int AddYoutubeChannels(string profiledata, long userId, long groupId, Helper.Cache _redisCache, Helper.AppSettings _appSettings, Model.DatabaseRepository dbr, IHostingEnvironment _appEnv)
        {
            int      isSaved   = 0;
            Channels _Channels = new Channels("575089347457-74q0u81gj88ve5bfdmbklcf2dnc0353q.apps.googleusercontent.com", "JRtS_TaeYpKOJWBCqt9h8-iG", "http://localhost:9821/GoogleManager/Google");

            Domain.Socioboard.Models.YoutubeChannel _YoutubeChannel;
            string[] YTdata = Regex.Split(profiledata, "<:>");
            _YoutubeChannel = Repositories.GplusRepository.getYTChannel(YTdata[2], _redisCache, dbr);


            if (_YoutubeChannel != null)
            {
                try
                {
                    _YoutubeChannel.UserId                  = userId;
                    _YoutubeChannel.YtubeChannelId          = YTdata[2];
                    _YoutubeChannel.YtubeChannelName        = YTdata[3];
                    _YoutubeChannel.ChannelpicUrl           = YTdata[9];
                    _YoutubeChannel.WebsiteUrl              = "https://www.youtube.com/channel/" + YTdata[2];
                    _YoutubeChannel.EntryDate               = DateTime.UtcNow;
                    _YoutubeChannel.YtubeChannelDescription = YTdata[4];
                    _YoutubeChannel.IsActive                = true;
                    _YoutubeChannel.AccessToken             = YTdata[0];
                    _YoutubeChannel.RefreshToken            = YTdata[1];
                    _YoutubeChannel.PublishingDate          = Convert.ToDateTime(YTdata[5]);
                    _YoutubeChannel.VideosCount             = Convert.ToDouble(YTdata[8]);
                    _YoutubeChannel.CommentsCount           = Convert.ToDouble(YTdata[7]);
                    _YoutubeChannel.SubscribersCount        = Convert.ToDouble(YTdata[10]);
                    _YoutubeChannel.ViewsCount              = Convert.ToDouble(YTdata[6]);
                }
                catch (Exception ex)
                {
                }
                isSaved = dbr.Update <Domain.Socioboard.Models.YoutubeChannel>(_YoutubeChannel);
            }
            else
            {
                _YoutubeChannel = new Domain.Socioboard.Models.YoutubeChannel();
                try
                {
                    _YoutubeChannel.UserId                  = userId;
                    _YoutubeChannel.YtubeChannelId          = YTdata[2];
                    _YoutubeChannel.YtubeChannelName        = YTdata[3];
                    _YoutubeChannel.ChannelpicUrl           = YTdata[9];
                    _YoutubeChannel.WebsiteUrl              = "https://www.youtube.com/channel/" + YTdata[2];
                    _YoutubeChannel.EntryDate               = DateTime.UtcNow;
                    _YoutubeChannel.YtubeChannelDescription = YTdata[4];
                    _YoutubeChannel.IsActive                = true;
                    _YoutubeChannel.AccessToken             = YTdata[0];
                    _YoutubeChannel.RefreshToken            = YTdata[1];
                    _YoutubeChannel.PublishingDate          = Convert.ToDateTime(YTdata[5]);
                    _YoutubeChannel.VideosCount             = Convert.ToDouble(YTdata[8]);
                    _YoutubeChannel.CommentsCount           = Convert.ToDouble(YTdata[7]);
                    _YoutubeChannel.SubscribersCount        = Convert.ToDouble(YTdata[10]);
                    _YoutubeChannel.ViewsCount              = Convert.ToDouble(YTdata[6]);
                }
                catch (Exception ex)
                {
                }
                isSaved = dbr.Add <Domain.Socioboard.Models.YoutubeChannel>(_YoutubeChannel);
            }

            if (isSaved == 1)
            {
                List <Domain.Socioboard.Models.YoutubeChannel> lstytChannel = dbr.Find <Domain.Socioboard.Models.YoutubeChannel>(t => t.YtubeChannelId.Equals(_YoutubeChannel.YtubeChannelId)).ToList();
                if (lstytChannel != null && lstytChannel.Count() > 0)
                {
                    isSaved = GroupProfilesRepository.AddGroupProfile(groupId, lstytChannel.First().YtubeChannelId, lstytChannel.First().YtubeChannelName, userId, lstytChannel.First().ChannelpicUrl, Domain.Socioboard.Enum.SocialProfileType.YouTube, dbr);
                    //codes to delete cache
                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                }
            }
            return(isSaved);
        }