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.Socioboard.Domain.WordpressAccount objWordpressAccount = new Domain.Socioboard.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.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); Domain.Socioboard.Domain.WordpressAccount objWordpressAccount = new Domain.Socioboard.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.Socioboard.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.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.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(""); }