public string GetTumblrAccountDetailsById(string UserId, string ProfileId)
 {
     try
     {
         Domain.Myfashion.Domain.TumblrAccount objTumblrAccount = new Domain.Myfashion.Domain.TumblrAccount();
         objTumblrAccount.UserId       = Guid.Parse(UserId);
         objTumblrAccount.tblrUserName = ProfileId;
         if (objTumblrAccountRepository.checkTubmlrUserExists(objTumblrAccount))
         {
             objTumblrAccount = objTumblrAccountRepository.getTumblrAccountDetailsById(ProfileId, Guid.Parse(UserId));
         }
         else
         {
             objTumblrAccount = objTumblrAccountRepository.getTumblrAccountDetailsById(ProfileId);
         }
         return(new JavaScriptSerializer().Serialize(objTumblrAccount));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
         return("Something Went Wrong");
     }
 }
Esempio n. 2
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.Myfashion.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.Myfashion.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.Myfashion.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                    Domain.Myfashion.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Myfashion.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);
                    #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);
        }