Example #1
0
        public void GetUerProfile(GooglePlusAccount objgpAcc, string acces_token, string refresh_token, Guid UserId)
        {
            PeopleController            obj       = new PeopleController();
            oAuthToken                  objtoken  = new oAuthToken();
            GooglePlusAccountRepository objgpRepo = new GooglePlusAccountRepository();

            SocialProfilesRepository socioprofilerepo = new SocialProfilesRepository();
            SocialProfile            socioprofile     = new SocialProfile();

            socioprofile.Id          = Guid.NewGuid();
            socioprofile.ProfileDate = DateTime.Now;
            socioprofile.ProfileId   = objgpAcc.GpUserId;
            socioprofile.ProfileType = "googleplus";
            socioprofile.UserId      = UserId;


            JArray objPeopleList = obj.GetPeopleList(objgpAcc.GpUserId, acces_token, "visible");

            objgpAcc.PeopleCount = objPeopleList.Count();


            if (!objgpRepo.checkGooglePlusUserExists(objgpAcc.GpUserId, UserId))
            {
                objgpRepo.addGooglePlusUser(objgpAcc);
                if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                {
                    socioprofilerepo.addNewProfileForUser(socioprofile);
                }
                else
                {
                    socioprofilerepo.updateSocialProfile(socioprofile);
                }
            }
            else
            {
                objgpRepo.updateGooglePlusUser(objgpAcc);
                if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                {
                    socioprofilerepo.addNewProfileForUser(socioprofile);
                }
                else
                {
                    socioprofilerepo.updateSocialProfile(socioprofile);
                }
            }
            GetUserActivities(objgpAcc.GpUserId, acces_token, UserId);
        }
        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 #3
0
        public void getFacebookUserProfile(dynamic data, string accesstoken, long friends, Guid user)
        {
            SocialProfile             socioprofile     = new SocialProfile();
            SocialProfilesRepository  socioprofilerepo = new SocialProfilesRepository();
            FacebookAccount           fbAccount        = new FacebookAccount();
            FacebookAccountRepository fbrepo           = new FacebookAccountRepository();

            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);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            oAuthTokenGa obj     = new oAuthTokenGa();
            Accounts     objAcc  = new Accounts();
            Analytics    objAlyt = new Analytics();
            User         user    = (User)Session["LoggedUser"];

            if (!IsPostBack)
            {
                if (Session["login"] == null)
                {
                    if (user == null)
                    {
                        Response.Redirect("Default.aspx");
                    }
                }

                try
                {
                    string strRefresh = obj.GetRefreshToken(Request.QueryString["code"].ToString());
                    if (!strRefresh.StartsWith("["))
                    {
                        strRefresh = "[" + strRefresh + "]";
                    }
                    JArray objArray = JArray.Parse(strRefresh);
                    GoogleAnalyticsAccount           objGaAcc     = new GoogleAnalyticsAccount();
                    GoogleAnalyticsAccountRepository objGaAccRepo = new GoogleAnalyticsAccountRepository();
                    GanalyticsHelper         objGaHelper          = new GanalyticsHelper();
                    SocialProfilesRepository socioprofilerepo     = new SocialProfilesRepository();
                    SocialProfile            socioprofile         = new SocialProfile();
                    foreach (var item in objArray)
                    {
                        DataSet dsAccount = objAcc.getGaAccounts(item["access_token"].ToString());
                        objGaAcc.RefreshToken  = item["refresh_token"].ToString();
                        objGaAcc.AccessToken   = item["access_token"].ToString();
                        objGaAcc.EmailId       = dsAccount.Tables["title"].Rows[0]["title_Text"].ToString();
                        objGaAcc.EntryDate     = DateTime.Now;
                        objGaAcc.GaAccountId   = dsAccount.Tables["property"].Rows[0]["value"].ToString();
                        objGaAcc.GaAccountName = dsAccount.Tables["property"].Rows[1]["value"].ToString();
                        objGaAcc.Id            = Guid.NewGuid();
                        objGaAcc.IsActive      = true;
                        objGaAcc.UserId        = user.Id;
                        DataSet dsProfile    = objAcc.getGaProfiles(item["access_token"].ToString(), objGaAcc.GaAccountId);
                        int     profileCount = dsProfile.Tables["property"].Select("name='ga:profileId'").Length;
                        string[,] names = new string[profileCount, 2];


                        int tempCount = 0;
                        foreach (DataRow dRow in dsProfile.Tables["property"].Rows)
                        {
                            //if (dRow["name"].Equals("ga:profileId") || dRow["name"].Equals("ga:profileName"))
                            {
                                if (dRow["name"].Equals("ga:profileId"))
                                {
                                    objGaAcc.GaProfileId = dRow["value"].ToString();
                                    names[tempCount, 0]  = dRow["value"].ToString();
                                }
                                if (dRow["name"].Equals("ga:profileName"))
                                {
                                    names[tempCount, 1]    = dRow["value"].ToString();
                                    objGaAcc.GaProfileName = dRow["value"].ToString();
                                }
                                if (tempCount >= profileCount)
                                {
                                    break;
                                }
                                if (names[tempCount, 0] != null && names[tempCount, 1] != null)
                                {
                                    tempCount++;
                                }
                            }
                        }

                        socioprofile.Id          = Guid.NewGuid();
                        socioprofile.ProfileDate = DateTime.Now;
                        socioprofile.ProfileId   = objGaAcc.GaAccountId;
                        socioprofile.ProfileType = "googleanalytics";
                        socioprofile.UserId      = user.Id;

                        if (!objGaAccRepo.checkGoogelAnalyticsUserExists(objGaAcc.GaAccountId, user.Id))
                        {
                            for (int i = 0; i < profileCount; i++)
                            {
                                objGaAcc.GaProfileId   = names[i, 0];
                                objGaAcc.GaProfileName = names[i, 1];
                                if (!objGaAccRepo.checkGoogelAnalyticsProfileExists(objGaAcc.GaAccountId, objGaAcc.GaProfileId, user.Id))
                                {
                                    objGaAccRepo.addGoogleAnalyticsUser(objGaAcc);
                                }
                                else
                                {
                                    objGaAccRepo.updateGoogelAnalyticsUser(objGaAcc);
                                }


                                objGaHelper.getCountryAnalyticsApi(objGaAcc.GaProfileId, user.Id);
                                objGaHelper.getYearWiseAnalyticsApi(objGaAcc.GaProfileId, user.Id);
                                objGaHelper.getMonthWiseAnalyticsApi(objGaAcc.GaProfileId, user.Id);
                                objGaHelper.getDayWiseAnalyticsApi(objGaAcc.GaProfileId, user.Id);
                            }

                            if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                            {
                                socioprofilerepo.addNewProfileForUser(socioprofile);
                            }
                            else
                            {
                                socioprofilerepo.updateSocialProfile(socioprofile);
                            }
                        }
                        else
                        {
                            //objGaAccRepo.updateGoogelAnalyticsUser(objGaAcc);
                            for (int i = 0; i < names.Length; i++)
                            {
                                objGaAcc.GaProfileId   = names[i, 0];
                                objGaAcc.GaProfileName = names[i, 1];
                                if (!objGaAccRepo.checkGoogelAnalyticsProfileExists(objGaAcc.GaAccountId, objGaAcc.GaProfileId, user.Id))
                                {
                                    objGaAccRepo.addGoogleAnalyticsUser(objGaAcc);
                                }
                                else
                                {
                                    objGaAccRepo.updateGoogelAnalyticsUser(objGaAcc);
                                }
                            }
                            if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                            {
                                socioprofilerepo.addNewProfileForUser(socioprofile);
                            }
                            else
                            {
                                socioprofilerepo.updateSocialProfile(socioprofile);
                            }
                        }
                        Response.Redirect("Home.aspx");
                    }
                }
                catch (Exception Err)
                {
                    logger.Error(Err.StackTrace);
                    try
                    {
                        Response.Redirect("/Home.aspx");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
        }
        public void getAccessToken()
        {
            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"].ToString(), ConfigurationManager.AppSettings["InstagramClientSec"].ToString(), ConfigurationManager.AppSettings["InstagramCallBackURL"].ToString(), "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            SocialProfilesRepository socioprofilerepo = new SocialProfilesRepository();
            SocialProfile            socioprofile     = new SocialProfile();

            _api = oAuthInstagram.GetInstance(configi);
            AccessToken access = new AccessToken();
            string      code   = Request.QueryString["code"].ToString();

            SocioBoard.Domain.User user = (SocioBoard.Domain.User)Session["LoggedUser"];
            access = _api.AuthGetAccessToken(code);

            UserController objusercontroller = new UserController();
            InstagramResponse <GlobusInstagramLib.App.Core.User> objuser = objusercontroller.GetUserDetails(access.user.id, access.access_token);

            InstagramAccount objInsAccount = new InstagramAccount();

            objInsAccount.AccessToken = access.access_token;
            //objInsAccount.FollowedBy=access.user.
            objInsAccount.InstagramId = access.user.id;
            objInsAccount.ProfileUrl  = access.user.profile_picture;
            objInsAccount.InsUserName = access.user.username;
            objInsAccount.TotalImages = objuser.data.counts.media;
            objInsAccount.FollowedBy  = objuser.data.counts.followed_by;
            objInsAccount.Followers   = objuser.data.counts.follows;
            objInsAccount.UserId      = user.Id;

            socioprofile.UserId        = user.Id;
            socioprofile.ProfileType   = "instagram";
            socioprofile.ProfileId     = access.user.id;
            socioprofile.ProfileStatus = 1;
            socioprofile.ProfileDate   = DateTime.Now;
            socioprofile.Id            = Guid.NewGuid();

            if (objInsRepo.checkInstagramUserExists(access.user.id, user.Id))
            {
                HttpContext.Current.Session["alreadyexist"] = objInsAccount;
                objInsRepo.updateInstagramUser(objInsAccount);
                if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                {
                    socioprofilerepo.addNewProfileForUser(socioprofile);
                }
            }
            else
            {
                objInsRepo.addInstagramUser(objInsAccount);
                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        = socioprofile.ProfileId;
                        teammemberprofile.ProfileType      = "instagram";
                        teammemberprofile.StatusUpdateDate = DateTime.Now;

                        objTeamMemberProfileRepository.addNewTeamMember(teammemberprofile);
                    }
                }
            }
            string messages = getIntagramImages(objInsAccount);


            Response.Write(messages);
        }
Example #6
0
        private void AccessToken()
        {
            SocioBoard.Domain.User user = (User)Session["LoggedUser"];
            oAuthTokenYoutube      ObjoAuthTokenYoutube = new oAuthTokenYoutube();
            oAuthToken             objToken             = new oAuthToken();

            //GlobusGooglePlusLib.App.Core.PeopleController obj = new GlobusGooglePlusLib.App.Core.PeopleController();
            logger.Error("Error1:oAuthToken");

            string refreshToken = string.Empty;
            string access_token = string.Empty;


            try
            {
                string objRefresh = string.Empty;
                objRefresh = ObjoAuthTokenYoutube.GetRefreshToken(Request.QueryString["code"]);
                if (!objRefresh.StartsWith("["))
                {
                    objRefresh = "[" + objRefresh + "]";
                }
                JArray objArray = JArray.Parse(objRefresh);

                logger.Error("Error1:GetRefreshToken");

                if (!objRefresh.Contains("refresh_token"))
                {
                    logger.Error("Error0:refresh_token");
                    access_token = objArray[0]["access_token"].ToString();
                    string abc = ObjoAuthTokenYoutube.RevokeToken(access_token);
                    Response.Redirect("https://accounts.google.com/o/oauth2/auth?client_id=" + System.Configuration.ConfigurationManager.AppSettings["YtconsumerKey"] + "&redirect_uri=" + System.Configuration.ConfigurationManager.AppSettings["Ytredirect_uri"] + "&scope=https://www.googleapis.com/auth/youtube+https://www.googleapis.com/auth/youtube.readonly+https://www.googleapis.com/auth/youtubepartner+https://www.googleapis.com/auth/youtubepartner-channel-audit+https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/plus.me&response_type=code&access_type=offline");
                    logger.Error("Error1:refresh_token");
                }


                foreach (var item in objArray)
                {
                    logger.Error("Abhay Item :" + item);
                    try
                    {
                        try
                        {
                            refreshToken = item["refresh_token"].ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                            logger.Error(ex.Message);

                            Console.WriteLine(ex.StackTrace);
                        }


                        access_token = item["access_token"].ToString();

                        break;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                    }
                }


                //Get user Profile
                #region <<Get user Profile>>
                JArray objEmail = new JArray();
                try
                {
                    objEmail = objToken.GetUserInfo("me", access_token.ToString());
                }
                catch (Exception ex)
                {
                    logger.Error("Email : " + objEmail);
                    logger.Error(ex.Message);
                }


                #endregion


                GlobusGooglePlusLib.Youtube.Core.Channels ObjChannel = new GlobusGooglePlusLib.Youtube.Core.Channels();
                //Get the Channels of user

                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);
                    logger.Error("Successfully GetValus");
                    logger.Error("Value :" + Value);
                    JObject UserChannels = JObject.Parse(@Value);
                    logger.Error("Successfully Convert Jobj");
                    logger.Error("Successfully Convert Jobj");

                    objarray = (JArray)UserChannels["items"];
                    logger.Error("Successfully Convert JArr");
                }
                catch (Exception ex)
                {
                    logger.Error("UserChannels :" + ex.Message);
                }


                YoutubeAccount           objYoutubeAccount           = new YoutubeAccount();
                YoutubeChannel           objYoutubeChannel           = new YoutubeChannel();
                YoutubeChannelRepository objYoutubeChannelRepository = new YoutubeChannelRepository();
                YoutubeAccountRepository objYoutubeAccountRepository = new YoutubeAccountRepository();

                //put condition here to check is user already exise if exist then update else insert
                string ytuerid = "";
                foreach (var itemEmail in objEmail)
                {
                    logger.Error("itemEmail :" + itemEmail);
                    try
                    {
                        objYoutubeAccount.Id = Guid.NewGuid();
                        ytuerid = itemEmail["id"].ToString();
                        objYoutubeAccount.Ytuserid       = itemEmail["id"].ToString();
                        objYoutubeAccount.Emailid        = itemEmail["email"].ToString();
                        objYoutubeAccount.Ytusername     = itemEmail["given_name"].ToString();
                        objYoutubeAccount.Ytprofileimage = itemEmail["picture"].ToString();
                        objYoutubeAccount.Accesstoken    = access_token;
                        objYoutubeAccount.Refreshtoken   = refreshToken;
                        objYoutubeAccount.Isactive       = 1;
                        objYoutubeAccount.Entrydate      = DateTime.Now;
                        objYoutubeAccount.UserId         = user.Id;
                    }
                    catch (Exception ex)
                    {
                        logger.Error("itemEmail1 :" + ex.Message);
                        logger.Error("itemEmail1 :" + ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                    }
                }

                foreach (var item in objarray)
                {
                    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 = ytuerid;
                        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)
                            {
                                logger.Error("aagaya1: " + ex);
                                Console.WriteLine(ex.StackTrace);
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error("aagaya2: " + ex);
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error("aagaya3: " + ex);
                        Console.WriteLine(ex.StackTrace);
                        logger.Error(ex.StackTrace);
                        logger.Error(ex.Message);
                    }
                }
                //YoutubeChannelRepository.Add(objYoutubeChannel);
                SocialProfile            objSocialProfile            = new SocialProfile();
                SocialProfilesRepository objSocialProfilesRepository = new SocialProfilesRepository();
                objSocialProfile.Id            = Guid.NewGuid();
                objSocialProfile.UserId        = user.Id;
                objSocialProfile.ProfileId     = ytuerid;
                objSocialProfile.ProfileType   = "youtube";
                objSocialProfile.ProfileDate   = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;
                logger.Error("aagaya");
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);

                    if (!objYoutubeAccountRepository.checkYoutubeUserExists(objYoutubeAccount))
                    {
                        logger.Error("Abhay");
                        YoutubeAccountRepository.Add(objYoutubeAccount);
                        logger.Error("Abhay account add ho gaya");
                        YoutubeChannelRepository.Add(objYoutubeChannel);
                        logger.Error("Channel account add ho gaya");
                        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        = objYoutubeAccount.Ytuserid;
                            teammemberprofile.ProfileType      = "youtube";
                            teammemberprofile.StatusUpdateDate = DateTime.Now;
                            objTeamMemberProfileRepository.addNewTeamMember(teammemberprofile);
                        }
                    }
                }
                else
                {
                    logger.Error("Suraj");
                    if (!objYoutubeAccountRepository.checkYoutubeUserExists(objYoutubeAccount))
                    {
                        YoutubeAccountRepository.Add(objYoutubeAccount);
                        YoutubeChannelRepository.Add(objYoutubeChannel);
                    }
                    else
                    {
                        Response.Redirect("Home.aspx");
                    }
                }

                Response.Redirect("Home.aspx");
            }
            catch (Exception Err)
            {
                Console.Write(Err.Message.ToString());
                logger.Error(Err.StackTrace);
                logger.Error(Err.Message);
            }
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        private void getTwitterUserProfile()
        {
            var requestToken    = (String)Request.QueryString["oauth_token"];
            var requestSecret   = (String)Session["requestSecret"];
            var requestVerifier = (String)Request.QueryString["oauth_verifier"];


            OAuth.AccessToken       = requestToken;
            OAuth.AccessTokenSecret = requestVerifier;
            OAuth.AccessTokenGet(requestToken, requestVerifier);

            JArray profile = userinfo.Get_Users_LookUp_ByScreenName(OAuth, OAuth.TwitterScreenName);
            User   user    = (User)Session["LoggedUser"];
            SocialProfilesRepository socioprofilerepo = new SocialProfilesRepository();
            SocialProfile            socioprofile     = new SocialProfile();

            #region for managing referrals
            ManageReferrals(OAuth);
            #endregion

            foreach (var item in profile)
            {
                try
                {
                    twitterAccount.FollowingCount = Convert.ToInt32(item["friends_count"].ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                try
                {
                    twitterAccount.FollowersCount = Convert.ToInt32(item["followers_count"].ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                twitterAccount.Id          = Guid.NewGuid();
                twitterAccount.IsActive    = true;
                twitterAccount.OAuthSecret = OAuth.AccessTokenSecret;
                twitterAccount.OAuthToken  = OAuth.AccessToken;
                try
                {
                    twitterAccount.ProfileImageUrl = item["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                try
                {
                    twitterAccount.ProfileUrl = string.Empty;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                try
                {
                    twitterAccount.TwitterUserId = item["id_str"].ToString().TrimStart('"').TrimEnd('"');
                }
                catch (Exception er)
                {
                    try
                    {
                        twitterAccount.TwitterUserId = item["id"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception err)
                    {
                        Console.WriteLine(err.StackTrace);
                    }
                    Console.WriteLine(er.StackTrace);
                }

                try
                {
                    twitterAccount.TwitterScreenName = item["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                twitterAccount.UserId = user.Id;

                socioprofile.Id          = Guid.NewGuid();
                socioprofile.ProfileDate = DateTime.Now;
                socioprofile.ProfileId   = twitterAccount.TwitterUserId;
                socioprofile.ProfileType = "twitter";
                socioprofile.UserId      = user.Id;

                if (HttpContext.Current.Session["login"] != null)
                {
                    if (HttpContext.Current.Session["login"].ToString().Equals("twitter"))
                    {
                        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    = twitterAccount.TwitterName;
                        usr.Password    = regObject.MD5Hash(twitterAccount.TwitterName);
                        usr.EmailId     = "";
                        usr.UserStatus  = 1;
                        if (!userrepo.IsUserExist(usr.EmailId))
                        {
                            UserRepository.Add(usr);
                        }
                    }
                }

                TwitterStatsRepository objTwtstats = new TwitterStatsRepository();
                TwitterStats           objStats    = new TwitterStats();
                Random rNum = new Random();
                objStats.Id             = Guid.NewGuid();
                objStats.TwitterId      = twitterAccount.TwitterUserId;
                objStats.UserId         = user.Id;
                objStats.FollowingCount = twitterAccount.FollowingCount;
                objStats.FollowerCount  = twitterAccount.FollowersCount;
                objStats.Age1820        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age2124        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age2534        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age3544        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age4554        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age5564        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age65          = rNum.Next(twitterAccount.FollowersCount);
                objStats.EntryDate      = DateTime.Now;
                if (!objTwtstats.checkTwitterStatsExists(twitterAccount.TwitterUserId, user.Id))
                {
                    objTwtstats.addTwitterStats(objStats);
                }
                if (!twtrepo.checkTwitterUserExists(twitterAccount.TwitterUserId, user.Id))
                {
                    twtrepo.addTwitterkUser(twitterAccount);
                    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        = twitterAccount.TwitterUserId;
                            teammemberprofile.ProfileType      = "twitter";
                            teammemberprofile.StatusUpdateDate = DateTime.Now;

                            objTeamMemberProfileRepository.addNewTeamMember(teammemberprofile);
                        }
                    }
                    else
                    {
                        socioprofilerepo.updateSocialProfile(socioprofile);
                    }
                }
                else
                {
                    HttpContext.Current.Session["alreadyexist"] = twitterAccount;
                    twtrepo.updateTwitterUser(twitterAccount);
                    TwitterMessageRepository twtmsgreponew = new TwitterMessageRepository();
                    twtmsgreponew.updateScreenName(twitterAccount.TwitterUserId, twitterAccount.TwitterScreenName);
                    if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                    {
                        socioprofilerepo.addNewProfileForUser(socioprofile);
                    }
                    else
                    {
                        socioprofilerepo.updateSocialProfile(socioprofile);
                    }
                }
                if (Session["UserAndGroupsForTwitter"] != null)
                {
                    if (Session["UserAndGroupsForTwitter"].ToString() == "twitter")
                    {
                        try
                        {
                            if (Session["GroupName"] != null)
                            {
                                Groups                 group            = (Groups)Session["GroupName"];
                                GroupProfile           groupprofile     = new GroupProfile();
                                GroupProfileRepository groupprofilerepo = new GroupProfileRepository();
                                groupprofile.Id           = Guid.NewGuid();
                                groupprofile.ProfileId    = socioprofile.ProfileId;
                                groupprofile.ProfileType  = "twitter";
                                groupprofile.GroupOwnerId = user.Id;
                                groupprofile.EntryDate    = DateTime.Now;
                                groupprofile.GroupId      = group.Id;
                                if (!groupprofilerepo.checkGroupProfileExists(user.Id, group.Id, groupprofile.ProfileId))
                                {
                                    groupprofilerepo.AddGroupProfile(groupprofile);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.StackTrace);
                        }
                    }
                }
            }
        }
Example #8
0
        public void GetLinkedInUserProfile(dynamic data, oAuthLinkedIn _oauth, Guid user, string LinkedinUserId)
        {
            SocialProfile             socioprofile       = new SocialProfile();
            SocialProfilesRepository  socioprofilerepo   = new SocialProfilesRepository();
            LinkedInAccount           objLinkedInAccount = new LinkedInAccount();
            LinkedInAccountRepository objLiRepo          = new LinkedInAccountRepository();

            try
            {
                objLinkedInAccount.UserId         = user;
                objLinkedInAccount.LinkedinUserId = data.id.ToString();
                try
                {
                    objLinkedInAccount.EmailId = data.email.ToString();
                }
                catch { }
                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 { }
                try
                {
                    objLinkedInAccount.ProfileUrl = data.profile_url.ToString();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                objLinkedInAccount.Connections = data.connections;
                objLinkedInAccount.IsActive    = true;

                socioprofile.UserId        = user;
                socioprofile.ProfileType   = "linkedin";
                socioprofile.ProfileId     = LinkedinUserId;
                socioprofile.ProfileStatus = 1;
                socioprofile.ProfileDate   = DateTime.Now;
                socioprofile.Id            = Guid.NewGuid();
            }
            catch
            {
            }
            try
            {
                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        = socioprofile.ProfileId;
                        teammemberprofile.ProfileType      = "linkedin";
                        teammemberprofile.StatusUpdateDate = DateTime.Now;

                        objTeamMemberProfileRepository.addNewTeamMember(teammemberprofile);
                    }
                }
                else
                {
                    socioprofile.ProfileId = data.id.ToString();
                    socioprofilerepo.updateSocialProfile(socioprofile);
                }
                if (!objLiRepo.checkLinkedinUserExists(LinkedinUserId, user))
                {
                    objLiRepo.addLinkedinUser(objLinkedInAccount);
                }
                else
                {
                    objLinkedInAccount.LinkedinUserId = LinkedinUserId;
                    objLiRepo.updateLinkedinUser(objLinkedInAccount);
                }
                // GetLinkedInFeeds(_oauth, data.id, user.Id);
            }
            catch
            {
            }
        }
        private void GetAccessToken()
        {
            try
            {
                User user = (User)Session["LoggedUser"];
                if (user == null)
                {
                    Response.Redirect("Default.aspx");
                }
                oAuthTumbler requestHelper = new oAuthTumbler();



                string code = Request.QueryString["oauth_verifier"];
                string AccessTokenResponse = string.Empty;

                try
                {
                    AccessTokenResponse = requestHelper.GetAccessToken(oAuthTumbler.TumblrToken, code);
                }
                catch (Exception ex)
                {
                    logger.Error("AccessTokenResponse: " + ex.Message);
                    logger.Error("AccessTokenResponse: " + ex.StackTrace);
                }

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

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


                string sstr = string.Empty;

                try
                {
                    sstr = oAuthTumbler.OAuthData(Globals.UsersDashboardUrl, "GET", LoginDetails.Key, LoginDetails.Value, null);
                }
                catch (Exception ex)
                {
                    logger.Error("sstr: " + ex.Message);
                    logger.Error("sstr: " + ex.StackTrace);
                }

                JObject profile = new JObject();
                try
                {
                    profile = JObject.Parse(oAuthTumbler.OAuthData(Globals.UsersInfoUrl, "GET", LoginDetails.Key, LoginDetails.Value, null));
                }
                catch (Exception ex)
                {
                    logger.Error("profile: " + ex.Message);
                    logger.Error("profile: " + ex.StackTrace);
                }
                JObject                  UserDashboard               = JObject.Parse(oAuthTumbler.OAuthData(Globals.UsersDashboardUrl, "GET", LoginDetails.Key, LoginDetails.Value, null));
                TumblrAccount            objTumblrAccount            = new TumblrAccount();
                TumblrAccountRepository  objTumblrAccountRepository  = new TumblrAccountRepository();
                SocialProfile            objSocialProfile            = new SocialProfile();
                SocialProfilesRepository objSocialProfilesRepository = new SocialProfilesRepository();
                objSocialProfile.Id        = Guid.NewGuid();
                objSocialProfile.UserId    = user.Id;
                objSocialProfile.ProfileId = profile["response"]["user"]["name"].ToString();

                objSocialProfile.ProfileType   = "tumblr";
                objSocialProfile.ProfileDate   = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;

                objTumblrAccount.Id                    = Guid.NewGuid();
                objTumblrAccount.tblrUserName          = profile["response"]["user"]["name"].ToString();
                objTumblrAccount.UserId                = user.Id;
                objTumblrAccount.tblrAccessToken       = accessToken;
                objTumblrAccount.tblrAccessTokenSecret = accessTokenSecret;


                objTumblrAccount.tblrProfilePicUrl = profile["response"]["user"]["name"].ToString();
                objTumblrAccount.IsActive          = 1;
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    if (!objTumblrAccountRepository.checkTubmlrUserExists(objTumblrAccount))
                    {
                        TumblrAccountRepository.Add(objTumblrAccount);

                        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        = objTumblrAccount.tblrUserName;
                            teammemberprofile.ProfileType      = "tumblr";
                            teammemberprofile.StatusUpdateDate = DateTime.Now;

                            objTeamMemberProfileRepository.addNewTeamMember(teammemberprofile);
                        }
                    }
                }
                else
                {
                    if (!objTumblrAccountRepository.checkTubmlrUserExists(objTumblrAccount))
                    {
                        TumblrAccountRepository.Add(objTumblrAccount);
                    }
                    else
                    {
                        Response.Redirect("Home.aspx");
                    }
                }

                JArray objJarray = (JArray)UserDashboard["response"]["posts"];

                logger.Error("objJarray: " + objJarray);

                if (objJarray != null)
                {
                    logger.Error("objJarray lenght : " + objJarray.Count);
                }
                else
                {
                    logger.Error("objJarray is NULL");
                }

                TumblrFeed           objTumblrFeed           = new TumblrFeed();
                TumblrFeedRepository objTumblrFeedRepository = new TumblrFeedRepository();
                foreach (var item in objJarray)
                {
                    objTumblrFeed.Id     = Guid.NewGuid();
                    objTumblrFeed.UserId = user.Id;
                    try
                    {
                        objTumblrFeed.ProfileId = profile["response"]["user"]["name"].ToString();
                        logger.Error("objTumblrFeed.ProfileId : " + objTumblrFeed.ProfileId);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        objTumblrFeed.blogname = item["blog_name"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        objTumblrFeed.blogId = item["id"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        objTumblrFeed.blogposturl = item["post_url"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        String result = item["caption"].ToString();
                        objTumblrFeed.description = Regex.Replace(result, @"<[^>]*>", String.Empty);
                    }
                    catch (Exception ex)
                    {
                        objTumblrFeed.description = null;
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        objTumblrFeed.slug = item["slug"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        objTumblrFeed.type = item["type"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        string   test = item["date"].ToString();
                        DateTime dt;
                        if (test.Contains("GMT"))
                        {
                            test = test.Replace("GMT", "").Trim().ToString();
                            dt   = Convert.ToDateTime(test);
                        }
                        else
                        {
                            test = test.Replace("GMT", "").Trim().ToString();
                            dt   = Convert.ToDateTime(test);
                        }
                        objTumblrFeed.date = dt;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        objTumblrFeed.reblogkey = item["reblog_key"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        string str = item["liked"].ToString();
                        if (str == "False")
                        {
                            objTumblrFeed.liked = 0;
                        }
                        else
                        {
                            objTumblrFeed.liked = 1;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        string str = item["followed"].ToString();
                        if (str == "false")
                        {
                            objTumblrFeed.followed = 0;
                        }
                        else
                        {
                            objTumblrFeed.followed = 1;
                        }
                        // objTumblrDashboard.followed = Convert.ToInt16(item["followed"]);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        objTumblrFeed.canreply = Convert.ToInt16(item["can_reply"]);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        objTumblrFeed.sourceurl = item["source_url"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        objTumblrFeed.sourcetitle = item["source_title"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        JArray asdasd12 = (JArray)item["photos"];
                        foreach (var item1 in asdasd12)
                        {
                            objTumblrFeed.imageurl = item1["original_size"]["url"].ToString();
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        objTumblrFeed.videourl = item["permalink_url"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }

                    try
                    {
                        string str = item["note_count"].ToString();
                        objTumblrFeed.notes = Convert.ToInt16(str);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }

                    objTumblrFeed.timestamp = DateTime.Now;
                    if (!objTumblrFeedRepository.checkTumblrMessageExists(objTumblrFeed))
                    {
                        try
                        {
                            logger.Error("objTumblrFeedRepository.checkTumblrMessageExists " + objTumblrAccount.Id);
                            TumblrFeedRepository.Add(objTumblrFeed);
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Exception : objTumblrFeedRepository.checkTumblrMessageExists " + objTumblrAccount.Id);
                            logger.Error(ex.Message);
                            logger.Error(ex.StackTrace);
                        }
                    }
                }
                Response.Redirect("Home.aspx");
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
            }
        }