public ActionResult Form(PostsForm form) { form.IsNew = form.PostId == 0; if (!ModelState.IsValid) return View(form); Post post; if(form.IsNew) { post = new Post { CreatedAt = DateTime.UtcNow, User = Auth.User }; } else { post = Database.Session.Load<Post>(form.PostId); if (post == null) return HttpNotFound(); post.UpdatedAt = DateTime.UtcNow; } post.Title = form.Title; post.Slug = form.Slug; post.Content = form.Content; Database.Session.SaveOrUpdate(post); return RedirectToAction("Index"); }
public ActionResult Form(PostsForm form) { form.IsNew = form.PostId == null; if (!ModelState.IsValid) return View(form); var selectedTags = ReconsileTags(form.Tags).ToList(); Post post; if (form.IsNew) { post = new Post { CreatedAt = DateTime.UtcNow, User = Auth.User }; foreach (var tag in selectedTags) { post.Tags.Add(tag); } } else { post = Database.Session.Load<Post>(form.PostId); if (post == null) return HttpNotFound(); post.UpdatedAt = DateTime.UtcNow; foreach (var toAdd in selectedTags.Where(t => !post.Tags.Contains(t))) { post.Tags.Add(toAdd); } foreach (var toRemove in post.Tags.Where(t => !selectedTags.Contains(t)).ToList()) { post.Tags.Remove(toRemove); } } post.Title = form.Title; post.Slug = form.Slug; post.Content = form.Content; Database.Session.SaveOrUpdate(post); return RedirectToAction("Index"); }
private WilderMinds.MetaWeblog.Post ToMetaWebLogPost(Models.Post post) { var request = _context.HttpContext.Request; string url = request.Scheme + "://" + request.Host; return(new WilderMinds.MetaWeblog.Post { postid = post.ID, title = post.Title, wp_slug = post.Slug, permalink = url + post.GetLink(), dateCreated = post.PubDate, description = post.Content, categories = post.Categories.ToArray(), mt_excerpt = post.Excerpt }); }
public Task <string> AddPostAsync(string blogid, string username, string password, Post post, bool publish) { ValidateUser(username, password); var newPost = new Models.Post { Title = post.title, Slug = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : Models.Post.CreateSlug(post.title), Content = post.description, IsPublished = publish, Categories = post.categories, Excerpt = post.mt_excerpt, PostImage = post.description.FindFirstImage() }; if (post.dateCreated != DateTime.MinValue) { newPost.PubDate = post.dateCreated; } _blog.SavePost(newPost).GetAwaiter().GetResult(); return(Task.FromResult(newPost.ID)); }