Exemplo n.º 1
0
        public async Task <object> GetAsync(
            [FromQuery] int skip,
            [FromQuery] int limit = 3)
        {
            bool includeUnpublished = false;
            var  currentUser        = User.Identity as AuthenticatedUser;

            if (currentUser != null && currentUser.HasClaim(ClaimTypes.Role, UserRole.Administrator))
            {
                includeUnpublished = true;
            }

            var result = await _newsItemRepository.GetLatestAsync(skip, limit, includeUnpublished);

            return(new
            {
                status = JStatus.OK,
                result = result.Select(
                    x => new
                {
                    x.Id,
                    x.Title,
                    Author = x.AuthorName,
                    Date = (x.Published ?? DateTime.UtcNow).ToString("dd MMMM yyyy"),
                    IsPublished = x.Published.HasValue,
                    x.Html
                })
            });
        }