Exemplo n.º 1
0
        public async Task <IActionResult> Index(long compositionId, long chapterId)
        {
            IActionResult result = BadRequest();

            if (await _rightService.CheckRights(compositionId, await _userManager.GetUserAsync(HttpContext.User)))
            {
                var chapter = await _chapterService.FindByIdAsync(chapterId);

                if (chapter != null)
                {
                    ChapterViewModel viewModel = new ChapterViewModel()
                    {
                        ChapterId     = chapter.Id,
                        CompositionId = chapter.CompositionId,
                        Number        = chapter.Number,
                        Text          = chapter.Text
                    };
                    result = View(viewModel);
                }
            }
            else
            {
                result = RedirectToAction("AccessDenied", "Notifications");
            }

            return(result);
        }
Exemplo n.º 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);
        }