Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 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");
     }
 }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
 private ActionResult Save(BlogModel blog)
 {
     _blogger.Save(blog);
     return RedirectToAction("index", "Home");
 }
Esempio n. 5
0
 private ActionResult Preview(BlogModel blog, bool isInEditMode)
 {
     blog.IsEditMode = isInEditMode;
     return View(blog);
 }
Esempio n. 6
0
        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(),

            };
        }
Esempio n. 7
0
        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();
            }
        }