Пример #1
0
        /// <summary>
        /// 书籍详情
        /// </summary>
        /// <param name="nid"></param>
        /// <returns></returns>
        public async Task <ActionResult> Detail(int novelId = 0)
        {
            string loginUserName = currentUser.UserName;
            Novel  novel         = null;

            if (novelId > 0)
            {
                novel = _bookService.GetNovel(novelId);
            }

            if (novel == null || novel.Id <= 0)
            {
                return(Redirect(DataContext.GetErrorUrl(ErrorMessage.小说不存在, channelId: RouteChannelId)));
            }

            BookDetailView view = novel.ToBookDetailView();
            //活动截止时间
            var packageInfo = await Task.Run(() => _packageService.GetNovelPackage(Constants.PackageType.LimitFree, novelId));

            if (packageInfo != null)
            {
                view.PackageEndTime = packageInfo.EndTime;
            }
            else
            {
                view.PackageEndTime = null;
            }

            //是否收藏
            bool isAddMark = await Task.Run(() => _bookmarkService.Exists(novelId, loginUserName));

            view.IsAddMark = isAddMark;
            //是否全本优惠
            view.IsOrder = await Task.Run(() => IsOrder(_orderService));

            //阅读记录
            ILogService         logService = DataContext.ResolveService <ILogService>();
            NovelReadRecordInfo readRecord = await Task.Run(() => logService.GetRecentChapter(loginUserName, novelId));

            if (readRecord != null)
            {
                view.RecentReadChapterCode = readRecord.ChapterCode;
            }

            //作者的话
            string column = "Message";

            string where = "and novelId = @novelId and authorId = @authorId ";
            string orderby      = " order by id desc";
            var    authorNotice = await Task.Run(() => _bookService.GetAuthorNotice(column, where, orderby, new { novelId = novelId, authorId = novel.UserId }));

            view.AuthorNotice = authorNotice == null ? null : authorNotice.Message;

            //章节信息
            var lastChapter = await Task.Run(() => _chapterService.GetLatestChapter(novelId));

            view.RecentChapterName       = lastChapter == null ? null : lastChapter.ChapterName;
            view.RecentChapterUpdateTime = lastChapter == null ? default(DateTime) : lastChapter.OnlineTime;
            view.RecentChapterCode       = lastChapter == null ? 0 : lastChapter.ChapterCode;
            int rowCount    = 0;
            var chapterList = await Task.Run(() => GetChapterList(out rowCount, novelId, novel.ContentType));

            view.TotalChapterCount = rowCount;
            view.ChapterList       = new SimpleResponse <IEnumerable <ChapterView> >(!chapterList.IsNullOrEmpty(), chapterList);

            //评论信息
            int commentCount = 0;
            var commentList  = await Task.Run(() => GetCommentList(out commentCount, novel.Id));

            view.CommentCount = commentCount;
            view.CommentList  = new SimpleResponse <IEnumerable <CommentView> >(!commentList.IsNullOrEmpty(), commentList);

            //猜你喜欢
            bool IsCartoonType = novel.ContentType == (int)Constants.Novel.ContentType.漫画;

            view.RecClassId = IsCartoonType ? RecSection.CartoonDetail.GuessRec : RecSection.BookDetail.GuessRec;
            if (IsCartoonType)
            {
                //漫画详情-来源
                var cp = await Task.Run(() => _bookService.GetCP("CnName", "and Id = @cpId and status = @status", "order by id ", new { cpId = novel.CPId, status = 1 }));

                view.CPName = cp == null ? null : cp.CnName;
            }

            //记录日志

            NovelLogInfo log = new NovelLogInfo();

            log          = GetLogInfo(log) as NovelLogInfo;
            log.CookieId = GetCookieId();
            log.NovelId  = novelId;
            log.AddTime  = DateTime.Now;
            var service = DataContext.ResolveService <ILogService>();
            await Task.Run(() => service.NovelReadLog(log));

            var model = new SimpleResponse <BookDetailView>(view != null, view);

            if (IsCartoonType)
            {
                return(View("/Views/Cartoon/Detail.cshtml", model));
            }
            else
            {
                return(View(model));
            }
        }