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 })); }
/// <summary> /// 新增博客标签 /// </summary> /// <param name="sortName"></param> /// <returns></returns> public static BlogSort AddBlogSort(string sortName) { BlogSort sort = new BlogSort() { SortName = sortName, IsDelete = 0, CreateTime = DateTime.Now, }; ContextHelper.DbContext.BlogSorts.Add(sort); ContextHelper.DbContext.SaveChanges(); return(sort); }