예제 #1
0
        public async Task <IActionResult> GetUserPublications(int userId)
        {
            var publications = await _blogDbContext.Publications
                               .Include(p => p.Author)
                               .Where(p => p.Author.Id == userId)
                               .ToListAsync();

            var response = publications.Select(pub => PublicationMapper.ToResponseModel(pub))
                           .ToList();

            return(Ok(response));
        }
예제 #2
0
        public IActionResult GetPublication(int id)
        {
            var publication = _blogDbContext.Publications
                              .Include(p => p.Author)
                              .FirstOrDefault(p => p.Id == id);

            if (publication == null)
            {
                return(NotFound(string.Format("Такой публикации нет")));
            }

            return(Ok(PublicationMapper.ToResponseModel(publication)));
        }