コード例 #1
0
        public async Task <ActionResult> Index(int?page)
        {
            int currentPage           = page ?? 1;
            int quantityOfPostsOnPage = _settingsRepo.GetSettings().PostsOnSite;

            try
            {
                var posts = await _postRepo.GetAllPostsAsync();

                return(View(posts.ToPagedList <Post>(currentPage, quantityOfPostsOnPage)));
            } catch (Exception e)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Get()
        {
            var posts = await _postRepo.GetAllPostsAsync();

            return(Ok(posts.Select(p => ApiModelConverter.ToPostApiModel(p))));
        }
コード例 #3
0
ファイル: PostController.cs プロジェクト: WAD00007717/CW
        public async Task <ActionResult <PostsWithCountDto> > GetAllPostsAsync([FromQuery] int?pageNumber, int?userId)
        {
            var posts = await _repository.GetAllPostsAsync(pageNumber, userId);

            return(Ok(posts));
        }