예제 #1
0
        public ActionResult Details(int id, string kw)
        {
            Post post = PostBll.GetById(id);

            if (post != null)
            {
                ViewBag.Keyword = post.Keyword + "," + post.Label;
                UserInfoOutputDto user       = Session.GetByRedis <UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();
                DateTime          modifyDate = post.ModifyDate;
                ViewBag.Next = PostBll.GetFirstEntityFromL2CacheNoTracking(p => p.ModifyDate > modifyDate && (p.Status == Status.Pended || user.IsAdmin), p => p.ModifyDate);
                ViewBag.Prev = PostBll.GetFirstEntityFromL2CacheNoTracking(p => p.ModifyDate < modifyDate && (p.Status == Status.Pended || user.IsAdmin), p => p.ModifyDate, false);
                if (user.IsAdmin)
                {
                    return(View("Details_Admin", post));
                }

                if (post.Status != Status.Pended)
                {
                    return(RedirectToAction("Post", "Home"));
                }

                if (string.IsNullOrEmpty(Session.GetByRedis <string>("post" + id)))
                {
                    HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.RecordPostVisit), args: id);
                    Session.SetByRedis("post" + id, id.ToString());
                }
                return(View(post));
            }

            return(RedirectToAction("Index", "Error"));
        }
예제 #2
0
        public async Task <ActionResult> GetMessages()
        {
            var post = (await PostBll.LoadEntitiesFromCacheNoTrackingAsync(p => p.Status == Status.Pending).ConfigureAwait(false)).Select(p => new
            {
                p.Id,
                p.Title,
                p.PostDate,
                p.Author
            });
            var msgs = (await LeaveMessageBll.LoadEntitiesFromCacheNoTrackingAsync(m => m.Status == Status.Pending).ConfigureAwait(false)).Select(p => new
            {
                p.Id,
                p.PostDate,
                p.NickName
            });
            var comments = (await CommentBll.LoadEntitiesFromCacheNoTrackingAsync(c => c.Status == Status.Pending).ConfigureAwait(false)).Select(p => new
            {
                p.Id,
                p.CommentDate,
                p.PostId,
                p.NickName
            });

            return(ResultData(new
            {
                post,
                msgs,
                comments
            }));
        }
예제 #3
0
        public ActionResult Pass(int id)
        {
            Post post = PostBll.GetById(id);

            post.Status     = Status.Pended;
            post.ModifyDate = DateTime.Now;
            post.PostDate   = DateTime.Now;
            bool   b    = PostBll.UpdateEntitySaved(post);
            var    cast = BroadcastBll.LoadEntities(c => c.Status == Status.Subscribed).ToList();
            string link = Request.Url?.Scheme + "://" + Request.Url?.Authority + "/" + id;

            cast.ForEach(c =>
            {
                var ts         = DateTime.Now.GetTotalMilliseconds();
                string content = System.IO.File.ReadAllText(Request.MapPath("/template/broadcast.html")).Replace("{{link}}", link + "?email=" + c.Email).Replace("{{time}}", post.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss")).Replace("{{title}}", post.Title).Replace("{{author}}", post.Author).Replace("{{content}}", post.Content.RemoveHtmlTag(150)).Replace("{{cancel}}", Url.Action("Subscribe", "Subscribe", new
                {
                    c.Email,
                    act      = "cancel",
                    validate = c.ValidateCode,
                    timespan = ts,
                    hash     = (c.Email + "cancel" + c.ValidateCode + ts).AESEncrypt(ConfigurationManager.AppSettings["BaiduAK"])
                }, Request.Url.Scheme));
                BackgroundJob.Enqueue(() => SendMail(GetSettings("Title") + "博客有新文章发布了", content, c.Email));
            });
            HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.UpdateLucene));
            return(ResultData(null, b, b ? "审核通过!" : "审核失败!"));
        }
예제 #4
0
        /// <summary>
        /// 获取所有文章
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAllData()
        {
            var plist = PostBll.LoadEntitiesNoTracking(p => p.Status != Status.Deleted).OrderBy(p => p.Status).ThenByDescending(p => p.IsFixedTop).ThenByDescending(p => p.ModifyDate).Select(p => new
            {
                p.Id,
                p.Author,
                CategoryName = p.Category.Name,
                p.Email,
                p.IsFixedTop,
                p.Label,
                md = p.ModifyDate,
                pd = p.PostDate,
                p.Title,
                ViewCount = p.PostAccessRecord.Sum(r => r.ClickCount),
                p.VoteDownCount,
                p.VoteUpCount,
                stat = p.Status
            }).ToList();
            var list = new List <PostDataModel>();

            plist.ForEach(item =>
            {
                PostDataModel model = item.MapTo <PostDataModel>();
                model.PostDate      = item.pd.ToString("yyyy-MM-dd HH:mm");
                model.ModifyDate    = item.md.ToString("yyyy-MM-dd HH:mm");
                model.Status        = item.stat.GetDisplay();
                list.Add(model);
            });
            return(ResultData(list));
        }
예제 #5
0
        public ActionResult All()
        {
            UserInfoOutputDto user   = Session.GetByRedis <UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();
            List <string>     tags   = PostBll.GetAll().Select(p => p.Label).ToList();//tag
            List <string>     result = new List <string>();

            tags.ForEach(s =>
            {
                if (!string.IsNullOrEmpty(s))
                {
                    result.AddRange(s.Split(',', ','));
                }
            });
            ViewBag.tags = result.GroupBy(t => t).OrderByDescending(g => g.Count()).ThenBy(g => g.Key);
            ViewBag.cats = CategoryBll.GetAll(c => c.Post.Count, false).Select(c => new TagCloudViewModel()
            {
                Id    = c.Id,
                Name  = c.Name,
                Count = c.Post.Count(p => p.Status == Status.Pended || user.IsAdmin)
            }).ToList();//category
            ViewBag.seminars = SeminarBll.GetAll(c => c.Post.Count, false).Select(c => new TagCloudViewModel
            {
                Id    = c.Id,
                Name  = c.Title,
                Count = c.Post.Count(p => p.Status == Status.Pended || user.IsAdmin)
            }).ToList(); //seminars
            return(View());
        }
예제 #6
0
        public ActionResult GetPending(int page = 1, int size = 10, string search = "")
        {
            int total;
            IQueryable <Post> temp;

            if (string.IsNullOrEmpty(search))
            {
                temp = PostBll.LoadPageEntitiesNoTracking(page, size, out total, p => p.Status == Status.Pending, p => p.Id);
            }
            else
            {
                temp = PostBll.LoadPageEntitiesNoTracking(page, size, out total, p => p.Status == Status.Pending && (p.Title.Contains(search) || p.Author.Contains(search) || p.Email.Contains(search) || p.Label.Contains(search)), p => p.Id);
            }
            var plist = temp.OrderByDescending(p => p.IsFixedTop).ThenByDescending(p => p.ModifyDate).Select(p => new { p.Id, p.Author, CategoryName = p.Category.Name, p.Email, p.IsFixedTop, p.Label, md = p.ModifyDate, pd = p.PostDate, p.Title, ViewCount = p.PostAccessRecord.Any() ? p.PostAccessRecord.Sum(r => r.ClickCount) : 1, p.VoteDownCount, p.VoteUpCount, stat = p.Status }).ToList();
            var list  = new List <PostDataModel>();

            plist.ForEach(item =>
            {
                PostDataModel model = item.MapTo <PostDataModel>();
                model.PostDate      = item.pd.ToString("yyyy-MM-dd HH:mm");
                model.ModifyDate    = item.md.ToString("yyyy-MM-dd HH:mm");
                model.Status        = item.stat.GetDisplay();
                list.Add(model);
            });
            var pageCount = Math.Ceiling(total * 1.0 / size).ToInt32();

            return(PageResult(list, pageCount, total));
        }
        public ActionResult Pass(int id)
        {
            Comment comment = CommentBll.GetById(id);

            comment.Status = Status.Pended;
            Post post = PostBll.GetById(comment.PostId);
            bool b    = CommentBll.UpdateEntitySaved(comment);
            var  pid  = comment.ParentId == 0 ? comment.Id : CommentBll.GetParentCommentIdByChildId(id);

#if !DEBUG
            string content = System.IO.File.ReadAllText(Request.MapPath("/template/notify.html")).Replace("{{title}}", post.Title).Replace("{{time}}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Replace("{{nickname}}", comment.NickName).Replace("{{content}}", comment.Content);
            var    emails  = CommentBll.GetSelfAndAllChildrenCommentsByParentId(pid).Select(c => c.Email).Distinct().Except(new List <string>()
            {
                comment.Email,
                GetSettings("ReceiveEmail")
            }).ToList();
            string link = Url.Action("Details", "Post", new
            {
                id  = comment.PostId,
                cid = pid
            }, Request.Url.Scheme) + "#comment";
            foreach (var email in emails)
            {
                BackgroundJob.Enqueue(() => SendMail($"{Request.Url.Authority}{GetSettings("Title")}文章评论回复:", content.Replace("{{link}}", link), email));
            }
#endif
            return(ResultData(null, b, b ? "审核通过!" : "审核失败!"));
        }
예제 #8
0
        public async Task <ActionResult> Tag(string id, int page = 1, int size = 10, OrderBy orderBy = OrderBy.ModifyDate)
        {
            IList <PostOutputDto> posts;
            UserInfoOutputDto     user = Session.GetByRedis <UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();
            var temp = PostBll.LoadEntitiesNoTracking <PostOutputDto>(p => p.Label.Contains(id) && (p.Status == Status.Pended || user.IsAdmin)).OrderByDescending(p => p.IsFixedTop);

            switch (orderBy)
            {
            case OrderBy.CommentCount:
                posts = temp.ThenByDescending(p => p.Comment.Count).Skip(size * (page - 1)).Take(size).ToList();
                break;

            case OrderBy.PostDate:
                posts = temp.ThenByDescending(p => p.PostDate).Skip(size * (page - 1)).Take(size).ToList();
                break;

            case OrderBy.ViewCount:
                posts = temp.ThenByDescending(p => p.ViewCount).Skip(size * (page - 1)).Take(size).ToList();
                break;

            case OrderBy.VoteCount:
                posts = temp.ThenByDescending(p => p.VoteUpCount).Skip(size * (page - 1)).Take(size).ToList();
                break;

            default:
                posts = temp.ThenByDescending(p => p.ModifyDate).Skip(size * (page - 1)).Take(size).ToList();
                break;
            }
            var viewModel = await GetIndexPageViewModelAsync(0, 0, orderBy, user).ConfigureAwait(true);

            ViewBag.Total   = posts.Count;
            ViewBag.Tag     = id;
            viewModel.Posts = posts;
            return(View(viewModel));
        }
예제 #9
0
 public void PublishPost(Post p)
 {
     p.Status     = Status.Pended;
     p.PostDate   = DateTime.Now;
     p.ModifyDate = DateTime.Now;
     PostBll.AddOrUpdateSaved(e => e.Id, p);
     UpdateLucene();
 }
예제 #10
0
        public ActionResult Analyse(int id)
        {
            var list    = PostBll.GetById(id).PostAccessRecord.OrderBy(r => r.AccessTime).GroupBy(r => r.AccessTime.Date).Select(r => new[] { r.Key.GetTotalMilliseconds(), r.Sum(p => p.ClickCount) }).ToList();
            var high    = list.OrderByDescending(n => n[1]).FirstOrDefault();
            var average = list.Average(d => d[1]);

            return(ResultData(new { list, aver = average, high = high[1], highDate = DateTime.Parse("1970-01-01").AddMilliseconds(high[0]) }));
        }
예제 #11
0
        public ActionResult CompareVersion(int id, int v1, int v2)
        {
            var main  = PostBll.GetById(id).Mapper <PostHistoryVersion>();
            var left  = v1 <= 0 ? main : PostHistoryVersionBll.GetById(v1);
            var right = v2 <= 0 ? main : PostHistoryVersionBll.GetById(v2);

            return(View(new[] { main, left, right }));
        }
예제 #12
0
        public ActionResult Get(int id)
        {
            Post          post  = PostBll.GetById(id);
            PostOutputDto model = post.Mapper <PostOutputDto>();

            model.Seminars = string.Join(",", post.Seminar.Select(s => s.Title));
            return(ResultData(model));
        }
예제 #13
0
        public ActionResult Publish(PostInputDto post)
        {
            UserInfoOutputDto user = Session.GetByRedis <UserInfoOutputDto>(SessionKey.UserInfo);

            if (!CategoryBll.Any(c => c.Id == post.CategoryId && c.Status == Status.Available))
            {
                return(ResultData(null, message: "请选择一个分类"));
            }
            if (string.IsNullOrEmpty(post.Label?.Trim()))
            {
                post.Label = null;
            }
            else if (post.Label.Trim().Length > 50)
            {
                post.Label = post.Label.Replace(",", ",");
                post.Label = post.Label.Trim().Substring(0, 50);
            }
            else
            {
                post.Label = post.Label.Replace(",", ",");
            }
            post.Status     = Status.Pending;
            post.PostDate   = DateTime.Now;
            post.ModifyDate = DateTime.Now;
            if (user != null && user.IsAdmin)
            {
                post.Status = Status.Pended;
            }
            else
            {
                post.Content = ReplaceImgSrc(Regex.Replace(post.Content.HtmlSantinizerStandard(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/");
            }
            ViewBag.CategoryId = new SelectList(CategoryBll.LoadEntitiesNoTracking(c => c.Status == Status.Available), "Id", "Name", post.CategoryId);
            Post p = post.Mapper <Post>();

            p.PostAccessRecord.Add(new PostAccessRecord()
            {
                AccessTime = DateTime.Today,
                ClickCount = 0
            });
            p = PostBll.AddEntitySaved(p);
            if (p != null)
            {
                if (p.Status == Status.Pending)
                {
                    var    email = GetSettings("ReceiveEmail");
                    string link  = Url.Action("Details", "Post", new
                    {
                        id = p.Id
                    }, Request.Url?.Scheme ?? "http");
                    string content = System.IO.File.ReadAllText(Request.MapPath("/template/publish.html")).Replace("{{link}}", link).Replace("{{time}}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Replace("{{title}}", p.Title);
                    BackgroundJob.Enqueue(() => SendMail(GetSettings("Title") + "有访客投稿:", content, email));
                    return(ResultData(p.Mapper <PostOutputDto>(), message: "文章发表成功,待站长审核通过以后将显示到列表中!"));
                }
                return(ResultData(p.Mapper <PostOutputDto>(), message: "文章发表成功!"));
            }
            return(ResultData(null, false, "文章发表失败!"));
        }
예제 #14
0
        public async Task <ActionResult> Post(int page = 1, int size = 15, OrderBy orderBy = OrderBy.ModifyDate)
        {
            UserInfoOutputDto user = Session.GetByRedis <UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();

            ViewBag.Total = (await PostBll.LoadEntitiesFromL2CacheNoTrackingAsync <PostOutputDto>(p => p.Status == Status.Pended || user.IsAdmin && !p.IsFixedTop).ConfigureAwait(true)).Count();
            var viewModel = await GetIndexPageViewModelAsync(page, size, orderBy, user).ConfigureAwait(true);

            return(View(viewModel));
        }
예제 #15
0
        public ActionResult Post(int page = 1, int size = 15, OrderBy orderBy = OrderBy.ModifyDate)
        {
            UserInfoOutputDto user = Session.GetByRedis <UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();

            ViewBag.Total = PostBll.LoadEntitiesFromL2CacheNoTracking <PostOutputDto>(p => p.Status == Status.Pended || user.IsAdmin && !p.IsFixedTop).Count(p => !p.IsFixedTop);
            var viewModel = GetIndexPageViewModel(page, size, orderBy, user);

            return(View(viewModel));
        }
예제 #16
0
        public ActionResult RemoveTop(int id)
        {
            Post post = PostBll.GetById(id);

            post.IsBanner = false;
            bool b = PostBll.UpdateEntitySaved(post);

            return(ResultData(null, b, b ? "取消头图页成功" : "取消头图页失败!"));
        }
예제 #17
0
        public ActionResult RemoveSeminar(int id, int sid)
        {
            var     post    = PostBll.GetById(id);
            Seminar seminar = SeminarBll.GetById(sid);

            post.Seminar.Remove(seminar);
            bool b = PostBll.UpdateEntitySaved(post);

            return(ResultData(null, b, b ? $"已将文章【{post.Title}】从【{seminar.Title}】专题移除" : "添加失败"));
        }
예제 #18
0
        public ActionResult Restore(int id)
        {
            var post = PostBll.GetById(id);

            post.Status = Status.Pended;
            bool b = PostBll.UpdateEntitySaved(post);

            HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.UpdateLucene));
            return(ResultData(null, b, b ? "恢复成功!" : "恢复失败!"));
        }
예제 #19
0
        public TestBll(bool autoDetectChangesEnabled, bool lazyLoadingEnabled, bool isCreateDb)
        {
            Db = new LocationDb(isCreateDb);
            Db.Configuration.AutoDetectChangesEnabled = autoDetectChangesEnabled;
            Db.Configuration.LazyLoadingEnabled       = lazyLoadingEnabled; //关闭延迟加载

            Maps                = new MapBll(Db);
            Areas               = new AreaBll(Db);
            Position            = new PositionBll(DbHistory);
            TagPositions        = new TagPositionBll(Db);
            Departments         = new DepartmentBll(Db);
            Users               = new UserBll(Db);
            Tags                = new TagBll(Db);
            Archors             = new ArchorBll(Db);
            KKSCodes            = new KKSCodeBll(Db);
            t_KKSCodes          = new t_KKSCodeBll(Dbtopviewxp);
            t_SetModels         = new t_SetModelBll(Db);
            t_TypeProperties    = new t_Template_TypePropertyBll(Db);
            TransformMs         = new TransformMBll(Db);
            DevInfos            = new DevInfoBll(Db);
            DevPos              = new DevPosBll(Db);
            U3DPositions        = new U3DPositionBll(DbHistory);
            PhysicalTopologys   = new PhysicalTopologyBll(Db);
            NodeKKSs            = new NodeKKSBll(Db);
            Personnels          = new PersonnelBll(Db);
            Posts               = new PostBll(Db);
            JurisDictions       = new JurisDictionBll(Db);
            JurisDictionRecords = new JurisDictionRecordBll(Db);
            Meterials           = new MeterialBll(Db);
            //U3DPositions.ToList();
            ConfigArgs                            = new ConfigArgBll(Db);
            Bounds                                = new BoundBll(Db);
            Points                                = new PointBll(Db);
            OperationTickets                      = new OperationTicketBll(Db);
            OperationItems                        = new OperationItemBll(Db);
            WorkTickets                           = new WorkTicketBll(Db);
            SafetyMeasuress                       = new SafetyMeasuresBll(Db);
            MobileInspections                     = new MobileInspectionBll(Db);
            MobileInspectionItems                 = new MobileInspectionItemBll(Db);
            MobileInspectionContents              = new MobileInspectionContentBll(Db);
            MobileInspectionDevs                  = new MobileInspectionDevBll(Db);
            PersonnelMobileInspections            = new PersonnelMobileInspectionBll(Db);
            PersonnelMobileInspectionItems        = new PersonnelMobileInspectionItemBll(Db);
            PersonnelMobileInspectionHistorys     = new PersonnelMobileInspectionHistoryBll(DbHistory);
            PersonnelMobileInspectionItemHistorys = new PersonnelMobileInspectionItemHistoryBll(DbHistory);
            OperationTicketHistorys               = new OperationTicketHistoryBll(DbHistory);
            OperationItemHistorys                 = new OperationItemHistoryBll(DbHistory);
            WorkTicketHistorys                    = new WorkTicketHistoryBll(DbHistory);
            SafetyMeasuresHistorys                = new SafetyMeasuresHistoryBll(DbHistory);
            Targets                               = new TargetBll(Db);
            Roles = new RoleBll(Db);
            Menus = new MenuBll(Db);

            Z.EntityFramework.Extensions.LicenseManager.AddLicense("34;100-LLHSWWHA", "384799A60700037CBFC0EB5E03A62474");
        }
예제 #20
0
        public ActionResult AddTop(PostOutputDto p)
        {
            Post post = PostBll.GetById(p.Id);

            post.IsBanner    = true;
            post.Description = p.Description;
            post.ImageUrl    = p.ImageUrl;
            bool b = PostBll.UpdateEntitySaved(post);

            return(ResultData(null, b, b ? "添加头图页成功" : "添加头图页失败!"));
        }
예제 #21
0
        /// <summary>
        /// 获取文章分页
        /// </summary>
        /// <returns></returns>
        public ActionResult GetPageData(int page = 1, int size = 10, OrderBy orderby = OrderBy.ModifyDate, string kw = "")
        {
            if (page < 1)
            {
                page = 1;
            }
            if (size < 1)
            {
                page = 10;
            }
            var list = new List <PostDataModel>();
            IOrderedQueryable <Post> temp;
            var query = string.IsNullOrEmpty(kw) ? PostBll.GetAllNoTracking() : PostBll.LoadEntitiesNoTracking(p => p.Title.Contains(kw) || p.Author.Contains(kw) || p.Email.Contains(kw) || p.Label.Contains(kw) || p.Content.Contains(kw));
            var total = query.Count();
            var order = query.OrderByDescending(p => p.Status).ThenByDescending(p => p.IsFixedTop);

            switch (orderby)
            {
            case OrderBy.CommentCount:
                temp = order.ThenByDescending(p => p.Comment.Count);
                break;

            case OrderBy.PostDate:
                temp = order.ThenByDescending(p => p.PostDate);
                break;

            case OrderBy.ViewCount:
                temp = order.ThenByDescending(p => p.PostAccessRecord.Any() ? p.PostAccessRecord.Sum(r => r.ClickCount) : 1);
                break;

            case OrderBy.VoteCount:
                temp = order.ThenByDescending(p => p.VoteUpCount);
                break;

            default:
                temp = order.ThenByDescending(p => p.ModifyDate);
                break;
            }
            var plist = temp.Skip((page - 1) * size).Take(size).Select(p => new { p.Id, p.Author, CategoryName = p.Category.Name, p.Email, p.IsFixedTop, p.Label, md = p.ModifyDate, pd = p.PostDate, p.Title, ViewCount = p.PostAccessRecord.Any() ? p.PostAccessRecord.Sum(r => r.ClickCount) : 1, p.VoteDownCount, p.VoteUpCount, stat = p.Status, ModifyCount = p.PostHistoryVersion.Count }).ToList();

            plist.ForEach(item =>
            {
                PostDataModel model = item.MapTo <PostDataModel>();
                model.PostDate      = item.pd.ToString("yyyy-MM-dd HH:mm");
                model.ModifyDate    = item.md.ToString("yyyy-MM-dd HH:mm");
                model.Status        = item.stat.GetDisplay();
                model.ModifyCount   = item.ModifyCount;
                list.Add(model);
            });
            var pageCount = Math.Ceiling(total * 1.0 / size).ToInt32();

            return(PageResult(list, pageCount, total));
        }
예제 #22
0
        /// <summary>
        /// 获取头图文章
        /// </summary>
        /// <returns></returns>
        public ActionResult GetTops()
        {
            var list = PostBll.LoadEntitiesNoTracking <DateTime, PostOutputDto>(p => p.Status == Status.Pended && p.IsBanner, p => p.ModifyDate, false).Select(p => new
            {
                p.Id,
                p.Description,
                p.Title,
                p.ImageUrl
            }).ToList();

            return(ResultData(list));
        }
예제 #23
0
        public ActionResult CompareVersion(int id, int v1, int v2)
        {
            var main  = PostBll.GetById(id).Mapper <PostHistoryVersion>();
            var left  = v1 <= 0 ? main : PostHistoryVersionBll.GetById(v1);
            var right = v2 <= 0 ? main : PostHistoryVersionBll.GetById(v2);

            HtmlDiff.HtmlDiff diffHelper = new HtmlDiff.HtmlDiff(right.Content, left.Content);
            string            diffOutput = diffHelper.Build();

            right.Content = Regex.Replace(Regex.Replace(diffOutput, "<ins.+?</ins>", string.Empty), @"<\w+></\w+>", string.Empty);
            left.Content  = Regex.Replace(Regex.Replace(diffOutput, "<del.+?</del>", string.Empty), @"<\w+></\w+>", string.Empty);
            return(View(new[] { main, left, right }));
        }
예제 #24
0
        public ActionResult Fixtop(int id)
        {
            Post post = PostBll.GetById(id);

            post.IsFixedTop = !post.IsFixedTop;
            bool b = PostBll.UpdateEntitySaved(post);

            if (b)
            {
                return(ResultData(null, true, post.IsFixedTop ? "置顶成功!" : "取消置顶成功!"));
            }
            return(ResultData(null, false, "操作失败!"));
        }
예제 #25
0
        /// <summary>
        /// 获取非头图页文章
        /// </summary>
        /// <returns></returns>
        public ActionResult GetNotTops()
        {
            var list = PostBll.LoadEntitiesNoTracking(p => p.Status == Status.Pended && !p.IsBanner).GroupBy(p => p.Category.Name).Select(g => new
            {
                text     = g.Key,
                children = g.OrderBy(p => p.Title).Select(p => new
                {
                    id   = p.Id,
                    text = p.Title
                })
            }).ToList();

            return(ResultData(list));
        }
예제 #26
0
        public ActionResult GetTag()
        {
            List <string> list   = PostBll.GetAll().Select(p => p.Label).ToList();
            List <string> result = new List <string>();

            list.ForEach(s =>
            {
                if (!string.IsNullOrEmpty(s))
                {
                    result.AddRange(s.Split(',', ','));
                }
            });
            return(ResultData(result.Distinct().OrderBy(s => s)));
        }
예제 #27
0
        /// <summary>
        /// 首页
        /// </summary>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        public async Task <ActionResult> Index(OrderBy orderBy = OrderBy.ModifyDate)
        {
            ViewBag.Total = 0;
            UserInfoOutputDto user = Session.GetByRedis <UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();
            var tops      = (await PostBll.LoadEntitiesFromL2CacheNoTrackingAsync <DateTime, PostOutputDto>(t => t.Status == Status.Pended && t.IsBanner, p => p.ModifyDate, false).ConfigureAwait(true)).Select(p => new { p.Title, p.Description, p.Id, p.ImageUrl }).ToList();
            var viewModel = await GetIndexPageViewModelAsync(1, 15, orderBy, user).ConfigureAwait(true);

            var banner = new List <PostOutputDto>();

            tops.ForEach(t =>
            {
                banner.Add(t.MapTo <PostOutputDto>());
            });
            viewModel.Banner = banner;
            return(View(viewModel));
        }
예제 #28
0
        public ActionResult VoteUp(int id)
        {
            Post post = PostBll.GetById(id);

            if (Session["post-vote" + id] != null)
            {
                return(ResultData(null, false, "您刚才已经投过票了,感谢您的参与!"));
            }
            if (post != null)
            {
                Session["post-vote" + id] = id;
                ++post.VoteUpCount;
                bool b = PostBll.UpdateEntitySaved(post);
                return(ResultData(null, b, b ? "投票成功!" : "投票失败!"));
            }
            return(ResultData(null, false, "非法操作"));
        }
예제 #29
0
        public async Task <ActionResult> Category(int id, int page = 1, int size = 15, OrderBy orderBy = OrderBy.ModifyDate)
        {
            UserInfoOutputDto user = Session.GetByRedis <UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();
            var cat = await CategoryBll.GetByIdAsync(id).ConfigureAwait(true);

            if (cat is null)
            {
                return(RedirectToAction("Index", "Error"));
            }
            var posts = PostBll.LoadEntitiesNoTracking(p => p.CategoryId == cat.Id && (p.Status == Status.Pended || user.IsAdmin)).OrderByDescending(p => p.IsFixedTop);

            ViewBag.Total = posts.Count();
            switch (orderBy)
            {
            case OrderBy.CommentCount:
                posts = posts.ThenByDescending(p => p.Comment.Count);
                break;

            case OrderBy.PostDate:
                posts = posts.ThenByDescending(p => p.PostDate);
                break;

            case OrderBy.ViewCount:
                posts = posts.ThenByDescending(p => p.PostAccessRecord.Sum(r => r.ClickCount));
                break;

            case OrderBy.VoteCount:
                posts = posts.ThenByDescending(p => p.VoteUpCount);
                break;

            case OrderBy.AverageViewCount:
                posts = posts.ThenByDescending(p => p.PostAccessRecord.Average(r => r.ClickCount));
                break;

            default:
                posts = posts.ThenByDescending(p => p.ModifyDate);
                break;
            }
            var viewModel = GetIndexPageViewModel(0, 0, orderBy, user);

            ViewBag.CategoryName = cat.Name;
            ViewBag.Desc         = cat.Description;
            viewModel.Posts      = posts.Skip(size * (page - 1)).Take(size).ToList().Mapper <IList <PostOutputDto> >();
            return(View(viewModel));
        }
예제 #30
0
        public ActionResult Truncate(int id)
        {
            var post = PostBll.GetById(id);

            if (post is null)
            {
                return(ResultData(null, false, "文章已经被删除!"));
            }

            if (post.IsWordDocument)
            {
                try
                {
                    System.IO.File.Delete(Path.Combine(Server.MapPath("/upload"), post.ResourceName));
                    Directory.Delete(Path.Combine(Server.MapPath("/upload"), Path.GetFileNameWithoutExtension(post.ResourceName)), true);
                }
                catch (IOException)
                {
                }
            }

            var mc = post.Content.MatchImgTags();

            foreach (Match m in mc)
            {
                string path = m.Groups[3].Value;
                if (path.StartsWith("/"))
                {
                    path = Path.Combine(Server.MapPath("/"), path);
                    try
                    {
                        System.IO.File.Delete(path);
                    }
                    catch (IOException)
                    {
                    }
                }
            }
            bool b = PostBll.DeleteByIdSaved(id);

            HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.UpdateLucene));
            return(ResultData(null, b, b ? "删除成功!" : "删除失败!"));
        }