/// <AddGroupProfile>
 /// Add a new group profile
 /// </summary>
 /// <param name="group">Set Values in a GroupProfile Class Property and Pass the same Object of GroupProfile Class.(Domain.GroupProfile)</param>
 public void AddGroupProfile(Domain.Socioboard.Domain.GroupProfile group)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             //Proceed action to save data.
             session.Save(group);
             transaction.Commit();
         } //End Transaction
     }     //End Session
 }
 /// <UpdateGroupProfile>
 /// Update the details of group profile
 /// </summary>
 /// <param name="group">Set Values in a GroupProfile Class Property and Pass the same Object of GroupProfile Class.(Domain.GroupProfile)</param>
 public void UpdateGroupProfile(Domain.Socioboard.Domain.GroupProfile group)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 //Proceed action, to update specific data by user id.
                 session.CreateQuery("Update GroupProfiles set EntryDate =:entrydate where Id = :userid")
                 .SetParameter("userid", group.Id)
                 .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 // return 0;
             }
         } //End Transaction
     }     //End Session
 }
Example #3
0
        public string AddTumblrAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string code)
        {
            string ret = string.Empty;
            string AccessTokenResponse = string.Empty;

            try
            {
                oAuthTumbler requestHelper = new oAuthTumbler();
                oAuthTumbler.TumblrConsumerKey    = client_id;
                oAuthTumbler.TumblrConsumerSecret = client_secret;
                requestHelper.TumblrCallBackUrl   = redirect_uri;
                AccessTokenResponse = requestHelper.GetAccessToken(oAuthTumbler.TumblrToken, code);
                logger.Error(AccessTokenResponse);

                string[] tokens = AccessTokenResponse.Split('&'); //extract access token & secret from response
                logger.Error(tokens);
                string accessToken = tokens[0].Split('=')[1];
                logger.Error(accessToken);
                string accessTokenSecret = tokens[1].Split('=')[1];
                logger.Error(accessTokenSecret);

                KeyValuePair <string, string> LoginDetails = new KeyValuePair <string, string>(accessToken, accessTokenSecret);

                JObject profile = new JObject();
                try
                {
                    profile = JObject.Parse(oAuthTumbler.OAuthData(Globals.UsersInfoUrl, "GET", LoginDetails.Key, LoginDetails.Value, null));
                }
                catch (Exception ex)
                {
                }


                #region Add Tumblr Account
                objTumblrAccount                       = new Domain.Socioboard.Domain.TumblrAccount();
                objTumblrAccount.Id                    = Guid.NewGuid();
                objTumblrAccount.tblrUserName          = profile["response"]["user"]["name"].ToString();
                objTumblrAccount.UserId                = Guid.Parse(UserId);
                objTumblrAccount.tblrAccessToken       = accessToken;
                objTumblrAccount.tblrAccessTokenSecret = accessTokenSecret;
                objTumblrAccount.tblrProfilePicUrl     = "http://api.tumblr.com/v2/blog/" + objTumblrAccount.tblrUserName + ".tumblr.com/avatar";//profile["response"]["user"]["name"].ToString();
                objTumblrAccount.IsActive              = 1;
                if (!objTumblrAccountRepository.checkTubmlrUserExists(objTumblrAccount))
                {
                    TumblrAccountRepository.Add(objTumblrAccount);

                    #region Add Socialprofiles
                    objSocialProfile               = new Domain.Socioboard.Domain.SocialProfile();
                    objSocialProfile.Id            = Guid.NewGuid();
                    objSocialProfile.UserId        = Guid.Parse(UserId);
                    objSocialProfile.ProfileId     = profile["response"]["user"]["name"].ToString();
                    objSocialProfile.ProfileType   = "tumblr";
                    objSocialProfile.ProfileDate   = DateTime.Now;
                    objSocialProfile.ProfileStatus = 1;
                    if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                    {
                        objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    }
                    #endregion

                    #region Add TeamMemeberProfile
                    //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                    //Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                    //objTeamMemberProfile.Id = Guid.NewGuid();
                    //objTeamMemberProfile.TeamId = objTeam.Id;
                    //objTeamMemberProfile.Status = 1;
                    //objTeamMemberProfile.ProfileType = "tumblr";
                    //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                    //objTeamMemberProfile.ProfileId = objTumblrAccount.tblrUserName;

                    ////Modified [13-02-15]
                    //objTeamMemberProfile.ProfilePicUrl = objTumblrAccount.tblrProfilePicUrl;
                    //objTeamMemberProfile.ProfileName = objTumblrAccount.tblrUserName;

                    //objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);


                    Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
                    grpProfile.Id           = Guid.NewGuid();
                    grpProfile.EntryDate    = DateTime.UtcNow;
                    grpProfile.GroupId      = Guid.Parse(GroupId);
                    grpProfile.GroupOwnerId = Guid.Parse(UserId);
                    grpProfile.ProfileId    = objTumblrAccount.tblrUserName;
                    grpProfile.ProfileType  = "tumblr";
                    grpProfile.ProfileName  = objTumblrAccount.tblrUserName;
                    grpProfile.ProfilePic   = objTumblrAccount.tblrProfilePicUrl;
                    grpProfileRepo.AddGroupProfile(grpProfile);
                    #endregion
                }
                #endregion


                //if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeam.Id, objTumblrAccount.tblrUserName))
                //{
                //    objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                //}

                #region Add Tumblr Feeds
                AddTunblrFeeds(UserId, LoginDetails, profile["response"]["user"]["name"].ToString());
                #endregion
            }
            catch (Exception ex)
            {
                logger.Error("AddTumblrAccount => " + ex.StackTrace);
            }
            return(ret);
        }
        public void GetPageProfile(dynamic data, oAuthLinkedIn _OAuth, string UserId, string CompanyPageId, string GroupId)
        {
            Domain.Socioboard.Domain.SocialProfile socioprofile = new Domain.Socioboard.Domain.SocialProfile();
            SocialProfilesRepository socioprofilerepo = new SocialProfilesRepository();
            Domain.Socioboard.Domain.LinkedinCompanyPage objLinkedincmpnypage = new Domain.Socioboard.Domain.LinkedinCompanyPage();
            LinkedinCompanyPageRepository objLinkedCmpnyPgeRepo = new LinkedinCompanyPageRepository();
            Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();

            try
            {
                objLinkedincmpnypage.UserId = Guid.Parse(UserId);
                try
                {
                    objLinkedincmpnypage.LinkedinPageId = data.Pageid.ToString();
                }
                catch
                {
                }
                objLinkedincmpnypage.Id = Guid.NewGuid();
                try
                {
                    objLinkedincmpnypage.EmailDomains = data.EmailDomains.ToString();
                }
                catch { }
                objLinkedincmpnypage.LinkedinPageName = data.name.ToString();
                objLinkedincmpnypage.OAuthToken = _OAuth.Token;
                objLinkedincmpnypage.OAuthSecret = _OAuth.TokenSecret;
                objLinkedincmpnypage.OAuthVerifier = _OAuth.Verifier;
                try
                {
                    objLinkedincmpnypage.Description = data.description.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.FoundedYear = data.founded_year.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.EndYear = data.end_year.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.Locations = data.locations.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.Specialties = data.Specialties.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.WebsiteUrl = data.website_url.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.Status = data.status.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.EmployeeCountRange = data.employee_count_range.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.Industries = data.industries.ToString();
                }
                catch { }
                try
                {
                    string NuberOfFollower = data.num_followers.ToString();
                    objLinkedincmpnypage.NumFollowers = Convert.ToInt16(NuberOfFollower);
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.CompanyType = data.company_type.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.LogoUrl = data.logo_url.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.SquareLogoUrl = data.square_logo_url.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.BlogRssUrl = data.blog_rss_url.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.UniversalName = data.universal_name.ToString();
                }
                catch { }
                #region SocialProfiles
                socioprofile.UserId = Guid.Parse(UserId);
                socioprofile.ProfileType = "linkedincompanypage";
                socioprofile.ProfileId = data.Pageid.ToString(); ;
                socioprofile.ProfileStatus = 1;
                socioprofile.ProfileDate = DateTime.Now;
                socioprofile.Id = Guid.NewGuid();
                #endregion

                #region TeamMemberProfile
                //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                //objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                //objTeamMemberProfile.Id = Guid.NewGuid();
                //objTeamMemberProfile.TeamId = objTeam.Id;
                //objTeamMemberProfile.Status = 1;
                //objTeamMemberProfile.ProfileType = "linkedincompanypage";
                //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                //objTeamMemberProfile.ProfileId = socioprofile.ProfileId;


                grpProfile.Id = Guid.NewGuid();
                grpProfile.EntryDate = DateTime.UtcNow;
                grpProfile.GroupId = Guid.Parse(GroupId);
                grpProfile.GroupOwnerId = Guid.Parse(UserId);
                grpProfile.ProfileId = socioprofile.ProfileId;
                grpProfile.ProfileType = "linkedincompanypage";
               // grpProfile.ProfilePic 
                #endregion
            }
            catch
            {
            }
            try
            {
                if (!objSocialProfilesRepository.checkUserProfileExist(socioprofile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(socioprofile);
                }
                //if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeamMemberProfile.TeamId, objLinkedincmpnypage.LinkedinPageId))
                //{
                //    objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                //}
                if (!grpProfileRepo.checkProfileExistsingroup(Guid.Parse(GroupId), socioprofile.ProfileId))
                {
                    //    objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                    grpProfileRepo.AddGroupProfile(grpProfile);

                }

                if (!objLinkedCmpnyPgeRepo.checkLinkedinPageExists(CompanyPageId, Guid.Parse(UserId)))
                {
                    objLinkedCmpnyPgeRepo.addLinkenCompanyPage(objLinkedincmpnypage);
                }
                else
                {
                    objLinkedincmpnypage.LinkedinPageId = CompanyPageId;
                    objLinkedCmpnyPgeRepo.updateLinkedinPage(objLinkedincmpnypage);
                }
            }
            catch
            {

            }

        }
        public void getFacebookUserProfile(dynamic data, string accesstoken, long friends, Guid user)
        {
            SocialProfile socioprofile = new SocialProfile();
            //SocialProfilesRepository socioprofilerepo = new SocialProfilesRepository();
            Api.SocialProfile.SocialProfile ApiObjSocialProfile = new Api.SocialProfile.SocialProfile();
            FacebookAccount fbAccount = new FacebookAccount();
            //FacebookAccountRepository fbrepo = new FacebookAccountRepository();
            Api.FacebookFeed.FacebookFeed ApiObjFacebookFeed = new Api.FacebookFeed.FacebookFeed();
            try
            {
                try
                {
                    fbAccount.AccessToken = accesstoken;
                }
                catch
                {
                }
                try
                {
                    fbAccount.EmailId = data["email"].ToString();
                }
                catch
                {
                }
                try
                {
                    fbAccount.FbUserId = data["id"].ToString();
                }
                catch
                {
                }

                try
                {
                    fbAccount.ProfileUrl = data["link"].ToString();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }


                try
                {
                    fbAccount.FbUserName = data["name"].ToString();
                }
                catch
                {
                }
                try
                {
                    fbAccount.Friends = Convert.ToInt32(friends);
                }
                catch
                {
                }
                try
                {
                    fbAccount.Id = Guid.NewGuid();
                }
                catch
                {
                }
                fbAccount.IsActive = 1;
                try
                {
                    if (HttpContext.Current.Session["fbSocial"] != null)
                    {
                        if (HttpContext.Current.Session["fbSocial"] == "p")
                        {
                            //FacebookClient fbClient = new FacebookClient(accesstoken);
                            //int fancountPage = 0;
                            //dynamic fancount = fbClient.Get("fql", new { q = " SELECT fan_count FROM page WHERE page_id =" + fbAccount.FbUserId });
                            //foreach (var friend in fancount.data)
                            //{
                            //    fancountPage = friend.fan_count;

                            //}
                            //fbAccount.Friends = Convert.ToInt32(fancountPage);
                            fbAccount.Type = "page";
                        }
                        else
                        {
                            fbAccount.Type = "account";
                        }
                        fbAccount.UserId = user;
                    }

                    if (HttpContext.Current.Session["UserAndGroupsForFacebook"] != null)
                    {
                        try
                        {
                            fbAccount.UserId = user;
                            fbAccount.Type = "account";
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                }
                catch
                {
                }

                #region unused
                //if (HttpContext.Current.Session["login"] != null)
                //{
                //    if (HttpContext.Current.Session["login"].ToString().Equals("facebook"))
                //    {
                //        User usr = new User();
                //        UserRepository userrepo = new UserRepository();
                //        Registration regObject = new Registration();
                //        usr.AccountType = "free";
                //        usr.CreateDate = DateTime.Now;
                //        usr.ExpiryDate = DateTime.Now.AddMonths(1);
                //        usr.Id = Guid.NewGuid();
                //        usr.UserName = data["name"].ToString();
                //        usr.Password = regObject.MD5Hash(data["name"].ToString());
                //        usr.EmailId = data["email"].ToString();
                //        usr.UserStatus = 1;
                //        if (!userrepo.IsUserExist(data["email"].ToString()))
                //        {
                //            UserRepository.Add(usr);
                //        }
                //    }
                //} 
                #endregion
                try
                {
                    socioprofile.UserId = user;
                }
                catch
                {
                }
                try
                {
                    socioprofile.ProfileType = "facebook";
                }
                catch
                {
                }
                try
                {
                    socioprofile.ProfileId = data["id"].ToString();
                }
                catch
                {
                }
                try
                {
                    socioprofile.ProfileStatus = 1;
                }
                catch
                {
                }
                try
                {
                    socioprofile.ProfileDate = DateTime.Now;
                }
                catch
                {
                }
                try
                {
                    socioprofile.Id = Guid.NewGuid();
                }
                catch
                {
                }
                if (HttpContext.Current.Session["fbSocial"] != null)
                {
                    if (HttpContext.Current.Session["fbSocial"] == "p")
                    {

                        HttpContext.Current.Session["fbpagedetail"] = fbAccount;
                    }
                    else
                    {
                        if (!fbrepo.checkFacebookUserExists(fbAccount.FbUserId, user))
                        {
                            fbrepo.addFacebookUser(fbAccount);
                            if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                            {
                               
                                socioprofilerepo.addNewProfileForUser(socioprofile);

                                GroupRepository objGroupRepository = new GroupRepository();
                                SocioBoard.Domain.Team team = (SocioBoard.Domain.Team)HttpContext.Current.Session["GroupName"];
                                Groups lstDetails = objGroupRepository.getGroupName(team.GroupId);
                                if (lstDetails.GroupName == "Socioboard")
                                {                                   
                                    TeamMemberProfileRepository objTeamMemberProfileRepository = new TeamMemberProfileRepository();                                  
                                    TeamMemberProfile teammemberprofile = new TeamMemberProfile();
                                    teammemberprofile.Id = Guid.NewGuid();
                                    teammemberprofile.TeamId = team.Id;
                                    teammemberprofile.ProfileId = fbAccount.FbUserId;
                                    teammemberprofile.ProfileType = "facebook";
                                    teammemberprofile.StatusUpdateDate = DateTime.Now;

                                    objTeamMemberProfileRepository.addNewTeamMember(teammemberprofile);

                                }




                            }
                            else
                            {
                                socioprofilerepo.updateSocialProfile(socioprofile);
                            }

                           

                        }
                        else
                        {
                            HttpContext.Current.Session["alreadyexist"] = fbAccount;
                            fbrepo.updateFacebookUser(fbAccount);
                            if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                            {
                                socioprofilerepo.addNewProfileForUser(socioprofile);
                            }
                            else
                            {
                                socioprofilerepo.updateSocialProfile(socioprofile);
                            }
                        }

                    }
                }

                if (HttpContext.Current.Session["UserAndGroupsForFacebook"] != null)
                {
                    if (HttpContext.Current.Session["UserAndGroupsForFacebook"].ToString() == "facebook")
                    {
                        try
                        {
                            if (!fbrepo.checkFacebookUserExists(fbAccount.FbUserId, user))
                            {
                                fbrepo.addFacebookUser(fbAccount);
                                if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                                {
                                    socioprofilerepo.addNewProfileForUser(socioprofile);
                                }
                                else
                                {
                                    socioprofilerepo.updateSocialProfile(socioprofile);
                                }
                            }
                            else
                            {
                                fbrepo.updateFacebookUser(fbAccount);
                                if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                                {
                                    socioprofilerepo.addNewProfileForUser(socioprofile);
                                }
                                else
                                {
                                    socioprofilerepo.updateSocialProfile(socioprofile);
                                }
                            
                            }
                            if (HttpContext.Current.Session["GroupName"] != null)
                            {
                                GroupProfile groupprofile = new GroupProfile();
                                GroupProfileRepository groupprofilerepo = new GroupProfileRepository();
                                Groups group = (Groups)HttpContext.Current.Session["GroupName"];
                                groupprofile.Id = Guid.NewGuid();
                                groupprofile.GroupOwnerId = user;
                                groupprofile.ProfileId = socioprofile.ProfileId;
                                groupprofile.ProfileType = "facebook";
                                groupprofile.GroupId = group.Id;
                                groupprofile.EntryDate = DateTime.Now;
                                if (!groupprofilerepo.checkGroupProfileExists(user, group.Id, groupprofile.ProfileId))
                                {
                                    groupprofilerepo.AddGroupProfile(groupprofile);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
        public string AddYoutubeAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string code)
        {
            #region Local variables Inisitalisation
            string ret = string.Empty;
            string objRefresh = string.Empty;
            string refreshToken = string.Empty;
            string access_token = string.Empty;
            oAuthTokenYoutube ObjoAuthTokenYoutube = new oAuthTokenYoutube();
            oAuthToken objToken = new oAuthToken();
            Domain.Socioboard.Domain.YoutubeAccount objYoutubeAccount = new Domain.Socioboard.Domain.YoutubeAccount();
            Domain.Socioboard.Domain.YoutubeChannel objYoutubeChannel;
            YoutubeChannelRepository objYoutubeChannelRepository = new YoutubeChannelRepository();
            YoutubeAccountRepository objYoutubeAccountRepository = new YoutubeAccountRepository();
            #endregion
            #region Get AccessToken and RefreshToken
            objToken.ConsumerKey = client_id;
            objToken.ConsumerSecret = client_secret;
            try
            {
                objRefresh = ObjoAuthTokenYoutube.GetRefreshToken(code, client_id, client_secret, redirect_uri);
                logger.Error("Abhay: ObjoAuthTokenYoutube()");
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
            }
            JObject objaccesstoken = JObject.Parse(objRefresh);
            try
            {
                refreshToken = objaccesstoken["refresh_token"].ToString();

            }
            catch (Exception ex)
            {
                access_token = objaccesstoken["access_token"].ToString();
                ObjoAuthTokenYoutube.RevokeToken(access_token);
                Console.WriteLine(ex.StackTrace);
                return "Refresh Token Not Found";
            }

            try
            {

                access_token = objaccesstoken["access_token"].ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);

            }
            #endregion
            #region Get user Profile and Add Youtube Account
            JArray userinfo = new JArray();
            try
            {
                userinfo = objToken.GetUserInfo("me", access_token.ToString());
            }
            catch (Exception ex)
            {
            }
            foreach (var itemEmail in userinfo)
            {
                try
                {
                    objYoutubeAccount.Id = Guid.NewGuid();
                    objYoutubeAccount.Ytuserid = itemEmail["id"].ToString();
                    objYoutubeAccount.Emailid = itemEmail["email"].ToString();
                    try
                    {
                        objYoutubeAccount.Ytusername = itemEmail["given_name"].ToString();
                    }
                    catch (Exception ex)
                    {
                        objYoutubeAccount.Ytusername = itemEmail["name"].ToString();
                    }
                    objYoutubeAccount.Ytprofileimage = itemEmail["picture"].ToString();
                    objYoutubeAccount.Accesstoken = access_token;
                    objYoutubeAccount.Refreshtoken = refreshToken;
                    objYoutubeAccount.Isactive = 1;
                    objYoutubeAccount.Entrydate = DateTime.Now;
                    objYoutubeAccount.UserId = Guid.Parse(UserId);
                    if (!objYoutubeAccountRepository.checkYoutubeUserExists(objYoutubeAccount))
                    {
                        YoutubeAccountRepository.Add(objYoutubeAccount);
                        ret = "Account Added Successfully";
                    }
                    else
                    {
                        ret = "Account already Exist !";
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }

            }


            #endregion
            #region Add Youtube Channels
            GlobusGooglePlusLib.Youtube.Core.Channels ObjChannel = new GlobusGooglePlusLib.Youtube.Core.Channels();
            JArray objarray = new JArray();
            try
            {
                string part = (oAuthTokenYoutube.Parts.contentDetails.ToString() + "," + oAuthTokenYoutube.Parts.statistics.ToString());
                string Value = ObjChannel.Get_Channel_List(access_token, part, 50, true);
                JObject UserChannels = JObject.Parse(@Value);
                objarray = (JArray)UserChannels["items"];
            }
            catch (Exception ex)
            {
            }

            foreach (var item in objarray)
            {
                objYoutubeChannel = new Domain.Socioboard.Domain.YoutubeChannel();
                try
                {
                    objYoutubeChannel.Id = Guid.NewGuid();
                    objYoutubeChannel.Channelid = item["id"].ToString();
                    objYoutubeChannel.Likesid = item["contentDetails"]["relatedPlaylists"]["likes"].ToString();
                    objYoutubeChannel.Favoritesid = item["contentDetails"]["relatedPlaylists"]["favorites"].ToString();
                    objYoutubeChannel.Uploadsid = item["contentDetails"]["relatedPlaylists"]["uploads"].ToString();
                    objYoutubeChannel.Watchhistoryid = item["contentDetails"]["relatedPlaylists"]["watchHistory"].ToString();
                    objYoutubeChannel.Watchlaterid = item["contentDetails"]["relatedPlaylists"]["watchLater"].ToString();
                    objYoutubeChannel.Googleplususerid = objYoutubeAccount.Ytuserid;
                    objYoutubeChannel.UserId = Guid.Parse(UserId);
                    try
                    {
                        string viewcnt = item["statistics"]["viewCount"].ToString();
                        objYoutubeChannel.ViewCount = Convert.ToInt32(viewcnt);
                        string videocnt = item["statistics"]["videoCount"].ToString();
                        objYoutubeChannel.VideoCount = Convert.ToInt32(videocnt);
                        string commentcnt = item["statistics"]["commentCount"].ToString();
                        objYoutubeChannel.CommentCount = Convert.ToInt32(commentcnt);
                        string Subscribercnt = item["statistics"]["subscriberCount"].ToString();
                        objYoutubeChannel.SubscriberCount = Convert.ToInt32(Subscribercnt);
                        try
                        {
                            string str = item["statistics"]["hiddenSubscriberCount"].ToString();
                            if (str == "false")
                            {
                                objYoutubeChannel.HiddenSubscriberCount = 0;
                            }
                            else
                            {
                                objYoutubeChannel.HiddenSubscriberCount = 1;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                if (!objYoutubeChannelRepository.checkYoutubeChannelExists(objYoutubeChannel.Channelid, Guid.Parse(UserId)))
                {
                    YoutubeChannelRepository.Add(objYoutubeChannel);
                }
            }
            #endregion
            #region Add TeamMemberProfile
            //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
            //Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
            //objTeamMemberProfile.Id = Guid.NewGuid();
            //objTeamMemberProfile.TeamId = objTeam.Id;
            //objTeamMemberProfile.Status = 1;
            //objTeamMemberProfile.ProfileType = "youtube";
            //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
            //objTeamMemberProfile.ProfileId = objYoutubeAccount.Ytuserid;

            //objTeamMemberProfile.ProfileName = objYoutubeAccount.Ytusername;
            //objTeamMemberProfile.ProfilePicUrl = objYoutubeAccount.Ytprofileimage;

            //if (!objTeamMemberProfileRepository.checkTeamMemberProfilebyType(objTeam.Id, objYoutubeAccount.Ytuserid, "youtube"))
            //{
            //    objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
            //}

            Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
            grpProfile.Id = Guid.NewGuid();
            grpProfile.EntryDate = DateTime.UtcNow;
            grpProfile.GroupId = Guid.Parse(GroupId);
            grpProfile.GroupOwnerId = Guid.Parse(UserId);
            grpProfile.ProfileId = objYoutubeAccount.Ytuserid;
            grpProfile.ProfileType = "youtube";
            grpProfile.ProfileName = objYoutubeAccount.Ytusername;
            grpProfile.ProfilePic = objYoutubeAccount.Ytprofileimage;


            #endregion
            #region SocialProfile
            Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
            objSocialProfile.Id = Guid.NewGuid();
            objSocialProfile.ProfileType = "youtube";
            objSocialProfile.ProfileId = objYoutubeAccount.Ytuserid;
            objSocialProfile.UserId = Guid.Parse(UserId);
            objSocialProfile.ProfileDate = DateTime.Now;
            objSocialProfile.ProfileStatus = 1;
            if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
            {
                grpProfileRepo.AddGroupProfile(grpProfile);
                objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
            }
            #endregion
            GetYoutubeChannelVideos(UserId, objYoutubeAccount.Ytuserid);
            return ret;
        }
        public string AddFacebookAccount(string code, string UserId, string GroupId)
        {
            string ret = string.Empty;
            string client_id = ConfigurationManager.AppSettings["ClientId"];
            string redirect_uri = ConfigurationManager.AppSettings["RedirectUrl"];
            string client_secret = ConfigurationManager.AppSettings["ClientSecretKey"];
            long friendscount = 0;
            try
            {
                FacebookClient fb = new FacebookClient();
                string profileId = string.Empty;
                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("client_id", client_id);
                parameters.Add("redirect_uri", redirect_uri);
                parameters.Add("client_secret", client_secret);
                parameters.Add("code", code);
                JsonObject fbaccess_token = null;
                try
                {
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                    fbaccess_token = (JsonObject)fb.Get("/oauth/access_token", parameters);

                }
                catch (Exception ex)
                {

                    try
                    {
                        fbaccess_token = (JsonObject)fb.Get("/oauth/access_token", parameters);
                    }
                    catch (Exception ex1)
                    {
                        return "issue_access_token";
                    }
                }

                string accessToken = fbaccess_token["access_token"].ToString();
                if (accessToken != null)
                {
                    fb.AccessToken = accessToken;
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                    dynamic profile = fb.Get("v2.0/me?fields=id,name,email");
                    dynamic friends = fb.Get("v2.0/me/friends");
                    try
                    {
                        friendscount = Convert.ToInt16(friends["summary"]["total_count"].ToString());
                    }
                    catch (Exception ex)
                    {
                        friendscount = 0;
                        logger.Error("friendscount >> " + ex.StackTrace);
                        logger.Error("friendscount >> " + friends.ToString());
                    }
                    if (!objFacebookAccountRepository.checkFacebookUserExists(Convert.ToString(profile["id"]), Guid.Parse(UserId)))
                    {
                        #region Add FacebookAccount
                        objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount();
                        objFacebookAccount.Id = Guid.NewGuid();
                        objFacebookAccount.FbUserId = (Convert.ToString(profile["id"]));
                        objFacebookAccount.FbUserName = (Convert.ToString(profile["name"]));
                        objFacebookAccount.AccessToken = accessToken;
                        objFacebookAccount.Friends = Convert.ToInt16(friendscount);
                        try
                        {
                            objFacebookAccount.EmailId = (Convert.ToString(profile["email"]));
                        }
                        catch { }
                        objFacebookAccount.Type = "account";
                        try
                        {
                            objFacebookAccount.ProfileUrl = (Convert.ToString(profile["link"]));
                        }
                        catch { }
                        objFacebookAccount.IsActive = 1;
                        objFacebookAccount.UserId = Guid.Parse(UserId);
                        objFacebookAccountRepository.addFacebookUser(objFacebookAccount);
                        if (!string.IsNullOrEmpty(objFacebookAccount.FbUserId))
                        {
                            ShareathonRepository shreathonpage = new ShareathonRepository();
                            ShareathonGroupRepository objShareathonGroup = new ShareathonGroupRepository();

                            if (shreathonpage.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId))
                            {
                                shreathonpage.UpadteShareathonByFacebookUserId(objFacebookAccount.FbUserId, objFacebookAccount.UserId);
                            }
                            if (objShareathonGroup.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId))
                            {
                                objShareathonGroup.UpadteShareathonByFacebookUserId(objFacebookAccount.FbUserId, objFacebookAccount.UserId);
                            }
                        }

                        #endregion
                        #region Add TeamMemberProfile

                        Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
                        grpProfile.Id = Guid.NewGuid();
                        grpProfile.GroupId = Guid.Parse(GroupId);
                        grpProfile.GroupOwnerId = Guid.Parse(UserId);
                        grpProfile.ProfileId = objFacebookAccount.FbUserId;
                        grpProfile.ProfileType = "facebook";
                        grpProfile.ProfileName = (Convert.ToString(profile["name"]));
                        grpProfile.EntryDate = DateTime.UtcNow;
                        grpProfile.ProfilePic = "http://graph.facebook.com/" + objFacebookAccount.FbUserId + "/picture?type=small";

                        #endregion
                        #region SocialProfile
                        Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                        objSocialProfile.Id = Guid.NewGuid();
                        objSocialProfile.ProfileType = "facebook";
                        objSocialProfile.ProfileId = (Convert.ToString(profile["id"]));
                        objSocialProfile.UserId = Guid.Parse(UserId);
                        objSocialProfile.ProfileDate = DateTime.Now;
                        objSocialProfile.ProfileStatus = 1;
                        #endregion
                        if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                        {
                            objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                            grpProfileRepo.AddGroupProfile(grpProfile);
                        }
                        #region Add Facebook Feeds
                        AddFacebookFeeds(UserId, fb, profile);
                        #endregion

                        ret = "Account Added Successfully";

                        ret = new JavaScriptSerializer().Serialize(objFacebookAccount);

                    }
                    else
                    {
                        objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(Convert.ToString(profile["id"]), Guid.Parse(UserId));
                        if (objFacebookAccount.IsActive == 2)
                        {
                            objFacebookAccount.IsActive = 1;
                            objFacebookAccount.AccessToken = accessToken;
                            objFacebookAccountRepository.updateFacebookUser(objFacebookAccount);

                            Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                            objSocialProfile.Id = Guid.NewGuid();
                            objSocialProfile.ProfileType = "facebook";
                            objSocialProfile.ProfileId = objFacebookAccount.FbUserId;
                            objSocialProfile.UserId = Guid.Parse(UserId);
                            objSocialProfile.ProfileDate = DateTime.Now;
                            objSocialProfile.ProfileStatus = 1;
                            objSocialProfilesRepository.updateSocialProfileStatus(objSocialProfile);
                            ShareathonRepository shreathonpage = new ShareathonRepository();
                            if (shreathonpage.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId))
                            {
                                shreathonpage.UpadteShareathonByFacebookUserId(objFacebookAccount.FbUserId, objFacebookAccount.UserId);
                            }
                            ret = "Account Updated successfully !";
                        }
                        else
                        {
                            ret = "Account already Exist !";
                        }

                    }
                }
                //return new JavaScriptSerializer().Serialize(ret);
                return ret;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return "Something Went Wrong";
            }
        }
        public IHttpActionResult AddLinkedInAccount(LinkedInManager LinkedInManager)
        {
            string          ret        = "";
            string          UserId     = LinkedInManager.UserId;
            oAuthLinkedIn   _oauth     = new oAuthLinkedIn();
            LinkedInProfile objProfile = new LinkedInProfile();

            Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
            try
            {
                _oauth.ConsumerKey = ConfigurationManager.AppSettings["LinkedinApiKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }

            try
            {
                _oauth.ConsumerSecret = ConfigurationManager.AppSettings["LinkedinSecretKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }
            string access_token_Url      = "https://www.linkedin.com/uas/oauth2/accessToken";
            string access_token_postData = "grant_type=authorization_code&code=" + LinkedInManager.Code + "&redirect_uri=" + System.Web.HttpUtility.UrlEncode(ConfigurationManager.AppSettings["LinkedinCallBackURL"]) + "&client_id=" + ConfigurationManager.AppSettings["LinkedinApiKey"] + "&client_secret=" + ConfigurationManager.AppSettings["LinkedinSecretKey"];

            LinkedInProfile.UserProfile objUserProfile = new LinkedInProfile.UserProfile();
            string token     = _oauth.APIWebRequestAccessToken("POST", access_token_Url, access_token_postData);
            var    oathtoken = JObject.Parse(token);

            _oauth.Token = oathtoken["access_token"].ToString().TrimStart('"').TrimEnd('"');
            #region Get linkedin Profile data from Api
            try
            {
                _oauth.ConsumerKey = ConfigurationManager.AppSettings["LinkedinApiKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }

            try
            {
                _oauth.ConsumerSecret = ConfigurationManager.AppSettings["LinkedinSecretKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }
            try
            {
                objUserProfile = objProfile.GetUserProfile(_oauth);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }
            #endregion
            dynamic data = objUserProfile;
            try
            {
                #region LinkedInAccount
                objLinkedInAccount.UserId         = Guid.Parse(UserId);
                objLinkedInAccount.LinkedinUserId = data.id.ToString();
                try
                {
                    objLinkedInAccount.EmailId = data.email.ToString();
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
                objLinkedInAccount.LinkedinUserName = data.first_name.ToString() + data.last_name.ToString();
                objLinkedInAccount.OAuthToken       = _oauth.Token;
                objLinkedInAccount.OAuthSecret      = _oauth.TokenSecret;
                objLinkedInAccount.OAuthVerifier    = _oauth.Verifier;
                try
                {
                    objLinkedInAccount.ProfileImageUrl = data.picture_url.ToString();
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
                try
                {
                    objLinkedInAccount.ProfileUrl = data.profile_url.ToString();
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
                #endregion
                #region SocialProfiles
                try
                {
                    objLinkedInAccount.Connections = data.connections;
                    objLinkedInAccount.IsActive    = true;
                    objSocialProfile.UserId        = Guid.Parse(UserId);
                    objSocialProfile.ProfileType   = "linkedin";
                    objSocialProfile.ProfileId     = data.id.ToString();
                    objSocialProfile.ProfileStatus = 1;
                    objSocialProfile.ProfileDate   = DateTime.Now;
                    objSocialProfile.Id            = Guid.NewGuid();
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
                #endregion SocialProfiles
                #region Add TeamMemberProfile
                try
                {
                    //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(LinkedInManager.GroupId));
                    //objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                    //objTeamMemberProfile.Id = Guid.NewGuid();
                    //objTeamMemberProfile.TeamId = objTeam.Id;
                    //objTeamMemberProfile.Status = 1;
                    //objTeamMemberProfile.ProfileType = "linkedin";
                    //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                    //objTeamMemberProfile.ProfileId = objLinkedInAccount.LinkedinUserId;
                    //objTeamMemberProfile.ProfileName = objLinkedInAccount.LinkedinUserName;
                    //objTeamMemberProfile.ProfilePicUrl = objLinkedInAccount.ProfileImageUrl;

                    grpProfile.Id           = Guid.NewGuid();
                    grpProfile.GroupId      = Guid.Parse(LinkedInManager.GroupId);
                    grpProfile.GroupOwnerId = objLinkedInAccount.UserId;
                    grpProfile.ProfileId    = objLinkedInAccount.LinkedinUserId;
                    grpProfile.ProfileType  = "linkedin";
                    grpProfile.ProfileName  = objLinkedInAccount.LinkedinUserName;
                    grpProfile.EntryDate    = DateTime.UtcNow;
                    //grpProfileRepo.AddGroupProfile(grpProfile);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
                #endregion
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
            }
            try
            {
                if (!objLinkedInAccountRepository.checkLinkedinUserExists(objLinkedInAccount.LinkedinUserId, Guid.Parse(UserId)))
                {
                    objLinkedInAccountRepository.addLinkedinUser(objLinkedInAccount);
                    ret = "LinkedIn Account Added Successfully";
                }
                else
                {
                    ret = "LinkedIn Account Already Exist";
                }
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    grpProfileRepo.AddGroupProfile(grpProfile);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
            }
            return(Ok(ret));
        }
        public string AddFacebookPagesByUrl(string userid, string profileId, string groupId, string name)
        {
            logger.Error(userid + ", " + profileId + ", " + groupId + ", " + name);
            string ret = string.Empty;
            FacebookAccount _FacebookAccount = new FacebookAccount();
            string token = ConfigurationManager.AppSettings["AccessToken1"].ToString();
            try
            {
                #region fancount
                FacebookClient fb = new FacebookClient();
                fb.AccessToken = token;
                int fancountPage = 0;
                try
                {
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                    dynamic friends = fb.Get("v2.0/" + profileId);
                    fancountPage = Convert.ToInt32(friends["likes"].ToString());

                }
                catch (Exception)
                {
                    fancountPage = 0;
                    fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString();
                    try
                    {
                        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                        dynamic friends = fb.Get("v2.0/" + profileId);
                        fancountPage = Convert.ToInt32(friends["likes"].ToString());
                    }
                    catch (Exception ex)
                    {
                        fancountPage = 0;
                        fb.AccessToken = ConfigurationManager.AppSettings["AccessToken3"].ToString();
                        try
                        {
                            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                            dynamic friends = fb.Get("v2.0/" + profileId);
                            fancountPage = Convert.ToInt32(friends["likes"].ToString());
                        }
                        catch (Exception exx)
                        {
                            fancountPage = 0;
                            fb.AccessToken = ConfigurationManager.AppSettings["AccessToken4"].ToString();
                            try
                            {
                                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                                dynamic friends = fb.Get("v2.0/" + profileId);
                                fancountPage = Convert.ToInt32(friends["likes"].ToString());
                            }
                            catch (Exception exxx)
                            {
                                logger.Error("fancount : " + exxx.Message);
                            }
                        }
                    }
                }
                #endregion


                #region Add FacebookAccount
                objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount();
                objFacebookAccount.Id = Guid.NewGuid();
                objFacebookAccount.FbUserId = profileId;
                objFacebookAccount.FbUserName = name;
                objFacebookAccount.AccessToken = "";
                objFacebookAccount.Friends = Convert.ToInt32(fancountPage);
                objFacebookAccount.EmailId = "";
                objFacebookAccount.Type = "Page";
                objFacebookAccount.ProfileUrl = "";
                objFacebookAccount.IsActive = 1;
                objFacebookAccount.UserId = Guid.Parse(userid);
                if (!objFacebookAccountRepository.checkFacebookUserExists(objFacebookAccount.FbUserId, objFacebookAccount.UserId))
                {
                    objFacebookAccountRepository.addFacebookUser(objFacebookAccount);
                }
                if (!string.IsNullOrEmpty(objFacebookAccount.FbUserId))
                {
                    ShareathonRepository shreathonpage = new ShareathonRepository();
                    ShareathonGroupRepository objShareathonGroup = new ShareathonGroupRepository();
                    if (shreathonpage.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId))
                    {
                        shreathonpage.UpdateShareathonByFacebookPageId(objFacebookAccount.FbUserId, objFacebookAccount.UserId);
                    }
                    if (objShareathonGroup.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId))
                    {
                        objShareathonGroup.UpdateShareathonByFacebookPageId(objFacebookAccount.FbUserId, objFacebookAccount.UserId);
                    }
                }
                #endregion
                #region SocialProfile
                Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                objSocialProfile.Id = Guid.NewGuid();
                objSocialProfile.ProfileType = "facebook_page";
                objSocialProfile.ProfileId = profileId;
                objSocialProfile.UserId = Guid.Parse(userid);
                objSocialProfile.ProfileDate = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    #region Add TeamMemberProfile
                    Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
                    grpProfile.Id = Guid.NewGuid();
                    grpProfile.GroupId = Guid.Parse(groupId);
                    grpProfile.GroupOwnerId = objFacebookAccount.UserId;
                    grpProfile.ProfileId = objFacebookAccount.FbUserId;
                    grpProfile.ProfileType = "facebook_page";
                    grpProfile.ProfileName = name;
                    grpProfile.EntryDate = DateTime.UtcNow;
                    grpProfileRepo.AddGroupProfile(grpProfile);
                    #endregion
                }
                #endregion


                try
                {
                    logger.Error(" Token:" + token);
                    if (token != null)
                    {
                        FacebookClient _FacebookClient = new FacebookClient();
                        _FacebookClient.AccessToken = token;
                        dynamic profile = null;

                        try
                        {
                            profile = fb.Get("v2.0/" + profileId);
                            logger.Error("AddFacebookPagesByUrl Token 1");
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString();
                                profile = fb.Get("v2.0/" + profileId);
                            }
                            catch (Exception ex2)
                            {
                                try
                                {
                                    //fb.AccessToken = "CAAKYvwDVmnUBAAR2O9hxFkHzfNG8H6KbQLaiGFMRshJkbttdzhDeprklcb1yaV0rwtC7N8Xz1rsL1cykiRv2ouXtBUFxvOZCNnpFELnQGFV8jGUWjm1GYsZA40IKAORLGoAcSaa2lJkuuSoLBksB8LFPHI4cqW7VVqxgDwZCRwObxqR4Qp9QEDHxa7j1yoZD";
                                    fb.AccessToken = ConfigurationManager.AppSettings["AccessToken3"].ToString();
                                    profile = fb.Get("v2.0/" + profileId);
                                    logger.Error("AddFacebookPagesByUrl Token 3");
                                }
                                catch (Exception ex3)
                                {
                                    try
                                    {
                                        //fb.AccessToken = "CAAKYvwDVmnUBAFtZB8pvVrqYQonmq7MD90oNdoipDc0Te4onP2XlbZAYT4bzOZAKTr8jdhw0P1PclgLOtVxJ9g2qx4vxZAzh2CXqXAZBZAZBwkgWIVjc2B4rcXAp6O5B3gXqd8Ko5ITL9VCZCMOkMZCPc1hBsp0n8zgPt6e3Dd0vaodPBS8nMz7RD";
                                        fb.AccessToken = ConfigurationManager.AppSettings["AccessToken4"].ToString();
                                        profile = fb.Get("v2.0/" + profileId);
                                        logger.Error("AddFacebookPagesByUrl Token 4");
                                    }
                                    catch (Exception ex4)
                                    {
                                        logger.Error("Finally :" + fb.AccessToken);
                                        logger.Error(ex4.Message);

                                    }
                                }
                            }
                        }
                        new Thread(delegate()
                        {
                            AddFbPagePost(userid, fb.AccessToken, profileId);
                        }).Start();
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
            }
            return ret;
        }
        public string AddFacebookAccountWithlogin(string accessToken, string UserId, string GroupId)
        {
            string ret = string.Empty;
            string client_id = ConfigurationManager.AppSettings["ClientId"];
            string redirect_uri = ConfigurationManager.AppSettings["RedirectUrl"];
            string client_secret = ConfigurationManager.AppSettings["ClientSecretKey"];
            long friendscount = 0;
            try
            {
                FacebookClient fb = new FacebookClient();
                string profileId = string.Empty;
                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("client_id", client_id);
                parameters.Add("redirect_uri", redirect_uri);
                parameters.Add("client_secret", client_secret);
                if (accessToken != null)
                {
                    fb.AccessToken = accessToken;
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                    dynamic profile = fb.Get("v2.0/me");
                    dynamic friends = fb.Get("v2.0/me/friends");
                    try
                    {
                        friendscount = Convert.ToInt16(friends["summary"]["total_count"].ToString());
                    }
                    catch (Exception ex)
                    {
                        //try
                        //{
                        //    dynamic frndscount = fb.Get("fql", new { q = "SELECT friend_count FROM user WHERE uid=me()" });

                        //    foreach (var friend in frndscount.data)
                        //    {
                        //        frndscount = friend.friend_count;
                        //    }
                        //    friendscount = Convert.ToInt16(frndscount);
                        //}
                        //catch (Exception ex)
                        //{
                        //    friendscount = 0;
                        //    logger.Error(ex.Message);
                        //    logger.Error(ex.StackTrace);
                        //}

                        friendscount = 0;
                        logger.Error("friendscount >> " + ex.Message);
                        logger.Error("friendscount >> " + ex.StackTrace);
                        logger.Error("friendscount >> " + friends.ToString());
                        logger.Error("friendscount >> " + friends["paging"]["next"].ToString());
                    }
                    if (!objFacebookAccountRepository.checkFacebookUserExists(Convert.ToString(profile["id"]), Guid.Parse(UserId)))
                    {
                        #region Add FacebookAccount
                        objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount();
                        objFacebookAccount.Id = Guid.NewGuid();
                        objFacebookAccount.FbUserId = (Convert.ToString(profile["id"]));
                        objFacebookAccount.FbUserName = (Convert.ToString(profile["name"]));
                        objFacebookAccount.AccessToken = accessToken;
                        objFacebookAccount.Friends = Convert.ToInt16(friendscount);
                        try
                        {
                            objFacebookAccount.EmailId = (Convert.ToString(profile["email"]));
                        }
                        catch (Exception ex)
                        {

                        }
                        objFacebookAccount.Type = "account";
                        try
                        {
                            objFacebookAccount.ProfileUrl = (Convert.ToString(profile["link"]));
                        }
                        catch (Exception ex)
                        {
                        }
                        objFacebookAccount.IsActive = 1;
                        objFacebookAccount.UserId = Guid.Parse(UserId);
                        objFacebookAccountRepository.addFacebookUser(objFacebookAccount);
                        #endregion
                        #region Add TeamMemberProfile
                        //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                        //Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                        //objTeamMemberProfile.Id = Guid.NewGuid();
                        //objTeamMemberProfile.TeamId = objTeam.Id;
                        //objTeamMemberProfile.Status = 1;
                        //objTeamMemberProfile.ProfileType = "facebook";
                        //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                        //objTeamMemberProfile.ProfileId = Convert.ToString(profile["id"]);
                        //objTeamMemberProfile.ProfileName = (Convert.ToString(profile["name"]));
                        //objTeamMemberProfile.ProfilePicUrl = "http://graph.facebook.com/" + objTeamMemberProfile.ProfileId + "/picture?type=small";
                        //objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                        Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
                        grpProfile.Id = Guid.NewGuid();
                        grpProfile.GroupId = Guid.Parse(GroupId);
                        grpProfile.GroupOwnerId = Guid.Parse(UserId);
                        grpProfile.ProfileId = objFacebookAccount.FbUserId;
                        grpProfile.ProfileType = "facebook";
                        grpProfile.ProfileName = (Convert.ToString(profile["name"]));
                        grpProfile.EntryDate = DateTime.UtcNow;
                        grpProfile.ProfilePic = "http://graph.facebook.com/" + objFacebookAccount.FbUserId + "/picture?type=small";
                        #endregion
                        #region SocialProfile
                        Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                        objSocialProfile.Id = Guid.NewGuid();
                        objSocialProfile.ProfileType = "facebook";
                        objSocialProfile.ProfileId = (Convert.ToString(profile["id"]));
                        objSocialProfile.UserId = Guid.Parse(UserId);
                        objSocialProfile.ProfileDate = DateTime.Now;
                        objSocialProfile.ProfileStatus = 1;
                        #endregion
                        if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                        {
                            objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                        }
                        #region Add Facebook Feeds
                        AddFacebookFeeds(UserId, fb, profile);
                        #endregion
                        #region Add Facebook User Home
                        //AddFacebookUserHome(UserId, fb, profile);
                        #endregion
                        #region Add Facebook User Inbox Message
                        //AddFacebookMessage(UserId, fb, profile);
                        //AddFacebookMessageWithPagination(UserId, fb, profile);
                        #endregion
                        #region Add Facebook Stats
                        //AddFacebookStats(UserId, fb, profile);
                        #endregion
                        //getUserNotifications(UserId, fb, profile);
                        ret = "Account Added Successfully";

                        ret = new JavaScriptSerializer().Serialize(objFacebookAccount);

                    }
                    else
                    {
                        objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(Convert.ToString(profile["id"]), Guid.Parse(UserId));
                        if (objFacebookAccount.IsActive == 2)
                        {
                            objFacebookAccount.IsActive = 1;
                            objFacebookAccount.AccessToken = accessToken;
                            objFacebookAccountRepository.updateFacebookUser(objFacebookAccount);

                            Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                            objSocialProfile.Id = Guid.NewGuid();
                            objSocialProfile.ProfileType = "facebook";
                            objSocialProfile.ProfileId = objFacebookAccount.FbUserId;
                            objSocialProfile.UserId = Guid.Parse(UserId);
                            objSocialProfile.ProfileDate = DateTime.Now;
                            objSocialProfile.ProfileStatus = 1;
                            objSocialProfilesRepository.updateSocialProfileStatus(objSocialProfile);
                            ret = "Account Updated successfully !";
                        }
                        else
                        {
                            ret = "Account already Exist !";
                        }

                    }
                }
                //return new JavaScriptSerializer().Serialize(ret);
                return ret;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return "Something Went Wrong";
            }
        }
        public string AddFacebookPagesInfo(string facebookPage, string userid, string groupId)
        {
            List<Domain.Socioboard.Domain.AddFacebookPage> lstAddFacebookPage = (List<Domain.Socioboard.Domain.AddFacebookPage>)new JavaScriptSerializer().Deserialize(facebookPage, typeof(List<Domain.Socioboard.Domain.AddFacebookPage>));
            foreach (Domain.Socioboard.Domain.AddFacebookPage item in lstAddFacebookPage)
            {
                FacebookClient fb = new FacebookClient();
                fb.AccessToken = item.AccessToken;
                dynamic profile = fb.Get("v2.0/me");
                Domain.Socioboard.Domain.FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount();
                objFacebookAccount.FbUserId = item.ProfilePageId;
                objFacebookAccount.FbUserName = item.Name;
                objFacebookAccount.AccessToken = item.AccessToken;
                try
                {
                    objFacebookAccount.Friends = Int32.Parse(item.LikeCount);
                }
                catch (Exception ex)
                {
                    objFacebookAccount.Friends = 0;
                }
                objFacebookAccount.EmailId = item.Email;
                objFacebookAccount.Type = "Page";
                objFacebookAccount.ProfileUrl = "";
                objFacebookAccount.IsActive = 1;
                objFacebookAccount.UserId = Guid.Parse(userid);
                if (!objFacebookAccountRepository.checkFacebookUserExists(objFacebookAccount.FbUserId, objFacebookAccount.UserId))
                {
                    objFacebookAccountRepository.addFacebookUser(objFacebookAccount);
                }
                #region Add TeamMemberProfile
                Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
                grpProfile.Id = Guid.NewGuid();
                grpProfile.GroupId = Guid.Parse(groupId);
                grpProfile.GroupOwnerId = objFacebookAccount.UserId;
                grpProfile.ProfileId = objFacebookAccount.FbUserId;
                grpProfile.ProfileType = "facebook_page";
                grpProfile.ProfileName = objFacebookAccount.FbUserName;
                grpProfile.EntryDate = DateTime.UtcNow;
                #endregion
                #region SocialProfile
                Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                objSocialProfile.Id = Guid.NewGuid();
                objSocialProfile.ProfileType = "facebook_page";
                objSocialProfile.ProfileId = item.ProfilePageId;
                objSocialProfile.UserId = Guid.Parse(userid);
                objSocialProfile.ProfileDate = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    grpProfileRepo.AddGroupProfile(grpProfile);
                }
                #endregion
                ShareathonRepository shreathonpage = new ShareathonRepository();
                ShareathonGroupRepository objShareathonGroup = new ShareathonGroupRepository();
                if (shreathonpage.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId))
                {
                    shreathonpage.UpdateShareathonByFacebookPageId(objFacebookAccount.FbUserId, objFacebookAccount.UserId);
                }
                if (objShareathonGroup.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId))
                {
                    objShareathonGroup.UpdateShareathonByFacebookPageId(objFacebookAccount.FbUserId, objFacebookAccount.UserId);
                }
                new Thread(delegate()
                {
                    #region Add Facebook Feeds
                    AddFacebookFeeds(userid, fb, profile);
                    #endregion
                    getPageConversations(userid, fb, profile);
                    GetFacebookPageFeed(item.AccessToken, item.ProfilePageId);
                }).Start();

            }
            return "success";
        }
         public IHttpActionResult AddLinkedInAccount(LinkedInManager LinkedInManager)
        {
            string ret = "";
            string UserId = LinkedInManager.UserId;
            oAuthLinkedIn _oauth = new oAuthLinkedIn();
            LinkedInProfile objProfile = new LinkedInProfile();
            Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
            try
            {
                _oauth.ConsumerKey = ConfigurationManager.AppSettings["LinkedinApiKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }

            try
            {
                _oauth.ConsumerSecret = ConfigurationManager.AppSettings["LinkedinSecretKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }
            string access_token_Url = "https://www.linkedin.com/uas/oauth2/accessToken";
            string access_token_postData = "grant_type=authorization_code&code=" + LinkedInManager.Code + "&redirect_uri=" + System.Web.HttpUtility.UrlEncode(ConfigurationManager.AppSettings["LinkedinCallBackURL"]) + "&client_id=" + ConfigurationManager.AppSettings["LinkedinApiKey"] + "&client_secret=" + ConfigurationManager.AppSettings["LinkedinSecretKey"];
            LinkedInProfile.UserProfile objUserProfile = new LinkedInProfile.UserProfile();
            string token = _oauth.APIWebRequestAccessToken("POST", access_token_Url, access_token_postData);
            var oathtoken = JObject.Parse(token);
            _oauth.Token = oathtoken["access_token"].ToString().TrimStart('"').TrimEnd('"');
            #region Get linkedin Profile data from Api
            try
            {
                _oauth.ConsumerKey = ConfigurationManager.AppSettings["LinkedinApiKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }

            try
            {
                _oauth.ConsumerSecret = ConfigurationManager.AppSettings["LinkedinSecretKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }
            try
            {
                objUserProfile = objProfile.GetUserProfile(_oauth);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }
            #endregion
            dynamic data = objUserProfile;
            try
            {
                #region LinkedInAccount
                objLinkedInAccount.UserId = Guid.Parse(UserId);
                objLinkedInAccount.LinkedinUserId = data.id.ToString();
                try
                {
                    objLinkedInAccount.EmailId = data.email.ToString();
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
                objLinkedInAccount.LinkedinUserName = data.first_name.ToString() + data.last_name.ToString();
                objLinkedInAccount.OAuthToken = _oauth.Token;
                objLinkedInAccount.OAuthSecret = _oauth.TokenSecret;
                objLinkedInAccount.OAuthVerifier = _oauth.Verifier;
                try
                {
                    objLinkedInAccount.ProfileImageUrl = data.picture_url.ToString();
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
                try
                {
                    objLinkedInAccount.ProfileUrl = data.profile_url.ToString();
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
                #endregion
                #region SocialProfiles
                try
                {
                    objLinkedInAccount.Connections = data.connections;
                    objLinkedInAccount.IsActive = true;
                    objSocialProfile.UserId = Guid.Parse(UserId);
                    objSocialProfile.ProfileType = "linkedin";
                    objSocialProfile.ProfileId = data.id.ToString();
                    objSocialProfile.ProfileStatus = 1;
                    objSocialProfile.ProfileDate = DateTime.Now;
                    objSocialProfile.Id = Guid.NewGuid();
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
                #endregion SocialProfiles
                #region Add TeamMemberProfile
                try
                {
                    //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(LinkedInManager.GroupId));
                    //objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                    //objTeamMemberProfile.Id = Guid.NewGuid();
                    //objTeamMemberProfile.TeamId = objTeam.Id;
                    //objTeamMemberProfile.Status = 1;
                    //objTeamMemberProfile.ProfileType = "linkedin";
                    //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                    //objTeamMemberProfile.ProfileId = objLinkedInAccount.LinkedinUserId;
                    //objTeamMemberProfile.ProfileName = objLinkedInAccount.LinkedinUserName;
                    //objTeamMemberProfile.ProfilePicUrl = objLinkedInAccount.ProfileImageUrl;
                   
                    grpProfile.Id = Guid.NewGuid();
                    grpProfile.GroupId = Guid.Parse(LinkedInManager.GroupId);
                    grpProfile.GroupOwnerId = objLinkedInAccount.UserId;
                    grpProfile.ProfileId = objLinkedInAccount.LinkedinUserId;
                    grpProfile.ProfileType = "linkedin";
                    grpProfile.ProfileName = objLinkedInAccount.LinkedinUserName;
                    grpProfile.EntryDate = DateTime.UtcNow;
                    //grpProfileRepo.AddGroupProfile(grpProfile);

                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
                #endregion

            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
            }
            try
            {
                if (!objLinkedInAccountRepository.checkLinkedinUserExists(objLinkedInAccount.LinkedinUserId, Guid.Parse(UserId)))
                {
                    objLinkedInAccountRepository.addLinkedinUser(objLinkedInAccount);
                    ret = "LinkedIn Account Added Successfully";
                }
                else
                {
                    ret = "LinkedIn Account Already Exist";
                }
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    grpProfileRepo.AddGroupProfile(grpProfile);
                }
                

            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
            }
            return Ok(ret);
        }
Example #13
0
        private static async Task <ISocialSiteAccount> GetSocialAccountFromGroupProfile(Guid objUserid, Domain.Socioboard.Domain.GroupProfile objGroupProfile)
        {
            ISocialSiteAccount objSocialSiteAccount = null;
            string             accesstoken          = string.Empty;

            try {
                accesstoken = System.Web.HttpContext.Current.Session["access_token"].ToString();
            }
            catch { }

            if (objGroupProfile.ProfileType == "facebook" || objGroupProfile.ProfileType == "facebook_page")
            {
                //using (Api.FacebookAccount.FacebookAccount ApiobjFacebookAccount = new Api.FacebookAccount.FacebookAccount())
                //{
                //    ApiobjFacebookAccount.Timeout = 300000;
                //    objSocialSiteAccount = (FacebookAccount)(new JavaScriptSerializer().Deserialize(ApiobjFacebookAccount.getFacebookAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(FacebookAccount)));
                //}
                FacebookAccount     fbaccount  = new FacebookAccount();
                HttpResponseMessage fbresponse = await WebApiReq.GetReq("api/ApiFacebookAccount/GetFacebookAcoount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken);

                if (fbresponse.IsSuccessStatusCode)
                {
                    fbaccount = await fbresponse.Content.ReadAsAsync <Domain.Socioboard.Domain.FacebookAccount>();

                    objSocialSiteAccount = fbaccount;
                }
            }
            else if (objGroupProfile.ProfileType == "twitter")
            {
                //using (Api.TwitterAccount.TwitterAccount ApiobjTwitterAccount = new Api.TwitterAccount.TwitterAccount())
                //{

                //    ApiobjTwitterAccount.Timeout = 300000;
                //    objSocialSiteAccount = (TwitterAccount)(new JavaScriptSerializer().Deserialize(ApiobjTwitterAccount.GetTwitterAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(TwitterAccount)));

                //}
                TwitterAccount      twitterAcc      = new TwitterAccount();
                HttpResponseMessage twitterresponse = await WebApiReq.GetReq("api/ApiTwitterAccount/GetTwitterAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken);

                if (twitterresponse.IsSuccessStatusCode)
                {
                    twitterAcc = await twitterresponse.Content.ReadAsAsync <Domain.Socioboard.Domain.TwitterAccount>();

                    objSocialSiteAccount = twitterAcc;
                }
            }
            else if (objGroupProfile.ProfileType == "linkedin")
            {
                //using (Api.LinkedinAccount.LinkedinAccount ApiobjLinkedinAccount = new Api.LinkedinAccount.LinkedinAccount())
                //{

                //    ApiobjLinkedinAccount.Timeout = 300000;
                //    objSocialSiteAccount = (LinkedInAccount)(new JavaScriptSerializer().Deserialize(ApiobjLinkedinAccount.GetLinkedinAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(LinkedInAccount)));

                //}
                LinkedInAccount     LinkedinAcc      = new LinkedInAccount();
                HttpResponseMessage Linkedinresponse = await WebApiReq.GetReq("api/ApiLinkedinAccount/GetLinkedinAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken);

                if (Linkedinresponse.IsSuccessStatusCode)
                {
                    LinkedinAcc = await Linkedinresponse.Content.ReadAsAsync <Domain.Socioboard.Domain.LinkedInAccount>();

                    objSocialSiteAccount = LinkedinAcc;
                }
            }
            else if (objGroupProfile.ProfileType == "instagram")
            {
                //using (Api.InstagramAccount.InstagramAccount ApiobjInstagramAccount = new Api.InstagramAccount.InstagramAccount())
                //{
                //    objSocialSiteAccount = (InstagramAccount)(new JavaScriptSerializer().Deserialize(ApiobjInstagramAccount.UserInformation(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(InstagramAccount)));

                //}
                InstagramAccount    instAcc  = new InstagramAccount();
                HttpResponseMessage response = await WebApiReq.GetReq("api/ApiInstagramAccount/GetInstagramAccount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken);

                if (response.IsSuccessStatusCode)
                {
                    instAcc = await response.Content.ReadAsAsync <Domain.Socioboard.Domain.InstagramAccount>();

                    objSocialSiteAccount = instAcc;
                }
            }
            else if (objGroupProfile.ProfileType == "youtube")
            {
                //using (Api.YoutubeAccount.YoutubeAccount ApiobjYoutubeAccount = new Api.YoutubeAccount.YoutubeAccount())
                //{

                //    ApiobjYoutubeAccount.Timeout = 300000;
                //    objSocialSiteAccount = (YoutubeAccount)(new JavaScriptSerializer().Deserialize(ApiobjYoutubeAccount.GetYoutubeAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(YoutubeAccount)));

                //}

                YoutubeAccount      ytAcc    = new YoutubeAccount();
                HttpResponseMessage response = await WebApiReq.GetReq("api/ApiYoutubeAccount/GetYoutubeAccount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken);

                if (response.IsSuccessStatusCode)
                {
                    ytAcc = await response.Content.ReadAsAsync <Domain.Socioboard.Domain.YoutubeAccount>();

                    objSocialSiteAccount = ytAcc;
                }
            }
            else if (objGroupProfile.ProfileType == "tumblr")
            {
                //using (Api.TumblrAccount.TumblrAccount ApiobjTumblrAccount = new Api.TumblrAccount.TumblrAccount())
                //{

                //    ApiobjTumblrAccount.Timeout = 300000;
                //    objSocialSiteAccount = (TumblrAccount)(new JavaScriptSerializer().Deserialize(ApiobjTumblrAccount.GetTumblrAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(TumblrAccount)));

                //}
                TumblrAccount       ytAcc    = new TumblrAccount();
                HttpResponseMessage response = await WebApiReq.GetReq("api/ApiTumblrAccount/GetTumblrAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken);

                if (response.IsSuccessStatusCode)
                {
                    ytAcc = await response.Content.ReadAsAsync <Domain.Socioboard.Domain.TumblrAccount>();

                    objSocialSiteAccount = ytAcc;
                }
            }
            else if (objGroupProfile.ProfileType == "linkedincompanypage")
            {
                //using (Api.LinkedinCompanyPage.LinkedinCompanyPage objLinkedinCompanyPage = new Api.LinkedinCompanyPage.LinkedinCompanyPage())
                //{

                //    objLinkedinCompanyPage.Timeout = 300000;
                //    objSocialSiteAccount = (LinkedinCompanyPage)(new JavaScriptSerializer().Deserialize(objLinkedinCompanyPage.GetLinkedinCompanyPageDetailsByUserIdAndPageId(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(LinkedinCompanyPage)));
                //}

                LinkedinCompanyPage licompanypage = new LinkedinCompanyPage();
                HttpResponseMessage response      = await WebApiReq.GetReq("api/ApiLinkedinCompanyPage/GetLinkedinCompanyPageDetailsByUserIdAndPageId?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken);

                if (response.IsSuccessStatusCode)
                {
                    licompanypage = await response.Content.ReadAsAsync <Domain.Socioboard.Domain.LinkedinCompanyPage>();

                    objSocialSiteAccount = licompanypage;
                }
            }
            else if (objGroupProfile.ProfileType == "gplus")
            {
                //using (Api.GooglePlusAccount.GooglePlusAccount ApiobjGooglePlusAccount = new Api.GooglePlusAccount.GooglePlusAccount())
                //{

                //    ApiobjGooglePlusAccount.Timeout = 300000;
                //    objSocialSiteAccount = (GooglePlusAccount)(new JavaScriptSerializer().Deserialize(ApiobjGooglePlusAccount.GetGooglePlusAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId), typeof(GooglePlusAccount)));

                //}
                GooglePlusAccount   googlePlusAccount = new GooglePlusAccount();
                HttpResponseMessage response          = await WebApiReq.GetReq("api/ApiGooglePlusAccount/GetGooglePlusAccount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken);

                if (response.IsSuccessStatusCode)
                {
                    googlePlusAccount = await response.Content.ReadAsAsync <Domain.Socioboard.Domain.GooglePlusAccount>();

                    objSocialSiteAccount = googlePlusAccount;
                }
            }
            else if (objGroupProfile.ProfileType == "googleanalytics")
            {
                //using (Api.GoogleAnalyticsAccount.GoogleAnalyticsAccount ApiobjGoogleAnalyticsAccount = new Api.GoogleAnalyticsAccount.GoogleAnalyticsAccount())
                //{

                //    ApiobjGoogleAnalyticsAccount.Timeout = 300000;
                //    objSocialSiteAccount = (GoogleAnalyticsAccount)(new JavaScriptSerializer().Deserialize(ApiobjGoogleAnalyticsAccount.GetGooglePlusAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId), typeof(GoogleAnalyticsAccount)));

                //}
                GoogleAnalyticsAccount googlePlusAccount = new GoogleAnalyticsAccount();
                HttpResponseMessage    response          = await WebApiReq.GetReq("api/ApiGoogleAnalyticsAccount/GetGooglePlusAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId + "&UserId=" + objUserid.ToString(), "Bearer", accesstoken);

                if (response.IsSuccessStatusCode)
                {
                    googlePlusAccount = await response.Content.ReadAsAsync <Domain.Socioboard.Domain.GoogleAnalyticsAccount>();

                    objSocialSiteAccount = googlePlusAccount;
                }
            }


            return(objSocialSiteAccount);
        }
Example #14
0
        public string AddYoutubeAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string code)
        {
            #region Local variables Inisitalisation
            string            ret                  = string.Empty;
            string            objRefresh           = string.Empty;
            string            refreshToken         = string.Empty;
            string            access_token         = string.Empty;
            oAuthTokenYoutube ObjoAuthTokenYoutube = new oAuthTokenYoutube();
            oAuthToken        objToken             = new oAuthToken();
            Domain.Socioboard.Domain.YoutubeAccount objYoutubeAccount = new Domain.Socioboard.Domain.YoutubeAccount();
            Domain.Socioboard.Domain.YoutubeChannel objYoutubeChannel;
            YoutubeChannelRepository objYoutubeChannelRepository = new YoutubeChannelRepository();
            YoutubeAccountRepository objYoutubeAccountRepository = new YoutubeAccountRepository();
            #endregion
            #region Get AccessToken and RefreshToken
            objToken.ConsumerKey    = client_id;
            objToken.ConsumerSecret = client_secret;
            try
            {
                objRefresh = ObjoAuthTokenYoutube.GetRefreshToken(code, client_id, client_secret, redirect_uri);
                logger.Error("Abhay: ObjoAuthTokenYoutube()");
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
            }
            JObject objaccesstoken = JObject.Parse(objRefresh);
            try
            {
                refreshToken = objaccesstoken["refresh_token"].ToString();
            }
            catch (Exception ex)
            {
                access_token = objaccesstoken["access_token"].ToString();
                ObjoAuthTokenYoutube.RevokeToken(access_token);
                Console.WriteLine(ex.StackTrace);
                return("Refresh Token Not Found");
            }

            try
            {
                access_token = objaccesstoken["access_token"].ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            #endregion
            #region Get user Profile and Add Youtube Account
            JArray userinfo = new JArray();
            try
            {
                userinfo = objToken.GetUserInfo("me", access_token.ToString());
            }
            catch (Exception ex)
            {
            }
            foreach (var itemEmail in userinfo)
            {
                try
                {
                    objYoutubeAccount.Id       = Guid.NewGuid();
                    objYoutubeAccount.Ytuserid = itemEmail["id"].ToString();
                    objYoutubeAccount.Emailid  = itemEmail["email"].ToString();
                    try
                    {
                        objYoutubeAccount.Ytusername = itemEmail["given_name"].ToString();
                    }
                    catch (Exception ex)
                    {
                        objYoutubeAccount.Ytusername = itemEmail["name"].ToString();
                    }
                    objYoutubeAccount.Ytprofileimage = itemEmail["picture"].ToString();
                    objYoutubeAccount.Accesstoken    = access_token;
                    objYoutubeAccount.Refreshtoken   = refreshToken;
                    objYoutubeAccount.Isactive       = 1;
                    objYoutubeAccount.Entrydate      = DateTime.Now;
                    objYoutubeAccount.UserId         = Guid.Parse(UserId);
                    if (!objYoutubeAccountRepository.checkYoutubeUserExists(objYoutubeAccount))
                    {
                        YoutubeAccountRepository.Add(objYoutubeAccount);
                        ret = "Account Added Successfully";
                    }
                    else
                    {
                        ret = "Account already Exist !";
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
            }


            #endregion
            #region Add Youtube Channels
            GlobusGooglePlusLib.Youtube.Core.Channels ObjChannel = new GlobusGooglePlusLib.Youtube.Core.Channels();
            JArray objarray = new JArray();
            try
            {
                string  part         = (oAuthTokenYoutube.Parts.contentDetails.ToString() + "," + oAuthTokenYoutube.Parts.statistics.ToString());
                string  Value        = ObjChannel.Get_Channel_List(access_token, part, 50, true);
                JObject UserChannels = JObject.Parse(@Value);
                objarray = (JArray)UserChannels["items"];
            }
            catch (Exception ex)
            {
            }

            foreach (var item in objarray)
            {
                objYoutubeChannel = new Domain.Socioboard.Domain.YoutubeChannel();
                try
                {
                    objYoutubeChannel.Id               = Guid.NewGuid();
                    objYoutubeChannel.Channelid        = item["id"].ToString();
                    objYoutubeChannel.Likesid          = item["contentDetails"]["relatedPlaylists"]["likes"].ToString();
                    objYoutubeChannel.Favoritesid      = item["contentDetails"]["relatedPlaylists"]["favorites"].ToString();
                    objYoutubeChannel.Uploadsid        = item["contentDetails"]["relatedPlaylists"]["uploads"].ToString();
                    objYoutubeChannel.Watchhistoryid   = item["contentDetails"]["relatedPlaylists"]["watchHistory"].ToString();
                    objYoutubeChannel.Watchlaterid     = item["contentDetails"]["relatedPlaylists"]["watchLater"].ToString();
                    objYoutubeChannel.Googleplususerid = objYoutubeAccount.Ytuserid;
                    objYoutubeChannel.UserId           = Guid.Parse(UserId);
                    try
                    {
                        string viewcnt = item["statistics"]["viewCount"].ToString();
                        objYoutubeChannel.ViewCount = Convert.ToInt32(viewcnt);
                        string videocnt = item["statistics"]["videoCount"].ToString();
                        objYoutubeChannel.VideoCount = Convert.ToInt32(videocnt);
                        string commentcnt = item["statistics"]["commentCount"].ToString();
                        objYoutubeChannel.CommentCount = Convert.ToInt32(commentcnt);
                        string Subscribercnt = item["statistics"]["subscriberCount"].ToString();
                        objYoutubeChannel.SubscriberCount = Convert.ToInt32(Subscribercnt);
                        try
                        {
                            string str = item["statistics"]["hiddenSubscriberCount"].ToString();
                            if (str == "false")
                            {
                                objYoutubeChannel.HiddenSubscriberCount = 0;
                            }
                            else
                            {
                                objYoutubeChannel.HiddenSubscriberCount = 1;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                if (!objYoutubeChannelRepository.checkYoutubeChannelExists(objYoutubeChannel.Channelid, Guid.Parse(UserId)))
                {
                    YoutubeChannelRepository.Add(objYoutubeChannel);
                }
            }
            #endregion
            #region Add TeamMemberProfile
            //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
            //Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
            //objTeamMemberProfile.Id = Guid.NewGuid();
            //objTeamMemberProfile.TeamId = objTeam.Id;
            //objTeamMemberProfile.Status = 1;
            //objTeamMemberProfile.ProfileType = "youtube";
            //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
            //objTeamMemberProfile.ProfileId = objYoutubeAccount.Ytuserid;

            //objTeamMemberProfile.ProfileName = objYoutubeAccount.Ytusername;
            //objTeamMemberProfile.ProfilePicUrl = objYoutubeAccount.Ytprofileimage;

            //if (!objTeamMemberProfileRepository.checkTeamMemberProfilebyType(objTeam.Id, objYoutubeAccount.Ytuserid, "youtube"))
            //{
            //    objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
            //}

            Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
            grpProfile.Id           = Guid.NewGuid();
            grpProfile.EntryDate    = DateTime.UtcNow;
            grpProfile.GroupId      = Guid.Parse(GroupId);
            grpProfile.GroupOwnerId = Guid.Parse(UserId);
            grpProfile.ProfileId    = objYoutubeAccount.Ytuserid;
            grpProfile.ProfileType  = "youtube";
            grpProfile.ProfileName  = objYoutubeAccount.Ytusername;
            grpProfile.ProfilePic   = objYoutubeAccount.Ytprofileimage;


            #endregion
            #region SocialProfile
            Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
            objSocialProfile.Id            = Guid.NewGuid();
            objSocialProfile.ProfileType   = "youtube";
            objSocialProfile.ProfileId     = objYoutubeAccount.Ytuserid;
            objSocialProfile.UserId        = Guid.Parse(UserId);
            objSocialProfile.ProfileDate   = DateTime.Now;
            objSocialProfile.ProfileStatus = 1;
            if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
            {
                grpProfileRepo.AddGroupProfile(grpProfile);
                objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
            }
            #endregion
            GetYoutubeChannelVideos(UserId, objYoutubeAccount.Ytuserid);
            return(ret);
        }
Example #15
0
        public string AddTumblrAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string code)
        {
            string ret = string.Empty;
            string AccessTokenResponse = string.Empty;
            try
            {
                oAuthTumbler requestHelper = new oAuthTumbler();
                oAuthTumbler.TumblrConsumerKey = client_id;
                oAuthTumbler.TumblrConsumerSecret = client_secret;
                requestHelper.TumblrCallBackUrl = redirect_uri;
                AccessTokenResponse = requestHelper.GetAccessToken(oAuthTumbler.TumblrToken, code);
                logger.Error(AccessTokenResponse);

                string[] tokens = AccessTokenResponse.Split('&'); //extract access token & secret from response
                logger.Error(tokens);
                string accessToken = tokens[0].Split('=')[1];
                logger.Error(accessToken);
                string accessTokenSecret = tokens[1].Split('=')[1];
                logger.Error(accessTokenSecret);

                KeyValuePair<string, string> LoginDetails = new KeyValuePair<string, string>(accessToken, accessTokenSecret);

                JObject profile = new JObject();
                try
                {
                    profile = JObject.Parse(oAuthTumbler.OAuthData(Globals.UsersInfoUrl, "GET", LoginDetails.Key, LoginDetails.Value, null));
                }
                catch (Exception ex)
                {
                }


                #region Add Tumblr Account
                objTumblrAccount = new Domain.Socioboard.Domain.TumblrAccount();
                objTumblrAccount.Id = Guid.NewGuid();
                objTumblrAccount.tblrUserName = profile["response"]["user"]["name"].ToString();
                objTumblrAccount.UserId = Guid.Parse(UserId);
                objTumblrAccount.tblrAccessToken = accessToken;
                objTumblrAccount.tblrAccessTokenSecret = accessTokenSecret;
                objTumblrAccount.tblrProfilePicUrl = "http://api.tumblr.com/v2/blog/" + objTumblrAccount.tblrUserName + ".tumblr.com/avatar";//profile["response"]["user"]["name"].ToString();
                objTumblrAccount.IsActive = 1;
                if (!objTumblrAccountRepository.checkTubmlrUserExists(objTumblrAccount))
                {
                    TumblrAccountRepository.Add(objTumblrAccount);

                    #region Add Socialprofiles
                    objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                    objSocialProfile.Id = Guid.NewGuid();
                    objSocialProfile.UserId = Guid.Parse(UserId);
                    objSocialProfile.ProfileId = profile["response"]["user"]["name"].ToString();
                    objSocialProfile.ProfileType = "tumblr";
                    objSocialProfile.ProfileDate = DateTime.Now;
                    objSocialProfile.ProfileStatus = 1;
                    if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                    {
                        objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    }
                    #endregion

                    #region Add TeamMemeberProfile
                    //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                    //Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                    //objTeamMemberProfile.Id = Guid.NewGuid();
                    //objTeamMemberProfile.TeamId = objTeam.Id;
                    //objTeamMemberProfile.Status = 1;
                    //objTeamMemberProfile.ProfileType = "tumblr";
                    //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                    //objTeamMemberProfile.ProfileId = objTumblrAccount.tblrUserName;

                    ////Modified [13-02-15]
                    //objTeamMemberProfile.ProfilePicUrl = objTumblrAccount.tblrProfilePicUrl;
                    //objTeamMemberProfile.ProfileName = objTumblrAccount.tblrUserName;

                    //objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);


                    Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
                    grpProfile.Id = Guid.NewGuid();
                    grpProfile.EntryDate = DateTime.UtcNow;
                    grpProfile.GroupId = Guid.Parse(GroupId);
                    grpProfile.GroupOwnerId = Guid.Parse(UserId);
                    grpProfile.ProfileId = objTumblrAccount.tblrUserName;
                    grpProfile.ProfileType = "tumblr";
                    grpProfile.ProfileName = objTumblrAccount.tblrUserName;
                    grpProfile.ProfilePic = objTumblrAccount.tblrProfilePicUrl;
                    grpProfileRepo.AddGroupProfile(grpProfile);
                    #endregion
                }
                #endregion


                //if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeam.Id, objTumblrAccount.tblrUserName))
                //{
                //    objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                //}

                #region Add Tumblr Feeds
                AddTunblrFeeds(UserId, LoginDetails, profile["response"]["user"]["name"].ToString());
                #endregion

            }
            catch (Exception ex)
            {
                logger.Error("AddTumblrAccount => " + ex.StackTrace);
            }
            return ret;
        }
        public string AddInstagramAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string code)
        {
            string ret = string.Empty;
            oAuthInstagram objInsta = new oAuthInstagram();
            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", client_id, client_secret, redirect_uri, "http://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();
            try
            {
                logger.Error("AddInstagramAccount == >>" + access.access_token);
                #region InstagramAccount
                InstagramResponse<GlobusInstagramLib.App.Core.User> objuser = objusercontroller.GetUserDetails(access.user.id, access.access_token);

                objInstagramAccount = new Domain.Socioboard.Domain.InstagramAccount();
                objInstagramAccount.AccessToken = access.access_token;
                objInstagramAccount.InstagramId = access.user.id;
                try
                {
                    objInstagramAccount.ProfileUrl = access.user.profile_picture;
                }
                catch (Exception ex)
                {
                    logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.InsUserName = access.user.username;
                }
                catch (Exception ex)
                {
                    logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.TotalImages = objuser.data.counts.media;
                }
                catch (Exception ex)
                {
                    logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.FollowedBy = objuser.data.counts.followed_by;
                }
                catch (Exception ex)
                {
                    logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.Followers = objuser.data.counts.follows;
                }
                catch (Exception ex)
                {
                    logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                objInstagramAccount.UserId = Guid.Parse(UserId);
                #endregion


                if (!objInstagramAccountRepository.checkInstagramUserExists(objInstagramAccount.InstagramId, Guid.Parse(UserId)))
                {
                    objInstagramAccountRepository.addInstagramUser(objInstagramAccount);
                    #region Add TeamMemberProfile
                    //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                    //Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                    //objTeamMemberProfile.Id = Guid.NewGuid();
                    //objTeamMemberProfile.TeamId = objTeam.Id;
                    //objTeamMemberProfile.Status = 1;
                    //objTeamMemberProfile.ProfileType = "instagram";
                    //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                    //objTeamMemberProfile.ProfileId = objInstagramAccount.InstagramId;

                    ////Modified [13-02-15]
                    //objTeamMemberProfile.ProfilePicUrl = objInstagramAccount.ProfileUrl;
                    //objTeamMemberProfile.ProfileName = objInstagramAccount.InsUserName;

                    //objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);

                    Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
                    grpProfile.Id = Guid.NewGuid();
                    grpProfile.EntryDate = DateTime.UtcNow;
                    grpProfile.GroupId = Guid.Parse(GroupId);
                    grpProfile.GroupOwnerId = Guid.Parse(UserId);
                    grpProfile.ProfileId = objInstagramAccount.InstagramId;
                    grpProfile.ProfileType = "instagram";
                    grpProfile.ProfileName = objInstagramAccount.InsUserName;
                    grpProfile.ProfilePic = objInstagramAccount.ProfileUrl;
                    grpProfileRepo.AddGroupProfile(grpProfile);




                    #endregion
                    #region SocialProfile
                    Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                    objSocialProfile.Id = Guid.NewGuid();
                    objSocialProfile.ProfileType = "instagram";
                    objSocialProfile.ProfileId = objInstagramAccount.InstagramId;
                    objSocialProfile.UserId = Guid.Parse(UserId);
                    objSocialProfile.ProfileDate = DateTime.Now;
                    objSocialProfile.ProfileStatus = 1;
                    #endregion
                    #region Add SocialProfile
                    if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                    {
                        objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    }

                    #endregion
                    ret = "Account Added Successfully";
                }
                else
                {
                    ret = "Account already Exist !";
                }

                //GetIntagramImages(objInstagramAccount);
                GetInstagramFeeds(objInstagramAccount);

                GetInstagramUserDetails(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken);
                GetInstagramFollowing(objInstagramAccount.UserId.ToString(), objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1);
                GetInstagramFollower(objInstagramAccount.UserId.ToString(), objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1);
                GetInstagramPostLikes(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1);
                GetInstagramPostComments(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken);
                //GetInstagramUserPosts(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            return ret;
        }
        public string AddTwitterAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string requestToken, string requestSecret, string requestVerifier)
        {
            try
            {
                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;

                string ret = string.Empty;
                Users userinfo = new Users();
                oAuthTwitter OAuth = new oAuthTwitter(client_id, client_secret, redirect_uri);
                OAuth.AccessToken = requestToken;
                OAuth.AccessTokenSecret = requestVerifier;
                OAuth.AccessTokenGet(requestToken, requestVerifier);
                JArray profile = userinfo.Get_Users_LookUp_ByScreenName(OAuth, OAuth.TwitterScreenName);

                if (profile != null)
                {
                    logger.Error("Twitter.asmx >> AddTwitterAccount >> Twitter profile : " + profile);
                }
                else
                {
                    logger.Error("Twitter.asmx >> AddTwitterAccount >> NULL Twitter profile : " + profile);
                }

                objTwitterAccount = new Domain.Socioboard.Domain.TwitterAccount();
                TwitterUser twtuser;
                foreach (var item in profile)
                {
                    #region Add Twitter Account
                    try
                    {
                        objTwitterAccount.FollowingCount = Convert.ToInt32(item["friends_count"].ToString());
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        objTwitterAccount.FollowersCount = Convert.ToInt32(item["followers_count"].ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    objTwitterAccount.Id = Guid.NewGuid();
                    objTwitterAccount.IsActive = true;
                    objTwitterAccount.OAuthSecret = OAuth.AccessTokenSecret;
                    objTwitterAccount.OAuthToken = OAuth.AccessToken;
                    try
                    {
                        objTwitterAccount.ProfileImageUrl = item["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);

                    }
                    try
                    {
                        objTwitterAccount.ProfileUrl = string.Empty;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objTwitterAccount.TwitterUserId = item["id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception er)
                    {
                        try
                        {
                            objTwitterAccount.TwitterUserId = item["id"].ToString().TrimStart('"').TrimEnd('"');
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        Console.WriteLine(er.StackTrace);

                    }

                    try
                    {
                        objTwitterAccount.TwitterScreenName = item["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    objTwitterAccount.UserId = Guid.Parse(UserId);
                    #endregion
                    if (!objTwitterAccountRepository.checkTwitterUserExists(objTwitterAccount.TwitterUserId, Guid.Parse(UserId)))
                    {
                        objTwitterAccountRepository.addTwitterkUser(objTwitterAccount);
                        #region Add TeamMemberProfile
                        //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                        //Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                        //objTeamMemberProfile.Id = Guid.NewGuid();
                        //objTeamMemberProfile.TeamId = objTeam.Id;
                        //objTeamMemberProfile.Status = 1;
                        //objTeamMemberProfile.ProfileType = "twitter";
                        //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                        //objTeamMemberProfile.ProfileId = objTwitterAccount.TwitterUserId;

                        //objTeamMemberProfile.ProfileName = objTwitterAccount.TwitterScreenName;
                        //objTeamMemberProfile.ProfilePicUrl = objTwitterAccount.ProfileImageUrl;

                        //objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);

                        Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
                        grpProfile.Id = Guid.NewGuid();
                        grpProfile.EntryDate = DateTime.UtcNow;
                        grpProfile.GroupId = Guid.Parse(GroupId);
                        grpProfile.GroupOwnerId = Guid.Parse(UserId);
                        grpProfile.ProfileId = objTwitterAccount.TwitterUserId;
                        grpProfile.ProfileType = "twitter";
                        grpProfile.ProfileName = objTwitterAccount.TwitterScreenName;
                        grpProfile.ProfilePic = objTwitterAccount.ProfileImageUrl;
                        grpProfileRepo.AddGroupProfile(grpProfile);

                        #endregion
                        #region SocialProfile
                        Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                        objSocialProfile.Id = Guid.NewGuid();
                        objSocialProfile.ProfileType = "twitter";
                        objSocialProfile.ProfileId = objTwitterAccount.TwitterUserId;
                        objSocialProfile.UserId = Guid.Parse(UserId);
                        objSocialProfile.ProfileDate = DateTime.Now;
                        objSocialProfile.ProfileStatus = 1;
                        #endregion
                        #region Add Twitter Stats
                        if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                        {
                            objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                        }
                        objTwitterStats = new Domain.Socioboard.Domain.TwitterStats();
                        Random rNum = new Random();
                        objTwitterStats.Id = Guid.NewGuid();
                        objTwitterStats.TwitterId = objTwitterAccount.TwitterUserId;
                        objTwitterStats.UserId = Guid.Parse(UserId);
                        objTwitterStats.FollowingCount = objTwitterAccount.FollowingCount;
                        objTwitterStats.FollowerCount = objTwitterAccount.FollowersCount;
                        objTwitterStats.Age1820 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age2124 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age2534 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age3544 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age4554 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age5564 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age65 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.EntryDate = DateTime.Now;
                        if (!objTwtstats.checkTwitterStatsExists(objTwitterAccount.TwitterUserId, Guid.Parse(UserId)))
                        {
                            objTwtstats.addTwitterStats(objTwitterStats);
                        }
                        #endregion

                        #region AddTwitterFollowerCount
                        Domain.Socioboard.Domain.TwitterAccountFollowers objTwitterAccountFollowers = new Domain.Socioboard.Domain.TwitterAccountFollowers();
                        TwitterAccountFollowersRepository objTwitterAccountFollowersRepository = new TwitterAccountFollowersRepository();
                        objTwitterAccountFollowers.Id = Guid.NewGuid();
                        objTwitterAccountFollowers.UserId = Guid.Parse(UserId);
                        objTwitterAccountFollowers.EntryDate = DateTime.Now;
                        objTwitterAccountFollowers.FollowingsCount = Convert.ToInt32(item["friends_count"].ToString());
                        objTwitterAccountFollowers.FollowersCount = Convert.ToInt32(item["followers_count"].ToString());
                        try
                        {
                            objTwitterAccountFollowers.ProfileId = item["id_str"].ToString().TrimStart('"').TrimEnd('"');
                        }
                        catch (Exception er)
                        {
                            try
                            {
                                objTwitterAccountFollowers.ProfileId = item["id"].ToString().TrimStart('"').TrimEnd('"');
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            Console.WriteLine(er.StackTrace);

                        }
                        objTwitterAccountFollowersRepository.addTwitterAccountFollower(objTwitterAccountFollowers);
                        #endregion

                        ret = "Account Added Successfully";
                    }
                    else
                    {
                        ret = "Account already Exist !";
                    }
                }
                getTwitterMessages(UserId, OAuth);

                getUserRetweets(UserId, OAuth);


                //edited by avinash[24-03-15]

                //getTwitterEngagement(UserId, OAuth);

                getUserTweets(UserId, OAuth);

                getTwitterFeeds(UserId, OAuth);

                getTwitterDirectMessageSent(UserId, OAuth);
                getTwittwrDirectMessageRecieved(OAuth, UserId);
                getUserMentions(OAuth, objTwitterAccount.TwitterUserId, Guid.Parse(UserId));
                getUserFollowers(OAuth, objTwitterAccount.TwitterScreenName, objTwitterAccount.TwitterUserId, Guid.Parse(UserId));
                getUserRetweet(OAuth, objTwitterAccount.TwitterUserId, Guid.Parse(UserId));
                twitterrecentdetails(profile);
                //return ret;
                return new JavaScriptSerializer().Serialize(objTwitterAccount);
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
                return "";
            }
        }
        public void GetPageProfile(dynamic data, oAuthLinkedIn _OAuth, string UserId, string CompanyPageId, string GroupId)
        {
            Domain.Socioboard.Domain.SocialProfile socioprofile = new Domain.Socioboard.Domain.SocialProfile();
            Domain.Socioboard.Domain.GroupProfile  grpProfile   = new Domain.Socioboard.Domain.GroupProfile();
            SocialProfilesRepository socioprofilerepo           = new SocialProfilesRepository();

            Domain.Socioboard.Domain.LinkedinCompanyPage objLinkedincmpnypage = new Domain.Socioboard.Domain.LinkedinCompanyPage();
            LinkedinCompanyPageRepository objLinkedCmpnyPgeRepo = new LinkedinCompanyPageRepository();

            try
            {
                objLinkedincmpnypage.UserId = Guid.Parse(UserId);
                try
                {
                    objLinkedincmpnypage.LinkedinPageId = data.Pageid.ToString();
                }
                catch
                {
                }
                objLinkedincmpnypage.Id = Guid.NewGuid();
                try
                {
                    objLinkedincmpnypage.EmailDomains = data.EmailDomains.ToString();
                }
                catch { }
                objLinkedincmpnypage.LinkedinPageName = data.name.ToString();
                objLinkedincmpnypage.OAuthToken       = _OAuth.Token;
                objLinkedincmpnypage.OAuthSecret      = _OAuth.TokenSecret;
                objLinkedincmpnypage.OAuthVerifier    = _OAuth.Verifier;
                try
                {
                    objLinkedincmpnypage.Description = data.description.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.FoundedYear = data.founded_year.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.EndYear = data.end_year.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.Locations = data.locations.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.Specialties = data.Specialties.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.WebsiteUrl = data.website_url.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.Status = data.status.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.EmployeeCountRange = data.employee_count_range.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.Industries = data.industries.ToString();
                }
                catch { }
                try
                {
                    string NuberOfFollower = data.num_followers.ToString();
                    objLinkedincmpnypage.NumFollowers = Convert.ToInt16(NuberOfFollower);
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.CompanyType = data.company_type.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.LogoUrl = data.logo_url.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.SquareLogoUrl = data.square_logo_url.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.BlogRssUrl = data.blog_rss_url.ToString();
                }
                catch { }
                try
                {
                    objLinkedincmpnypage.UniversalName = data.universal_name.ToString();
                }
                catch { }
                #region SocialProfiles
                socioprofile.UserId        = Guid.Parse(UserId);
                socioprofile.ProfileType   = "linkedincompanypage";
                socioprofile.ProfileId     = data.Pageid.ToString();;
                socioprofile.ProfileStatus = 1;
                socioprofile.ProfileDate   = DateTime.Now;
                socioprofile.Id            = Guid.NewGuid();
                #endregion

                #region TeamMemberProfile
                //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                //objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                //objTeamMemberProfile.Id = Guid.NewGuid();
                //objTeamMemberProfile.TeamId = objTeam.Id;
                //objTeamMemberProfile.Status = 1;
                //objTeamMemberProfile.ProfileType = "linkedincompanypage";
                //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                //objTeamMemberProfile.ProfileId = socioprofile.ProfileId;

                grpProfile.Id           = Guid.NewGuid();
                grpProfile.GroupId      = Guid.Parse(GroupId);
                grpProfile.GroupOwnerId = objLinkedincmpnypage.UserId;
                grpProfile.ProfileId    = objLinkedincmpnypage.LinkedinPageId;
                grpProfile.ProfileType  = "linkedincompanypage";
                grpProfile.ProfileName  = objLinkedincmpnypage.LinkedinPageName;
                grpProfile.EntryDate    = DateTime.UtcNow;

                #endregion
            }
            catch
            {
            }
            try
            {
                if (!objSocialProfilesRepository.checkUserProfileExist(socioprofile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(socioprofile);
                    grpProfileRepo.AddGroupProfile(grpProfile);
                }
                if (!string.IsNullOrEmpty(GroupId))
                {
                    if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeamMemberProfile.TeamId, objLinkedincmpnypage.LinkedinPageId))
                    {
                        objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                    }
                }
                if (!objLinkedCmpnyPgeRepo.checkLinkedinPageExists(CompanyPageId, Guid.Parse(UserId)))
                {
                    objLinkedCmpnyPgeRepo.addLinkenCompanyPage(objLinkedincmpnypage);
                }
                else
                {
                    objLinkedincmpnypage.LinkedinPageId = CompanyPageId;
                    objLinkedCmpnyPgeRepo.updateLinkedinPage(objLinkedincmpnypage);
                }
            }
            catch
            {
            }
        }
        public string AddLinkedinAccount(string oauth_token, string oauth_verifier, string reuqestTokenSecret, string consumerKey, string consumerSecret, string UserId, string GroupId)
        {
            Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();

            try
            {
                logger.Error("AddLinkedinAccount()");

                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;

                string ret = string.Empty;
                LinkedInProfile objProfile = new LinkedInProfile();
                LinkedInProfile.UserProfile objUserProfile = new LinkedInProfile.UserProfile();
                objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                oAuthLinkedIn _oauth = new oAuthLinkedIn();
                objLinkedInAccount = new LinkedInAccount();
                #region Get linkedin Profile data from Api
                try
                {
                    _oauth.ConsumerKey = consumerKey;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    _oauth.ConsumerSecret = consumerSecret;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    _oauth.Token = oauth_token;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    _oauth.TokenSecret = reuqestTokenSecret;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    _oauth.Verifier = oauth_verifier;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    _oauth.AccessTokenGet(oauth_token);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);

                }
                try
                {
                    objUserProfile = objProfile.GetUserProfile(_oauth);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                #endregion
                dynamic data = objUserProfile;
                try
                {
                    #region LinkedInAccount
                    objLinkedInAccount.UserId = Guid.Parse(UserId);
                    objLinkedInAccount.LinkedinUserId = data.id.ToString();
                    try
                    {
                        objLinkedInAccount.EmailId = data.email.ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    objLinkedInAccount.LinkedinUserName = data.first_name.ToString() + data.last_name.ToString();
                    objLinkedInAccount.OAuthToken = _oauth.Token;
                    objLinkedInAccount.OAuthSecret = _oauth.TokenSecret;
                    objLinkedInAccount.OAuthVerifier = _oauth.Verifier;
                    try
                    {
                        objLinkedInAccount.ProfileImageUrl = data.picture_url.ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        objLinkedInAccount.ProfileUrl = data.profile_url.ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    #endregion
                    #region SocialProfiles
                    try
                    {
                        objLinkedInAccount.Connections = data.connections;
                        objLinkedInAccount.IsActive = true;
                        objSocialProfile.UserId = Guid.Parse(UserId);
                        objSocialProfile.ProfileType = "linkedin";
                        objSocialProfile.ProfileId = data.id.ToString();
                        objSocialProfile.ProfileStatus = 1;
                        objSocialProfile.ProfileDate = DateTime.Now;
                        objSocialProfile.Id = Guid.NewGuid();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                    }
                    #endregion SocialProfiles
                    #region Add TeamMemberProfile
                    try
                    {
                        //Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                        //objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                        //objTeamMemberProfile.Id = Guid.NewGuid();
                        //objTeamMemberProfile.TeamId = objTeam.Id;
                        //objTeamMemberProfile.Status = 1;
                        //objTeamMemberProfile.ProfileType = "linkedin";
                        //objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                        //objTeamMemberProfile.ProfileId = objLinkedInAccount.LinkedinUserId;
                        //objTeamMemberProfile.ProfileName = objLinkedInAccount.LinkedinUserName;
                        //objTeamMemberProfile.ProfilePicUrl = objLinkedInAccount.ProfileImageUrl;

                        grpProfile.Id = Guid.NewGuid();
                        grpProfile.EntryDate = DateTime.UtcNow;
                        grpProfile.GroupId = Guid.Parse(GroupId);
                        grpProfile.GroupOwnerId = Guid.Parse(UserId);
                        grpProfile.ProfileId = objLinkedInAccount.LinkedinUserId;
                        grpProfile.ProfileType = "linkedin";
                        grpProfile.ProfileName = objLinkedInAccount.LinkedinUserName;
                        grpProfile.ProfilePic = objLinkedInAccount.ProfileImageUrl;

                    }
                    catch (Exception ex)
                    {
                       logger.Error(ex.Message);
                    }
                    #endregion

                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
                try
                {
                    if (!objLinkedInAccountRepository.checkLinkedinUserExists(objLinkedInAccount.LinkedinUserId, Guid.Parse(UserId)))
                    {
                        objLinkedInAccountRepository.addLinkedinUser(objLinkedInAccount);
                        ret = "LinkedIn Account Added Successfully";
                    }
                    else
                    {
                        ret = "LinkedIn Account Already Exist";
                    }
                    if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                    {
                        objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    }
                    if (!grpProfileRepo.checkProfileExistsingroup(Guid.Parse(GroupId), objLinkedInAccount.LinkedinUserId))
                    {
                    //    objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                        grpProfileRepo.AddGroupProfile(grpProfile);

                    }

                    #region Add LinkedIn Feeds
                    LinkedInNetwork objln = new LinkedInNetwork();
                    List<LinkedInNetwork.Network_Updates> userUPdate = objln.GetNetworkUpdates(_oauth, 20);
                    Domain.Socioboard.MongoDomain.LinkedInFeed objLinkedInFeed;
                    foreach (var item in userUPdate)
                    {
                        objLinkedInFeed = new Domain.Socioboard.MongoDomain.LinkedInFeed();
                        try
                        {
                            //objLinkedInFeed = new Domain.Socioboard.Domain.LinkedInFeed();
                            objLinkedInFeed.Id = ObjectId.GenerateNewId();
                            objLinkedInFeed.Feeds = item.Message;
                            objLinkedInFeed.FromId = item.PersonId;
                            objLinkedInFeed.FromName = item.PersonFirstName + " " + item.PersonLastName;
                            objLinkedInFeed.FeedsDate = Convert.ToDateTime(item.DateTime).ToString("yyyy/MM/dd HH:mm:ss");
                            //objLinkedInFeed.EntryDate = DateTime.Now;
                            objLinkedInFeed.ProfileId = objLinkedInAccount.LinkedinUserId;
                            objLinkedInFeed.Type = item.UpdateType;
                            //objLinkedInFeed.UserId = Guid.Parse(UserId);
                            objLinkedInFeed.FromPicUrl = item.PictureUrl;
                            objLinkedInFeed.ImageUrl = item.ImageUrl;
                            objLinkedInFeed.FromUrl = item.url;
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        //if (!objLinkedInFeedRepository.checkLinkedInFeedExists(objLinkedInFeed.FeedId, Guid.Parse(UserId)))
                        //{

                        //    objLinkedInFeedRepository.addLinkedInFeed(objLinkedInFeed);
                        //}

                        var rt = linkedinFeedRepo.Find<Domain.Socioboard.MongoDomain.LinkedInFeed>(t=>t.FeedId.Equals(objLinkedInFeed.FeedId));
                        var task = Task.Run(async ()=> {
                            return await rt;
                        });
                        int count = task.Result.Count;
                        if (count < 1)
                        {
                            linkedinFeedRepo.Add(objLinkedInFeed);
                        }
                    }
                    #endregion


                    #region Add LinkedIn UserUpdates
                    GlobusLinkedinLib.App.Core.LinkedInUser l = new GlobusLinkedinLib.App.Core.LinkedInUser();
                    List<Domain.Socioboard.Domain.LinkedIn_Update_Messages> lst_Messages = l.GetUserUpdateNew(_oauth, objLinkedInAccount.LinkedinUserId, 10);
                    Domain.Socioboard.MongoDomain.LinkedInMessage objLinkedInMessage;
                    foreach (var item_Messages in lst_Messages)
                    {
                        objLinkedInMessage = new Domain.Socioboard.MongoDomain.LinkedInMessage();
                        try
                        {
                            objLinkedInMessage.Id = ObjectId.GenerateNewId();
                            objLinkedInMessage.Message = item_Messages.Message;
                            objLinkedInMessage.ProfileId = item_Messages.ProfileId;
                            objLinkedInMessage.ProfileName = item_Messages.ProfileName;
                            objLinkedInMessage.CreatedDate = Convert.ToDateTime(item_Messages.CreatedDate).ToString("yyyy/MM/dd HH:mm:ss");
                            //objLinkedInMessage.EntryDate = DateTime.Now;
                            objLinkedInMessage.Type = item_Messages.Type;
                            //objLinkedInMessage.UserId = Guid.Parse(UserId);
                            objLinkedInMessage.ImageUrl = item_Messages.ImageUrl;
                            objLinkedInMessage.FeedId = item_Messages.FeedId;
                            objLinkedInMessage.ProfileUrl = item_Messages.ProfileUrl;
                            objLinkedInMessage.Comments = item_Messages.Comments;
                            objLinkedInMessage.Likes = item_Messages.Likes;
                            objLinkedInMessage.ProfileImageUrl = item_Messages.ProfileImageUrl;
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }

                        var rt = linkedinMessageRepo.Find<Domain.Socioboard.MongoDomain.LinkedInMessage>(t => t.FeedId.Equals(objLinkedInMessage.FeedId));
                        var task = Task.Run(async () =>
                        {
                            return await rt;
                        });
                        int count = task.Result.Count;
                        if (count < 1)
                        {
                            linkedinMessageRepo.Add(objLinkedInMessage);
                        }

                        //if (!objLinkedInMessageRepository.checkLinkedInMessageExists(objLinkedInAccount.LinkedinUserId, objLinkedInMessage.FeedId, Guid.Parse(UserId)))
                        //{
                        //    objLinkedInMessageRepository.addLinkedInMessage(objLinkedInMessage);
                        //}
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
                return "";
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
                return "";
            }
        }