Ejemplo n.º 1
0
        public async Task <ActionResult> Block(int id)
        {
            var merge = await PostMergeRequestService.GetByIdAsync(id) ?? throw new NotFoundException("待合并文章未找到");

            merge.MergeState = MergeStatus.Block;
            var b = await PostMergeRequestService.SaveChangesAsync() > 0;

            return(b ? ResultData(null, true, "操作成功!") : ResultData(null, false, "操作失败!"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Merge([FromForm] PostMergeRequestCommandBase dto)
        {
            var merge = await PostMergeRequestService.GetByIdAsync(dto.Id) ?? throw new NotFoundException("待合并文章未找到");

            Mapper.Map(dto, merge);
            var b = await PostMergeRequestService.SaveChangesAsync() > 0;

            return(b ? await Merge(merge.Id) : ResultData(null, false, "文章合并失败!"));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Get(int id)
        {
            var p = Mapper.Map <PostMergeRequestDto>(await PostMergeRequestService.GetByIdAsync(id));

            if (p != null)
            {
                p.SubmitTime = p.SubmitTime.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone));
            }

            return(ResultData(p));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> MergeCompare(int mid)
        {
            var newer = await PostMergeRequestService.GetByIdAsync(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 <PostMergeRequestDto>(), newer = newer.Mapper <PostMergeRequestDto>() }));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Reject(int id, string reason)
        {
            var merge = await PostMergeRequestService.GetByIdAsync(id) ?? throw new NotFoundException("待合并文章未找到");

            merge.MergeState = MergeStatus.Reject;
            var b = await PostMergeRequestService.SaveChangesAsync() > 0;

            if (!b)
            {
                return(ResultData(null, false, "操作失败!"));
            }

            var link    = Request.Scheme + "://" + Request.Host + "/" + merge.Post.Id + "/merge/" + id;
            var content = new Template(await System.IO.File.ReadAllTextAsync(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, "127.0.0.1"));
            return(ResultData(null, true, "合并已拒绝!"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Merge(int id)
        {
            var merge = await PostMergeRequestService.GetByIdAsync(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 = await PostMergeRequestService.SaveChangesAsync() > 0;

            if (!b)
            {
                return(ResultData(null, false, "文章合并失败!"));
            }

            string link    = Request.Scheme + "://" + Request.Host + "/" + merge.Post.Id;
            string content = new Template(await System.IO.File.ReadAllTextAsync(HostEnvironment.WebRootPath + "/template/merge-pass.html")).Set("link", link).Set("title", merge.Post.Title).Render();

            BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Title"] + "博客你提交的修改已通过", content, merge.ModifierEmail, "127.0.0.1"));
            return(ResultData(null, true, "文章合并完成!"));
        }