public IActionResult GetMarkedPosts(int pageNumber = 1, int pageSize = 5)
        {
            pageSize = pageSize > maxPageSize ? maxPageSize : pageSize;

            var data = _dataService.GetMarkedPosts(pageNumber, pageSize);

            var result = Mapper.Map <IEnumerable <MarkedPostListModel> >(data);

            foreach (MarkedPostListModel p in result)
            {
                p.Url       = Url.Link(nameof(IPostDataService.GetPost), new{ p.Id });
                p.PostTitle = _dataService2.GetPost(p.Id).Title;
            }

            var prevlink = pageNumber > 1
                ? Url.Link(nameof(GetMarkedPosts), new { pageNumber = pageNumber - 1, pageSize })
                : null;

            var total = _dataService.GetNumberOfMarkedPost();

            var totalPages = (int)System.Math.Ceiling(total / (double)pageSize);

            var nextlink = pageNumber < totalPages
                ? Url.Link(nameof(GetMarkedPosts), new { pageNumber = pageNumber + 1, pageSize })
                : null;

            var curlink = Url.Link(nameof(GetMarkedPosts), new { pageNumber, pageSize });

            var linkedResult = new
            {
                Result = result,
                Links  = new List <object>
                {
                    new { name = "prev", url = prevlink },
                    new { name = "next", url = nextlink },
                    new { name = "cur", url = curlink }
                },
                TotalMarked = total
            };

            return(Ok(linkedResult));
        }
Exemple #2
0
        public IActionResult GetPost(int id)
        {
            var post = _dataService.GetPost(id);

            //var tagDomain = _dataService2.GetTagOfPost(id);
            //var tag = Mapper.Map<TagModel>(tagDomain);

            if (post == null)
            {
                return(NotFound());
            }

            var model = Mapper.Map <PostModel>(post);

            model.OwnerName = _dataService2.GetUser(model.OwnerId).DisplayedName;
            //model.Tag = tag;
            //model.TagUrl = Url.Link(nameof(TagController.GetTag), new { tag.Url });

            return(Ok(model));
        }
 public Post GetPost(long postId)
 {
     return(_postDataService.GetPost(postId));
 }