예제 #1
0
        public async Task <IActionResult> Main(long id)
        {
            if (await _rightService.CheckRights(id, await _userManager.GetUserAsync(HttpContext.User)))
            {
                var chapters    = _chapterService.FindByCompositionId(id);
                var composition = _compositionService.FindById(id);
                List <ChapterNumberAndId> chapterNumberAndIds = new List <ChapterNumberAndId>();
                foreach (var chapter in chapters)
                {
                    chapterNumberAndIds.Add(new ChapterNumberAndId()
                    {
                        ChapterId = chapter.Id,
                        Number    = chapter.Number
                    });
                }

                var model = new ChapterMainViewModel()
                {
                    CompositionId        = id,
                    ChapterNumbersAndIds = chapterNumberAndIds,
                    CompositionName      = composition.Name
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("AccessDenied", "Notifications"));
            }
        }
예제 #2
0
        public async Task <IActionResult> Index(long compositionId, long?chapterId)
        {
            IActionResult result = BadRequest();

            var composition = _dbCompositionService.FindById(compositionId);

            if (composition != null)
            {
                long    chapterIdCurrent = chapterId ?? 0;
                Chapter chapter          = null;
                if (chapterIdCurrent > 0)
                {
                    chapter = await _dbChapterService.FindByIdAsync(chapterIdCurrent);
                }
                else
                {
                    var firstChapter = _dbChapterService.FindByCompositionIdAndNumber(compositionId, 1);
                    if (firstChapter != null)
                    {
                        chapter = firstChapter;
                    }
                }
                if (chapter != null)
                {
                    List <ChapterNumberAndId> chapterNumberAndIds = new List <ChapterNumberAndId>();
                    var chapters = _dbChapterService.FindByCompositionId(compositionId);
                    foreach (var ch in chapters)
                    {
                        chapterNumberAndIds.Add(new ChapterNumberAndId()
                        {
                            ChapterId = ch.Id,
                            Number    = ch.Number
                        });
                    }

                    byte rating = 1;
                    if (_dbChapterService.LastChapter(chapter))
                    {
                        var user = await _userManager.GetUserAsync(HttpContext.User);

                        if (user != null)
                        {
                            var rate = _dbRatingService.FindByUserIdAndCompositionId(user.Id, composition.Id);
                            if (rate != null)
                            {
                                rating = rate.Mark;
                            }
                        }
                    }
                    var likes        = _dbLikeService.GetLikesByChapterId(chapter.Id);
                    var likesUserIds = new List <string>();
                    foreach (var like in likes)
                    {
                        likesUserIds.Add(like.UserId);
                    }
                    result = View(new ReaderChapterViewModel()
                    {
                        ChapterId            = chapterIdCurrent,
                        ChapterNumbersAndIds = chapterNumberAndIds,
                        CompositionId        = compositionId,
                        CompositionName      = composition.Name,
                        Text          = chapter.Text,
                        ChapterNumber = chapter.Number,
                        LikeUserIds   = likesUserIds,
                        Rating        = rating
                    });
                }
                else
                {
                    result = RedirectToAction("EmptyComposition", "Notifications");
                }
            }

            return(result);
        }