public ContentResult AddPost(Post post) { string json; ModelState.Clear(); if (TryValidateModel(post)) { var id = _blogRepository.AddPost(post); json = JsonConvert.SerializeObject(new { id = id, success = true, message = "Post added successfully." }); } else { json = JsonConvert.SerializeObject(new { id = 0, success = false, message = "Failed to add the post." }); } return Content(json, "application/json"); }
/// <summary> /// Adds a new post and returns the id. /// </summary> /// <param name="post"></param> /// <returns>Newly added post id</returns> public int AddPost(Post post) { using (var tran = _session.BeginTransaction()) { _session.Save(post); tran.Commit(); return post.Id; } }
public static MvcHtmlString PostLink(this HtmlHelper helper, Post post) { return helper.ActionLink(post.Title, "Post", "Blog", new { year = post.PostedOn.Year, month = post.PostedOn.Month, title = post.UrlSlug }, new { title = post.Title }); }
/// <summary> /// Update an existing post. /// </summary> /// <param name="post"></param> public void EditPost(Post post) { using (var tran = _session.BeginTransaction()) { _session.SaveOrUpdate(post); tran.Commit(); } }
public int AddPost(Post post) { _context.Posts.Add(post); _context.SaveChanges(); return post.Id; }
public void EditPost(Post post) { var entry = _context.Posts.Find(post.Id); entry.Category = post.Category; entry.Description = post.Description; entry.ShortDescription = post.ShortDescription; entry.Meta = post.Meta; entry.Published = post.Published; entry.Title = post.Title; entry.UrlSlug = post.UrlSlug; entry.Modified = post.Modified; _context.Tags.Load(); foreach (var tag in post.Tags.ToList()) { if (!entry.Tags.Contains(tag)) { entry.Tags.Add(tag); } } foreach (var tag in entry.Tags.ToList()) { if (!post.Tags.Contains(tag)) { entry.Tags.Remove(tag); } } _context.SaveChanges(); }
public ContentResult EditPost(Post post) { string json; ModelState.Clear(); if (TryValidateModel(post)) { _blogRepository.EditPost(post); json = JsonConvert.SerializeObject(new { id = post.Id, success = true, message = "Changes saved successfully." }); } else { json = JsonConvert.SerializeObject(new { id = 0, success = false, message = "Failed to save the changes." }); } return Content(json, "application/json"); }