Exemple #1
0
        public virtual JsonResult Edit(BlogEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { MessageType = 0, MessageContent = "数据未通过验证,请检查。" }));
            }
            Model.Blogs.Blog blog;

            if (model.Id > 0)
            {
                //编辑
                blog             = _blogService.GetBlog(model.Id);
                blog             = model.MapTo(blog);
                blog.Author      = UserContext.CurrentUser;
                blog.UpdatedTime = DateTime.Now;
                blog             = _blogService.UpdateBlog(blog);
            }
            else
            {
                //新增
                blog        = model.MapTo <Model.Blogs.Blog>();
                blog.Author = UserContext.CurrentUser;
                blog        = _blogService.AddBlog(blog);
            }

            if (blog == null || blog.Id == 0)
            {
                return(Json(new { MessageType = 0, MessageContent = "操作失败。请重试" }));
            }
            return(Json(new { MessageType = 1, MessageContent = "操作成功。" }));
        }
Exemple #2
0
 public static Blog ToEntity(this BlogEditModel model, Blog destination)
 {
     return(model.MapTo(destination));
 }
Exemple #3
0
 public static Blog ToEntity(this BlogEditModel model)
 {
     return(model.MapTo <BlogEditModel, Blog>());
 }