public ActionResult Save() { Blog blog; var blogId = Request.Form["blogId"]; if (blogId != "0") { blog = BlogModel.GetBlog(Convert.ToInt64(blogId)); } else { blog = new Blog(); } blog.Title = Request.Form["blogTitle"]; List <int> sortInts = new List <int>(); foreach (string key in Request.Form.AllKeys) { if (key.Contains("ck|") && Request.Form[key] == "true,false") { int id = Convert.ToInt32(key.Split('|')[1]); sortInts.Add(id); BlogSort sort = BlogModel.GetBlogSort(id); blog.Sorts.Add(sort); } } blog.Content = Request.Unvalidated.Form["ckeditor"]; blog.CreateTime = DateTime.Now; //TODO:标签与博客是多对多功能 blog.UserId = 1; BlogModel.AddblBlog(blog); return(RedirectToAction("Post", "Home", new{ id = blog.BlogId })); }
public ActionResult Post(int id) { Blog blog = BlogModel.GetBlog(id); //更新点击次数 BlogModel.UpdateBlogVisit(blog); //上一篇 var bortherPost = BlogModel.GetBortherPost(id); ViewData["bortherPost"] = bortherPost; //标签 ViewData["blogSort"] = BlogModel.GetBlogSorts(id); //评论 ViewData["blogComments"] = BlogModel.GetComments(id); foreach (KeyValuePair <Int64, string> post in bortherPost) { if (post.Key > id) { ViewData["nextPost"] = post; } if (post.Key < id) { ViewData["lastPost"] = post; } } //下一篇 return(View(blog)); }
// // GET: /Blog/ public ActionResult Add(int?id) { ViewData["blogSort"] = BlogModel.GetBlogSorts(); if (LoginHelper.IsEditMode && id.HasValue) { Blog blog = BlogModel.GetBlog(id.Value); return(View(blog)); } return(View()); }