public IActionResult Merge([FromForm] PostMergeRequestCommandBase dto) { var merge = PostMergeRequestService.GetById(dto.Id) ?? throw new NotFoundException("待合并文章未找到"); Mapper.Map(dto, merge); var b = PostMergeRequestService.SaveChanges() > 0; return(b ? Merge(merge.Id) : ResultData(null, false, "文章合并失败!")); }
public ActionResult Block(int id) { var merge = PostMergeRequestService.GetById(id) ?? throw new NotFoundException("待合并文章未找到"); merge.MergeState = MergeStatus.Block; var b = PostMergeRequestService.SaveChanges() > 0; return(b ? ResultData(null, true, "操作成功!") : ResultData(null, false, "操作失败!")); }
public IActionResult MergeCompare(int mid) { var newer = PostMergeRequestService.GetById(mid) ?? throw new NotFoundException("待合并文章未找到"); var old = newer.Post; var diffHelper = new HtmlDiff.HtmlDiff(old.Content, newer.Content); string diffOutput = diffHelper.Build(); old.Content = Regex.Replace(Regex.Replace(diffOutput, "<ins.+?</ins>", string.Empty), @"<\w+></\w+>", string.Empty); newer.Content = Regex.Replace(Regex.Replace(diffOutput, "<del.+?</del>", string.Empty), @"<\w+></\w+>", string.Empty); return(ResultData(new { old = old.Mapper <PostMergeRequestOutputDto>(), newer = newer.Mapper <PostMergeRequestOutputDto>() })); }
public ActionResult Get(int id) { var p = Mapper.Map <PostMergeRequestDto>(PostMergeRequestService.GetById(id)); if (p != null) { p.SubmitTime = p.SubmitTime.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); } return(ResultData(p)); }
public IActionResult Merge([FromForm] PostMergeRequestInputDtoBase dto) { var merge = PostMergeRequestService.GetById(dto.Id) ?? throw new NotFoundException("待合并文章未找到"); Mapper.Map(dto, merge); var b = PostMergeRequestService.UpdateEntitySaved(merge); if (b) { return(Merge(merge.Id)); } return(ResultData(null, false, "文章合并失败!")); }
public ActionResult Reject(int id, string reason) { var merge = PostMergeRequestService.GetById(id) ?? throw new NotFoundException("待合并文章未找到"); merge.MergeState = MergeStatus.Reject; var b = PostMergeRequestService.UpdateEntitySaved(merge); if (b) { string link = Request.Scheme + "://" + Request.Host + "/" + merge.Post.Id + "/merge/" + id; string content = System.IO.File.ReadAllText(HostingEnvironment.WebRootPath + "/template/merge-reject.html").Replace("{{link}}", link).Replace("{{title}}", merge.Post.Title).Replace("{{reason}}", reason); BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Title"] + "博客你提交的修改已被拒绝", content, merge.ModifierEmail)); return(ResultData(null, true, "合并已拒绝!")); } return(ResultData(null, false, "操作失败!")); }
public ActionResult Reject(int id, string reason) { var merge = PostMergeRequestService.GetById(id) ?? throw new NotFoundException("待合并文章未找到"); merge.MergeState = MergeStatus.Reject; var b = PostMergeRequestService.SaveChanges() > 0; if (!b) { return(ResultData(null, false, "操作失败!")); } var link = Request.Scheme + "://" + Request.Host + "/" + merge.Post.Id + "/merge/" + id; var content = new Template(System.IO.File.ReadAllText(HostEnvironment.WebRootPath + "/template/merge-reject.html")).Set("link", link).Set("title", merge.Post.Title).Set("reason", reason).Render(); BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Title"] + "博客你提交的修改已被拒绝", content, merge.ModifierEmail)); return(ResultData(null, true, "合并已拒绝!")); }
public IActionResult Merge(int id) { var merge = PostMergeRequestService.GetById(id) ?? throw new NotFoundException("待合并文章未找到"); var history = merge.Post.Mapper <PostHistoryVersion>(); history.Id = 0; merge.Post = Mapper.Map(merge, merge.Post); merge.Post.PostHistoryVersion.Add(history); merge.Post.ModifyDate = DateTime.Now; merge.MergeState = MergeStatus.Merged; var b = PostMergeRequestService.UpdateEntitySaved(merge); if (b) { string link = Request.Scheme + "://" + Request.Host + "/" + merge.Post.Id; string content = System.IO.File.ReadAllText(HostingEnvironment.WebRootPath + "/template/merge-pass.html").Replace("{{link}}", link).Replace("{{title}}", merge.Post.Title); BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Title"] + "博客你提交的修改已通过", content, merge.ModifierEmail)); return(ResultData(null, true, "文章合并完成!")); } return(ResultData(null, false, "文章合并失败!")); }
public ActionResult Get(int id) { return(ResultData(Mapper.Map <PostMergeRequestOutputDto>(PostMergeRequestService.GetById(id)))); }