public ActionResult Edit(BlogEditModel model)
        {
            var domainModel = _blogService.GetBlogByID(model.Id);

            _blogService.SaveBlog(model.ToEntity(domainModel));
            return(RedirectToAction("List"));
        }
Exemplo n.º 2
0
        public ActionResult Edit(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(View());
            }
            Blog blog = db.Blogs.Find(id);

            if (blog == null)
            {
                return(View());
            }
            var model = new BlogEditModel()
            {
                Id         = blog.Id,
                FullName   = blog.FullName,
                MarkDelete = blog.MarkDelete,
                Content    = blog.Content,
                Closed     = blog.Closed,
            };

            model.ParentId = blog.ParentId;
            var lst = new List <string>();

            foreach (var item in blog.BlogTags)
            {
                lst.Add(item.TagBlogId.ToString());
            }

            ViewBag.TagBlogId = new SelectList(db.TagBlogs, "Id", "Name", lst);
            ViewBag.ParentId  = new SelectList(db.Blogs, "Id", "Name", model.ParentId);

            return(View(model));
        }
Exemplo n.º 3
0
 private bool CreateNewBlog(BlogEditModel model, long userId)
 {
     _blogRepository.Save(new Domain.Blog {
         UserId = userId, Title = model.Title, Content = model.Content, IsNew = true
     });
     return(true);
 }
Exemplo n.º 4
0
        public ActionResult Create(string AppId)
        {
            var model = new BlogEditModel
            {
                AppId = AppId
            };

            if (AppId != null)
            {
                var app = db.Apps.Find(AppId);
                if (app == null)
                {
                    return(View());
                }
                model.AppName = app.Name;
            }
            if (AppId != null)
            {
                var product = db.Apps.Find(AppId);
                if (product == null)
                {
                    View();
                }
                model.AppName = product.Name;
            }
            ViewBag.TagBlogId = new SelectList(db.TagBlogs, "Id", "Name");
            ViewBag.ParentId  = new SelectList(db.Blogs, "Id", "Name");
            return(View(model));
        }
Exemplo n.º 5
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 = "操作成功。" }));
        }
Exemplo n.º 6
0
        public bool SaveBlog([FromBody] BlogEditModel model)
        {
            var responce = _blogService.SaveBlog(model, _sessionContext.UserSession.UserId);

            if (responce)
            {
                ResponseModel.Message = "Blog Save Succeffully.";
            }
            return(responce);
        }
Exemplo n.º 7
0
 public Blog(BlogEditModel model) : this()
 {
     this.Id          = model.Id;
     this.FullName    = model.FullName;
     this.Name        = model.Name;
     this.Content     = model.Content;
     this.Summary     = model.Summary;
     this.LongSummary = model.LongSummary;
     this.AppId       = model.AppId;
     this.UserId      = model.UserId;
     this.LastModify  = DateTime.UtcNow;
 }
Exemplo n.º 8
0
        public virtual ActionResult Edit(long?id = null)
        {
            var editModel = new BlogEditModel();

            if (id.HasValue && id.Value > 0)
            {
                var blog = _blogService.GetBlog(id.Value);
                editModel = blog.MapTo <BlogEditModel>();
            }

            return(View(editModel));
        }
Exemplo n.º 9
0
 public bool SaveBlog(BlogEditModel model, long userId)
 {
     if (model.Id > 0)
     {
         var _blog = _blogRepository.Table.FirstOrDefault(x => x.Id == model.Id);
         if (_blog != default)
         {
             _blog.Title   = model.Title;
             _blog.Content = model.Content;
             _blogRepository.Save(_blog);
             return(true);
         }
     }
     return(CreateNewBlog(model, userId));
 }
Exemplo n.º 10
0
 public static Blog ToEntity(this BlogEditModel model, Blog destination)
 {
     return(model.MapTo(destination));
 }
Exemplo n.º 11
0
 public static Blog ToEntity(this BlogEditModel model)
 {
     return(model.MapTo <BlogEditModel, Blog>());
 }
Exemplo n.º 12
0
        public async Task <ActionResult> Edit(BlogEditModel model)
        {
            var db          = new TDContext();
            var currentUser = User.Identity.GetUserId();

            var blog = await db.Blogs.FindAsync(model.Id);

            if (blog == null)
            {
                return(Json(Js.Error("Không tìm thấy bài viết")));
            }
            blog.FullName = model.FullName;
            blog.Name     = model.FullName.GetSafeName();
            blog.Content  = await model.Content.GetValidHtml();

            blog.ReasonModify += model.ReasonModify;
            blog.MarkDelete    = model.MarkDelete;
            blog.Summary       = await blog.Content.GetSummary();

            blog.LongSummary = await blog.Content.GetSummary(500);

            blog.ModifierId = currentUser;
            blog.LastModify = DateTime.UtcNow;
            blog.Closed     = model.Closed;
            if (model.TagBlogId != null)
            {
                var lstSelect = new List <string>();
                foreach (string item in model.TagBlogId)
                {
                    Guid    tagId       = item.ToGuid();
                    TagBlog findTagBlog = null;
                    if (tagId != Guid.Empty)
                    {
                        findTagBlog = db.TagBlogs.Find(tagId);
                    }

                    if (findTagBlog == null)
                    {
                        findTagBlog = db.TagBlogs.FirstOrDefault(x => x.FullName == item);
                        if (findTagBlog == null)
                        {
                            findTagBlog = new TagBlog(); //TagBlog(item); Fix
                            db.TagBlogs.Add(findTagBlog);
                        }
                    }
                    lstSelect.Add(findTagBlog.Id);
                }
                var current = blog.BlogTags.Select(x => x.TagBlogId).ToList();
                foreach (var item in current)
                {
                    if (!lstSelect.Contains(item))
                    {
                        var find = db.BlogTags.Find(item, blog.Id);
                        if (find != null)
                        {
                            db.BlogTags.Remove(find);
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(model.ParentId))
            {
                var parent = await db.Blogs.FindAsync(model.ParentId);

                if (parent != null)
                {
                    blog.ParentId = parent.Id;
                    var lstAdd = new List <string>();
                    foreach (var item in parent.BlogTags.Select(x => x.TagBlogId))
                    {
                        if (!lstAdd.Contains(item) && !await db.BlogTags.AnyAsync(x => x.TagBlogId == item && x.BlogId == model.Id))
                        {
                            db.BlogTags.Add(new BlogTag
                            {
                                BlogId    = model.Id,
                                TagBlogId = item,
                            });
                            lstAdd.Add(item);
                        }
                    }
                }
            }

            db.Entry(blog).State = EntityState.Modified;
            var res = await db.SaveMessageAsync();

            if (!string.IsNullOrEmpty(res))
            {
                return(Json(Js.Error(res)));
            }
            return(Json(Js.SuccessRedirect(Global.BlogChanged, "/admin/blogs")));
        }
Exemplo n.º 13
0
        public async Task <ActionResult> Create(BlogEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(this.GetModelStateError().GetError()));
            }
            var db     = new TDContext();
            var UserId = User.Identity.GetUserId();

            if (db.Blogs.Any(x => x.FullName == model.FullName))
            {
                return(Json(Js.Error(Global.BlogNameUsed)));
            }

            var lstSelect = await new TagBlogDB(db).FindOrCreate(model.TagBlogId);

            model.Content = await model.Content.GetValidHtml();

            model.Summary = await model.Content.GetSummary();

            model.LongSummary = await model.Content.GetSummary(500);

            model.Name   = model.FullName.GetSafeName();
            model.Id     = new DBHelper().GetBlogId(db);
            model.UserId = UserId;

            var blog = new Blog(model);

            if (model.ParentId != null)
            {
                var parent = await db.Blogs.FindAsync(model.ParentId);

                if (parent != null)
                {
                    blog.ParentId = parent.Id;
                    foreach (var item in parent.BlogTags.Select(x => x.TagBlogId))
                    {
                        if (!lstSelect.Contains(item))
                        {
                            lstSelect.Add(item);
                        }
                    }
                }
            }


            foreach (var item in lstSelect)
            {
                blog.BlogTags.Add(new BlogTag(item, blog.Id));
            }
            var gal = new GalleryDB(db).CreateBlog(blog);

            if (!string.IsNullOrEmpty(model.ImageData))
            {
                var saveFile = await this.db.SaveImage(model.ImageData, "blogs");

                if (!saveFile.OK)
                {
                    return(Json(Js.Error(saveFile.Message)));
                }
                saveFile.Image.IsMain = true;
                gal.AppFiles.Add(saveFile.Image);
            }
            db.Blogs.Add(blog);
            var str = await db.SaveMessageAsync();

            if (str.NotNull())
            {
                return(Json(str.GetError()));
            }
            if (string.IsNullOrEmpty(model.ParentId))
            {
                var parent = await db.Blogs.FindAsync(model.ParentId);

                if (parent != null)
                {
                    blog.ParentId = parent.Id;
                    var lstAdd = new List <string>();
                    foreach (var item in parent.BlogTags.Select(x => x.TagBlogId))
                    {
                        if (!lstAdd.Contains(item) && !await db.BlogTags.AnyAsync(x => x.TagBlogId == item && x.BlogId == model.Id))
                        {
                            db.BlogTags.Add(new BlogTag
                            {
                                BlogId    = model.Id,
                                TagBlogId = item,
                            });
                            lstAdd.Add(item);
                        }
                    }
                }
            }
            return(Json(Js.SuccessRedirect(Global.BlogInserted, "/admin/blogs")));
        }
Exemplo n.º 14
0
 public static async Task <bool> SubmitBlog(BlogEditModel blog)
 {
     return(await JsnoRepo.UpdateBlog(BlogEditModel.MapToDto(blog)));
 }