Exemplo n.º 1
0
        //踩/赞文章消息队列
        private static void CaiZanClickMQ()
        {
            ChapterBLL chapterBll = new ChapterBLL();

            while (IsRunning)
            {
                string data = RedisHelper.Dequeue("ZanCaiClick");  // 20|zan  21|cai
                if (data == null)
                {
                    Thread.Sleep(200);
                    continue;
                }
                string[] strs      = data.Split('|');
                int      chapterId = Convert.ToInt32(strs[0]);
                string   action    = strs[1];
                if (action == "zan")
                {
                    chapterBll.ZanChapter(chapterId, 1);
                    Console.WriteLine(action + ":" + chapterId);
                }
                else if (action == "cai")
                {
                    chapterBll.CaiChapter(chapterId, 1);
                    Console.WriteLine(action + ":" + chapterId);
                }
            }
        }
Exemplo n.º 2
0
        //显示文章列表
        public ActionResult ChapterList()
        {
            ChapterBLL chapterBll = new ChapterBLL();
            string     strPageNum = Request["pagenum"];
            int        pageNum    = string.IsNullOrEmpty(strPageNum) ? 1 : Convert.ToInt32(strPageNum);
            int        pageSize   = 10;
            int        totalSize  = 0;

            //缓存总条数
            string cacheKey = "ChapterList.TotalSize." + DateTime.Today.Day;

            totalSize = RedisHelper.Get <int>(cacheKey);
            if (totalSize <= 0)
            {
                totalSize = chapterBll.GetChapterCountToday(DateTime.Today);
                RedisHelper.Set <int>(cacheKey, totalSize, 1);
            }

            //分页获取当天数据
            List <Chapter> chapterList = chapterBll.GetPageChaptersToday(DateTime.Today, pageNum, pageSize);

            ViewBag.TotalSize   = totalSize;
            ViewBag.PageSize    = pageSize;
            ViewBag.CurrentPage = pageNum;
            ViewBag.ChapterList = chapterList;
            return(View());
        }
Exemplo n.º 3
0
        //新增/编辑文章页面
        public ActionResult AddOrEditChapter(string id)
        {
            string pageNum = Request["pagenum"];

            ViewBag.PageNum = pageNum == null ? 1 : Convert.ToInt32(pageNum);
            if (!WebHelper.CheckLogin())  //判断登录
            {
                string url = string.Format("/UserOperation/Login?returnUrl=/{0}", "AddOrEditChapter?id=" + id);
                //return Redirect(url);
            }

            ChapterBLL chapterBll = new ChapterBLL();
            Chapter    chapter    = new Chapter();

            if (string.IsNullOrEmpty(id))  //新增
            {
                return(View(new Chapter()));
            }
            else   //编辑
            {
                int chapterId = Convert.ToInt32(id);
                int userId    = (int)WebHelper.GetUserIdInSession();
                chapter = chapterBll.GetByChapterId(chapterId);
                if (chapter != null && chapter.Id > 0 && chapter.UserId == userId)
                {
                    return(View(chapter));
                }
                return(View(new Chapter()));
            }
        }
Exemplo n.º 4
0
        //个人主页
        public ActionResult Index(string userName)
        {
            if (!WebHelper.CheckLogin())  //判断登录
            {
                string url = string.Format("/UserOperation/Login?returnUrl=/{0}", userName);
                //return Redirect(url);
            }

            ChapterBLL chapterBll = new ChapterBLL();
            //查询用户发表的文章
            int userId = (int)WebHelper.GetUserIdInSession();
            int page   = Convert.ToInt32(Request["pagenum"]);

            page = page <= 0 ? 1 : page;
            int            pageSize    = 3;
            int            totalSize   = chapterBll.GetChaptersByUId(userId).Count;
            List <Chapter> chapterList = chapterBll.GetPageChaptersByUId(userId, page, pageSize);

            ViewBag.UserName    = userName;
            ViewBag.ChapterList = chapterList;
            ViewBag.TotalSize   = totalSize;
            ViewBag.PageSize    = pageSize;
            ViewBag.CurrentPage = page;
            return(View());
        }
Exemplo n.º 5
0
        public static bool Chapter_Batch_Upd(IList <Chapter> models)
        {
            var bll = new ChapterBLL();

            foreach (var model in models)
            {
                bll.Chapter_Upd(model);
            }
            return(true);
        }
Exemplo n.º 6
0
        //获取文章的踩/赞数
        public JsonResult GetCaiZanCount()
        {
            int        caiCount   = 0;
            int        zanCount   = 0;
            int        chapterId  = Convert.ToInt32(Request["chapterId"]);
            ChapterBLL chapterBll = new ChapterBLL();
            Chapter    chapter    = chapterBll.GetByChapterId(chapterId);

            caiCount = chapter.CaiCount;
            zanCount = chapter.ZanCount;
            return(Json(new { CaiCount = caiCount, ZanCount = zanCount }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 7
0
        public static IList <Chapter> Chapter_Move(Chapter model, string direction)
        {
            if (!IES.Service.UserService.OC_IsRole(model.OCID))
            {
                return(null);
            }

            var  BLL   = new ChapterBLL();
            bool moved = BLL.Chapter_Move(model.ChapterID, direction);

            return(moved ? BLL.Chapter_List(model) : null);
        }
Exemplo n.º 8
0
        public ActionResult SubmitAddOrEditChapter()
        {
            int    chapterId = 0;
            string pageNum   = Request["pageNum"];
            string id        = Request["chapterId"];
            string title     = Request["title"];
            string content   = Request["editorValue"];

            if (!WebHelper.CheckLogin())  //判断登录
            {
                string url = string.Format("/UserOperation/Login?returnUrl=/{0}", "AddOrEditChapter?id=" + id);
                //return Redirect(url);
            }
            int        userId     = (int)WebHelper.GetUserIdInSession();
            DateTime   now        = DateTime.Now;
            ChapterBLL chapterBll = new ChapterBLL();

            if (!string.IsNullOrEmpty(id) && id != "0")  //编辑
            {
                chapterId = Convert.ToInt32(id);
                chapterBll.EditChapter(chapterId, userId, title, content);
            }
            else   //新增
            {
                chapterId = chapterBll.AddChapter(title, content, userId);
            }

            //对新增或者编辑的文章生成静态文件(.shtml)
            //.../StaticPage/[UserId]/[ChapterId].shtml
            string path = Server.MapPath("~/StaticPage");

            chapterBll.GenerateStaticChapterPage(path, userId, chapterId, title, content);

            //添加到队列,写入到文章索引库中
            RedisHelper.Enqueue("ChaptersIndex", userId + "$" + chapterId + "$" + title + "$" + content + "$" + now + "$" + "url");

            string userName = new UserBLL().GetById(userId).UserName;

            return(Redirect("/" + userName + "?pagenum=" + pageNum));
        }