public override WeblogPost GetPost(string postId, string blogId) { if (!int.TryParse(postId, out int id) || id < 1) { throw new InvalidOperationException("Invalid PostId. Please make sure you provide an Id of an existing post."); } var post = PostBusiness.Load(id); if (post == null) { throw new ArgumentException("Unable to retrieve Post: " + UserBusiness.ErrorMessage); } var blogPost = new WeblogPost() { BlogId = "1", // only one blog so we hardcode this PostId = post.Id.ToString(), Abstract = post.Abstract, Body = post.Body, RawPostText = post.Markdown, DateCreated = post.Created, Url = PostBusiness.GetPostUrl(post), }; blogPost.PermaLink = blogPost.Url; if (!string.IsNullOrEmpty(post.Categories)) { blogPost.Categories = post.Categories; } return(blogPost); }
public void NewWeblogPostTest() { var post = new WeblogPost() { PostId = "1683236", Title = "UPDATED! A new Test Post", Body = "This is a long post with pointless points.", Abstract = "This is an abstracted abstract that's just as pointless - and longer.", Author = "Rick Strahl", DateCreated = DateTime.Now, RawPostText = "Markdown Text goes **here**.", Location = "Paia, HI", ImageUrl = "http://*****:*****@west-wind.com", "testing"); Assert.IsNotNull(token); var postId = client.UploadPost(post); Assert.IsNotNull(postId); Assert.IsNotEmpty(postId); }
public string GenerateCounter(WeblogPost post) { string url = Globals.FullPath(BlogUrls.Instance().Post(post)); string title = post.Subject; return(DotNetShoutoutCounterGenerator.Generate(url, title, _borderColor, _textBackColor, _textForeColor, _countBackColor, _countForeColor)); }
public ActionResult DeleteConfirmed(int id) { WeblogPost weblogpost = db.WeblogPosts.Find(id); db.WeblogPosts.Remove(weblogpost); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(WeblogPost weblogpost) { if (ModelState.IsValid) { db.Entry(weblogpost).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(weblogpost)); }
public ActionResult Edit(int id = 0) { WeblogPost weblogpost = db.WeblogPosts.Find(id); if (weblogpost == null) { return(HttpNotFound()); } return(View(weblogpost)); }
private void OnPreRenderPost(IContent content, CSPostEventArgs e) { if (e.ApplicationType == ApplicationType.Weblog) { WeblogPost post = content as WeblogPost; if ((post != null) && ((post.BlogPostType == BlogPostType.Post) || (post.BlogPostType == BlogPostType.Article))) { content.FormattedBody = string.Concat(content.FormattedBody, GenerateCounter(post)); } } }
public ActionResult Create(WeblogPost weblogpost) { //weblogpost.PostDateTime = DateTime.Now; weblogpost.PostDateTime = new Portal.CommonLibrary.PersianDateTime().GregorianToShamsi(DateTime.Now); weblogpost.Writer = User.Identity.Name; //weblogpost.PostContent = Server.HtmlEncode(weblogpost.PostContent); if (ModelState.IsValid) { db.WeblogPosts.Add(weblogpost); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(weblogpost)); }
public string UploadPost(WeblogPost post, string relativeUrl = "/posts") { var settings = new HttpRequestSettings { Content = post, Url = ApiBaseUrl + relativeUrl, HttpVerb = "POST" }; settings.Headers.Add("Authorization", $"Bearer {AuthenticationToken}"); string postId = null; try { postId = HttpUtils.JsonRequest <string>(settings); } catch (Exception ex) { SetError("Failed to send Post: " + ex.Message); } return(postId); }
public override string UploadPost([FromBody] WeblogPost post) { int.TryParse(post.PostId, out int postId); if (postId < 1) { postId = 0; } Post lastPost = null; Post newPost = null; if (postId > 0) { newPost = PostBusiness.Load(postId); } if (newPost == null) { newPost = PostBusiness.Create(); lastPost = PostBusiness.LoadLastPost(); newPost.Location = lastPost.Location; } newPost.Title = post.Title; newPost.Body = post.Body; newPost.Abstract = post.Abstract; newPost.Markdown = post.RawPostText; newPost.Author = post.Author; newPost.Active = post.PostStatus == PostStatuses.Published; newPost.ImageUrl = post.ImageUrl; if (string.IsNullOrEmpty(newPost.SafeTitle)) { newPost.SafeTitle = PostBusiness.GetSafeTitle(newPost.Title); } if (string.IsNullOrEmpty(post.Location) && lastPost != null) { newPost.Location = lastPost.Location; } if (string.IsNullOrEmpty(newPost.Author)) { newPost.Author = UserBusiness.Configuration.WeblogAuthor; } newPost.Keywords = post.Keywords; newPost.Categories = post.Categories; if (newPost.Created.Year < 2000) { newPost.Created = post.DateCreated; } if (post.CustomFields.Count > 0) { // Pass mt_updateslug to force the slug to refresh itself based on the title // and created date. var kvl = post.CustomFields.FirstOrDefault(cf => cf.Key == "mt_updateslug"); if (kvl.Key != null) { newPost.SafeTitle = PostBusiness.GetSafeTitle(newPost.Title); } // Update the created date which also changes the slug // Use with caution: This will change the URL kvl = post.CustomFields.FirstOrDefault(cf => cf.Key == "mt_date"); if (kvl.Key != null) { DateTime.TryParse(kvl.Value, out DateTime dt); if (dt > DateTime.MinValue) { newPost.Created = dt; newPost.Updated = DateTime.Now; newPost.SafeTitle = PostBusiness.GetSafeTitle(newPost.Title); // have to update the slug } } } if (!PostBusiness.Save(newPost)) { throw new InvalidOperationException(PostBusiness.ErrorMessage); } return(newPost.Id.ToString()); }
/// <summary> /// Upload a new or updated blog post. If the post has a previous /// post Id it is assumed to be an existing post that is looked up. /// </summary> /// <param name="blogId"></param> /// <param name="post"></param> /// <returns></returns> public abstract string UploadPost([FromBody] WeblogPost post);