public ActionResult ModifyBlog(ModifyBlogViewModel modifyBlogViewModel) { Response response = new Response() { Code = 0 }; Blog blog; if (ModelState.IsValid) { var category = categoryManager.Find(modifyBlogViewModel.CategoryId); if (category == null || category.Type != CategoryType.General) { response.Message = "栏目不匹配或者未找到!"; return(Json(response)); } if (blogManager.Count(b => b.Title == modifyBlogViewModel.Title) > 1) { response.Message = "标题重复了!"; return(Json(response)); } blog = blogManager.Find(modifyBlogViewModel.ID); if (blog == null) { response.Message = "该文章不存在!"; return(Json(response)); } //在已有对象上赋值 blog = Mapper.Map <ModifyBlogViewModel, Blog>(modifyBlogViewModel, blog); ////blog.Title = modifyBlogViewModel.Title; ////blog.Publish = modifyBlogViewModel.Publish; ////blog.Content = modifyBlogViewModel.editorValue; ////blog.Summary = modifyBlogViewModel.Summary; blog.Category = category; response = blogManager.Update(blog); } else { response.Message = "输入不合法!"; } return(Json(response)); }
public ActionResult ModifyBlog(int id) { Blog blog = blogManager.Find(id); if (blog == null) { return(View("Prompt", new Prompt() { Title = "错误", Message = "文章不存在!" })); } //modifyBlogViewModel.ID = blog.ID; //modifyBlogViewModel.CategoryId = blog.Category.ID; //modifyBlogViewModel.editorValue = blog.Content; //modifyBlogViewModel.Title = blog.Title; //modifyBlogViewModel.Publish = blog.Publish; //modifyBlogViewModel.Summary = blog.Summary; ModifyBlogViewModel modifyBlogViewModel = Mapper.Map <ModifyBlogViewModel>(blog); return(View(modifyBlogViewModel)); }