Ejemplo n.º 1
0
        public async Task<IHttpActionResult> Get(int id, int page)
        {
            var projectCommentsCount = await this.commentsService.ProjectCommentsCount(id);
            var lastPage = this.GetLastPage(projectCommentsCount);
            var username = this.User.Identity.IsAuthenticated ? this.CurrentUser.UserName : string.Empty;

            var model = new CommentsPageResponseModel
            {
                Comments = await this.commentsService
                    .ProjectComments(id, page)
                    .Project()
                    .To<CommentResponseModel>(new { username })
                    .ToListAsync(),
                IsLastPage = page == lastPage
            };

            return this.Data(model);
        }
Ejemplo n.º 2
0
        public async Task<IHttpActionResult> CommentsByUser(string username, int page)
        {
            var userCommentsCount = await this.commentsService.UserCommentsCount(username);
            var lastPage = this.GetLastPage(userCommentsCount); // TODO: extract to common logic for last page

            // TODO: Extract to attribute to check valid page if possible
            if (page < 1 || page > lastPage)
            {
                return this.Data(false, Constants.InvalidPageNumber);
            }

            var model = new CommentsPageResponseModel
            {
                Comments = await this.commentsService
                    .UserComments(username, page)
                    .Project()
                    .To<CommentResponseModel>()
                    .ToListAsync(),
                IsLastPage = page == lastPage,
                CurrentPage = page,
                LastPage = lastPage
            };

            return this.Data(model);
        }