public void GetUserSites(string UserId, string WpUserId)
        {
            Domain.Myfashion.Domain.WordpressAccount objWordpressAccount = new Domain.Myfashion.Domain.WordpressAccount();

            objWordpressAccount = objWPAccountRepo.GetWordpressAccountById(Guid.Parse(UserId), WpUserId);
            oAuthWordpress _oAuth = new oAuthWordpress();

            _oAuth.access_token = objWordpressAccount.AccessToken;
            string  usersites = _oAuth.APIWebRequestToGetUserInfo(Globals._UserSites);
            JObject User_Site = JObject.Parse(usersites);
            var     Site_Data = User_Site["sites"];

            foreach (var site in Site_Data)
            {
                Domain.Myfashion.Domain.WordpressSites objWordpressSites = new Domain.Myfashion.Domain.WordpressSites();
                objWordpressSites.Id                = Guid.NewGuid();
                objWordpressSites.SiteId            = site["ID"].ToString();
                objWordpressSites.SiteName          = site["name"].ToString();
                objWordpressSites.Description       = site["description"].ToString();
                objWordpressSites.Post_Count        = site["post_count"].ToString();
                objWordpressSites.Subscribers_Count = site["subscribers_count"].ToString();
                objWordpressSites.SiteURL           = site["URL"].ToString();
                objWordpressSites.UserId            = Guid.Parse(UserId);
                objWordpressSites.WPUserId          = WpUserId;
                objWordpressSites.CreatedTime       = DateTime.Parse(site["options"]["created_at"].ToString());
                objWordpressSites.EntryTime         = DateTime.Now;
                if (!objWordpressSitesRepository.IsSiteAllreadyExist(objWordpressSites.UserId, objWordpressSites.WPUserId, objWordpressSites.SiteId))
                {
                    objWordpressSitesRepository.AddWordpressSites(objWordpressSites);
                }
                GetUserFeedBySite(UserId, objWordpressSites.WPUserId, objWordpressSites.SiteId, objWordpressAccount.AccessToken);
            }
        }
        public void GetUsersofblog(string UserId, string SiteId)
        {
            Domain.Myfashion.Domain.WordpressAccount objWordpressAccount = new Domain.Myfashion.Domain.WordpressAccount();
            objWordpressAccount = objWPAccountRepo.GetWordpressAccountById(Guid.Parse(UserId), SiteId);
            oAuthWordpress _oAuth = new oAuthWordpress();

            _oAuth.access_token = objWordpressAccount.AccessToken;
            string userinfo = _oAuth.APIWebRequestToGetUserInfo(Globals._Usersofblog + objWordpressAccount.PrimaryBlogId + "/users");
        }
Beispiel #3
0
 public void AddWordpressAccount(Domain.Myfashion.Domain.WordpressAccount WordpressAccount)
 {
     //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(WordpressAccount);
             transaction.Commit();
         } // End Using Trasaction
     }     // End using session
 }
        public string PostBlog(string SiteId, string WPUserId, string Message, string Tittle, string tags, string UserId, byte[] imagebytes)
        {
            //string file = string.Empty;
            //MemoryStream stream = new MemoryStream(image);
            //Image img = Image.FromStream(stream);
            //FileStream fs= stream as FileStream;
            //string filename = fs.Name;
            //string type = img.RawFormat.GetType().ToString();
            //var path = Server.MapPath("~/" + System.Configuration.ConfigurationManager.AppSettings["domain"] + "/Contents/img/upload");
            //string imageid=Guid.NewGuid().ToString();
            //file = path + "\\" + SiteId + "_" + WPUserId + "_" + imageid + ".png";
            //if (!Directory.Exists(path))
            //{
            //    Directory.CreateDirectory(path);
            //}

            //File.WriteAllBytes(file,image);
            string encodedimg = string.Empty;

            try
            {
                encodedimg = Convert.ToBase64String(imagebytes);
            }
            catch (Exception ex)
            {
            }
            Domain.Myfashion.Domain.WordpressAccount objWordpressAccount = new Domain.Myfashion.Domain.WordpressAccount();
            objWordpressAccount = objWPAccountRepo.GetWordpressAccountById(Guid.Parse(UserId), WPUserId);
            oAuthWordpress _oAuth = new oAuthWordpress();

            try
            {
                _oAuth.access_token = objWordpressAccount.AccessToken;
                string postData  = _oAuth.PostDataToPostBlog(Tittle, Message, tags, encodedimg);
                string _response = _oAuth.APIWebRequest(Globals._PostBlog.Replace("[SiteId]", SiteId), postData);
            }
            catch (Exception ex)
            {
            }
            return("Success");
        }
        public string AddWordpressAccount(string code, string UserId, string GroupId)
        {
            WordpressAccountRepository objWPAccountRepo = new WordpressAccountRepository();
            Domain.Myfashion.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Myfashion.Domain.TeamMemberProfile();
            Domain.Myfashion.Domain.WordpressAccount objWordpressAccount = new Domain.Myfashion.Domain.WordpressAccount();
            string client_id = ConfigurationManager.AppSettings["WordpessClientID"];
            string redirect_uri = ConfigurationManager.AppSettings["WordpessCallBackURL"];
            string client_secret = ConfigurationManager.AppSettings["WordpessClientSecret"];
            oAuthWordpress _oAuth = new oAuthWordpress();
            _oAuth.client_id = client_id;
            _oAuth.client_secret = client_secret;
            _oAuth.redirect_uri = redirect_uri;
            _oAuth.code = code;
            string postdata=_oAuth.PostDataToGetAccessToken();
            try
            {
                string _token = _oAuth.APIWebRequest(Globals._TokenUrl, postdata);
                string access_token = JObject.Parse(_token)["access_token"].ToString();
                _oAuth.access_token = access_token;
                //string postdata1 = _oAuth.PostDataToGetAccessToken();
                //string _me = _oAuth.APIWebRequest(Globals._UserInfo, postdata1);
                string userinfo = _oAuth.APIWebRequestToGetUserInfo(Globals._UserInfo);
                JObject WP_User = JObject.Parse(userinfo);
                #region AddWPAccount
                objWordpressAccount.Id = Guid.NewGuid();
                objWordpressAccount.WpUserId = WP_User["ID"].ToString();
                objWordpressAccount.WpUserName = WP_User["username"].ToString();
                objWordpressAccount.DisplayName = WP_User["display_name"].ToString();
                objWordpressAccount.EmailId = WP_User["email"].ToString();
                objWordpressAccount.PrimaryBlogId = WP_User["primary_blog"].ToString();
                objWordpressAccount.TokenSiteId = WP_User["token_site_id"].ToString();
                objWordpressAccount.UserAvtar = WP_User["avatar_URL"].ToString();
                objWordpressAccount.ProfileUrl = WP_User["profile_URL"].ToString();
                objWordpressAccount.SiteCount = Int32.Parse(WP_User["site_count"].ToString());
                objWordpressAccount.UserId = Guid.Parse(UserId);
                objWordpressAccount.AccessToken = access_token;
                if (!objWPAccountRepo.IsProfileAllreadyExist(objWordpressAccount.UserId, objWordpressAccount.WpUserId))
                {
                    objWPAccountRepo.AddWordpressAccount(objWordpressAccount);
                }
                #endregion

                #region AddTeamMemberProfiles
                Domain.Myfashion.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                objTeamMemberProfile.Id = Guid.NewGuid();
                objTeamMemberProfile.ProfileId = WP_User["ID"].ToString();
                objTeamMemberProfile.TeamId = objTeam.Id;
                objTeamMemberProfile.ProfileType = "wordpress";
                objTeamMemberProfile.Status = 1;
                objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                if (!objTeamMemberProfileRepo.checkTeamMemberProfile(objTeam.Id, objTeamMemberProfile.ProfileId))
                {
                    objTeamMemberProfileRepo.addNewTeamMember(objTeamMemberProfile);
                }
                #endregion
                #region AddSocialProfile
                Domain.Myfashion.Domain.SocialProfile objSocialProfile = new Domain.Myfashion.Domain.SocialProfile();
                objSocialProfile.Id = Guid.NewGuid();
                objSocialProfile.UserId = Guid.Parse(UserId);
                objSocialProfile.ProfileType = "wordpress";
                objSocialProfile.ProfileId = WP_User["ID"].ToString();
                objSocialProfile.ProfileDate = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                }

                GetUserSites(UserId, objWordpressAccount.WpUserId);

                //GetUsersofblog(UserId,objWordpressAccount.WpUserId);
                #endregion
            }
            catch (Exception ex)
            {
            }
            return "";
        }
 public string PostBlog(string SiteId, string WPUserId, string Message, string Tittle,string tags, string UserId, byte[] imagebytes)
 {
     //string file = string.Empty;
     //MemoryStream stream = new MemoryStream(image);
     //Image img = Image.FromStream(stream);
     //FileStream fs= stream as FileStream;
     //string filename = fs.Name;
     //string type = img.RawFormat.GetType().ToString();
     //var path = Server.MapPath("~/" + System.Configuration.ConfigurationManager.AppSettings["domain"] + "/Contents/img/upload");
     //string imageid=Guid.NewGuid().ToString();
     //file = path + "\\" + SiteId + "_" + WPUserId + "_" + imageid + ".png";
     //if (!Directory.Exists(path))
     //{
     //    Directory.CreateDirectory(path);
     //}
    
     //File.WriteAllBytes(file,image);
     string encodedimg = string.Empty;
     try
     {
         encodedimg = Convert.ToBase64String(imagebytes);
     }
     catch (Exception ex)
     {
     }
     Domain.Myfashion.Domain.WordpressAccount objWordpressAccount = new Domain.Myfashion.Domain.WordpressAccount();
     objWordpressAccount = objWPAccountRepo.GetWordpressAccountById(Guid.Parse(UserId), WPUserId);
     oAuthWordpress _oAuth = new oAuthWordpress();
     try
     {
         _oAuth.access_token = objWordpressAccount.AccessToken;
         string postData = _oAuth.PostDataToPostBlog(Tittle, Message, tags, encodedimg);
         string _response = _oAuth.APIWebRequest(Globals._PostBlog.Replace("[SiteId]", SiteId), postData);
     }
     catch (Exception ex)
     {
     }
     return "Success";
 }
 public void GetUserSites(string UserId, string WpUserId)
 {
     Domain.Myfashion.Domain.WordpressAccount objWordpressAccount = new Domain.Myfashion.Domain.WordpressAccount();
     
     objWordpressAccount = objWPAccountRepo.GetWordpressAccountById(Guid.Parse(UserId), WpUserId);
     oAuthWordpress _oAuth = new oAuthWordpress();
     _oAuth.access_token = objWordpressAccount.AccessToken;
     string usersites = _oAuth.APIWebRequestToGetUserInfo(Globals._UserSites);
     JObject User_Site = JObject.Parse(usersites);
     var Site_Data = User_Site["sites"];
     foreach (var site in Site_Data)
     {
         Domain.Myfashion.Domain.WordpressSites objWordpressSites = new Domain.Myfashion.Domain.WordpressSites();
         objWordpressSites.Id = Guid.NewGuid();
         objWordpressSites.SiteId = site["ID"].ToString();
         objWordpressSites.SiteName = site["name"].ToString();
         objWordpressSites.Description = site["description"].ToString();
         objWordpressSites.Post_Count = site["post_count"].ToString();
         objWordpressSites.Subscribers_Count = site["subscribers_count"].ToString();
         objWordpressSites.SiteURL = site["URL"].ToString();
         objWordpressSites.UserId = Guid.Parse(UserId);
         objWordpressSites.WPUserId = WpUserId;
         objWordpressSites.CreatedTime = DateTime.Parse(site["options"]["created_at"].ToString());
         objWordpressSites.EntryTime = DateTime.Now;
         if (!objWordpressSitesRepository.IsSiteAllreadyExist(objWordpressSites.UserId, objWordpressSites.WPUserId, objWordpressSites.SiteId))
         {
             objWordpressSitesRepository.AddWordpressSites(objWordpressSites);
         }
         GetUserFeedBySite(UserId, objWordpressSites.WPUserId, objWordpressSites.SiteId, objWordpressAccount.AccessToken);
     }
 }
 public void GetUsersofblog(string UserId, string SiteId)
 {
     Domain.Myfashion.Domain.WordpressAccount objWordpressAccount = new Domain.Myfashion.Domain.WordpressAccount();
     objWordpressAccount = objWPAccountRepo.GetWordpressAccountById(Guid.Parse(UserId),SiteId);
     oAuthWordpress _oAuth = new oAuthWordpress();
     _oAuth.access_token = objWordpressAccount.AccessToken;
     string userinfo = _oAuth.APIWebRequestToGetUserInfo(Globals._Usersofblog + objWordpressAccount.PrimaryBlogId + "/users");
 }
Beispiel #9
0
 public string GetWordpressAccountById(string userid, string wpid)
 {
     Domain.Myfashion.Domain.WordpressAccount wpacc = WpAccountRepo.GetWordpressAccountById(Guid.Parse(userid), wpid);
     return(new JavaScriptSerializer().Serialize(wpacc));
 }
        public string AddWordpressAccount(string code, string UserId, string GroupId)
        {
            WordpressAccountRepository objWPAccountRepo = new WordpressAccountRepository();

            Domain.Myfashion.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Myfashion.Domain.TeamMemberProfile();
            Domain.Myfashion.Domain.WordpressAccount  objWordpressAccount  = new Domain.Myfashion.Domain.WordpressAccount();
            string         client_id     = ConfigurationManager.AppSettings["WordpessClientID"];
            string         redirect_uri  = ConfigurationManager.AppSettings["WordpessCallBackURL"];
            string         client_secret = ConfigurationManager.AppSettings["WordpessClientSecret"];
            oAuthWordpress _oAuth        = new oAuthWordpress();

            _oAuth.client_id     = client_id;
            _oAuth.client_secret = client_secret;
            _oAuth.redirect_uri  = redirect_uri;
            _oAuth.code          = code;
            string postdata = _oAuth.PostDataToGetAccessToken();

            try
            {
                string _token       = _oAuth.APIWebRequest(Globals._TokenUrl, postdata);
                string access_token = JObject.Parse(_token)["access_token"].ToString();
                _oAuth.access_token = access_token;
                //string postdata1 = _oAuth.PostDataToGetAccessToken();
                //string _me = _oAuth.APIWebRequest(Globals._UserInfo, postdata1);
                string  userinfo = _oAuth.APIWebRequestToGetUserInfo(Globals._UserInfo);
                JObject WP_User  = JObject.Parse(userinfo);
                #region AddWPAccount
                objWordpressAccount.Id            = Guid.NewGuid();
                objWordpressAccount.WpUserId      = WP_User["ID"].ToString();
                objWordpressAccount.WpUserName    = WP_User["username"].ToString();
                objWordpressAccount.DisplayName   = WP_User["display_name"].ToString();
                objWordpressAccount.EmailId       = WP_User["email"].ToString();
                objWordpressAccount.PrimaryBlogId = WP_User["primary_blog"].ToString();
                objWordpressAccount.TokenSiteId   = WP_User["token_site_id"].ToString();
                objWordpressAccount.UserAvtar     = WP_User["avatar_URL"].ToString();
                objWordpressAccount.ProfileUrl    = WP_User["profile_URL"].ToString();
                objWordpressAccount.SiteCount     = Int32.Parse(WP_User["site_count"].ToString());
                objWordpressAccount.UserId        = Guid.Parse(UserId);
                objWordpressAccount.AccessToken   = access_token;
                if (!objWPAccountRepo.IsProfileAllreadyExist(objWordpressAccount.UserId, objWordpressAccount.WpUserId))
                {
                    objWPAccountRepo.AddWordpressAccount(objWordpressAccount);
                }
                #endregion

                #region AddTeamMemberProfiles
                Domain.Myfashion.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                objTeamMemberProfile.Id               = Guid.NewGuid();
                objTeamMemberProfile.ProfileId        = WP_User["ID"].ToString();
                objTeamMemberProfile.TeamId           = objTeam.Id;
                objTeamMemberProfile.ProfileType      = "wordpress";
                objTeamMemberProfile.Status           = 1;
                objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                if (!objTeamMemberProfileRepo.checkTeamMemberProfile(objTeam.Id, objTeamMemberProfile.ProfileId))
                {
                    objTeamMemberProfileRepo.addNewTeamMember(objTeamMemberProfile);
                }
                #endregion
                #region AddSocialProfile
                Domain.Myfashion.Domain.SocialProfile objSocialProfile = new Domain.Myfashion.Domain.SocialProfile();
                objSocialProfile.Id            = Guid.NewGuid();
                objSocialProfile.UserId        = Guid.Parse(UserId);
                objSocialProfile.ProfileType   = "wordpress";
                objSocialProfile.ProfileId     = WP_User["ID"].ToString();
                objSocialProfile.ProfileDate   = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                }

                GetUserSites(UserId, objWordpressAccount.WpUserId);

                //GetUsersofblog(UserId,objWordpressAccount.WpUserId);
                #endregion
            }
            catch (Exception ex)
            {
            }
            return("");
        }