public static string BlogUrl(BlogModel blog, HttpRequestBase request, UrlHelper url) { return BlogUrl(new BlogSummary { Id = blog.Id, DateCreated = blog.DateCreated, Tags = blog.Tags, Title = blog.Title, }, request, url); }
public ActionResult Index(BlogModel blog) { switch (blog.Action) { case "Save": return Save(blog); case "Delete": return Delete(blog); case "Preview": case "Edit": return Preview(blog, blog.Action == "Edit"); default: throw new HttpException(400, "bad Request"); } }
public void Delete(BlogModel blog) { if (blog.Id != default(int)) { var tags = _unitOfWork.BlogTags.Find(t => t.BlogPostId == blog.Id); foreach (var t in tags) { _unitOfWork.BlogTags.Remove(t); } var dbBlog = _blogRepository.FindById(blog.Id); _blogRepository.Remove(dbBlog); _unitOfWork.SaveChanges(); } }
private ActionResult Save(BlogModel blog) { _blogger.Save(blog); return RedirectToAction("index", "Home"); }
private ActionResult Preview(BlogModel blog, bool isInEditMode) { blog.IsEditMode = isInEditMode; return View(blog); }
private BlogPost ConvertToView(BlogModel blog) { return new BlogPost { Id = blog.Id, Title = blog.Title, Content = blog.Content, DateCreated = !string.IsNullOrWhiteSpace(blog.DateCreatedText) ? Convert.ToDateTime(blog.DateCreatedText) : blog.DateCreated, BlogTags = string.IsNullOrEmpty(blog.TagsString) ? blog.Tags.Select(s => new BlogTag { Tag = new Tag { Title = s.Trim() } }).ToList() : blog.TagsString.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(s => new BlogTag { Tag = new Tag { Title = s.Trim() } }).ToList(), }; }
public void Save(BlogModel blog) { var dbBlog = ConvertToView(blog); var b = _blogRepository.FindById(blog.Id); if (b == null) { _blogRepository.Add(dbBlog); _unitOfWork.SaveChanges(); SaveBlogTags(dbBlog.Id, dbBlog.BlogTags); } else { b.Content = dbBlog.Content; b.Title = dbBlog.Title; SaveBlogTags(b.Id, dbBlog.BlogTags); _unitOfWork.SaveChanges(); } }