Esempio n. 1
0
        [HttpGet] // displays blog landing page
        public IActionResult Index()
        {
            var request   = new ListRecentBlogPostsRequest();
            var response  = _listRecentBlogPostsInteractor.ListRecentBlogPosts(request);
            var viewmodel = new BlogIndexViewModel();

            if (response.RequestSuccessful)
            {
                viewmodel.RecentPosts = MapListOfBlogPostToListOfDTOModel(response.ListOfRecentPosts);
            }
            return(View(viewmodel));
        }
        public ListRecentBlogPostsResponse ListRecentBlogPosts(ListRecentBlogPostsRequest request)
        {
            var response = new ListRecentBlogPostsResponse();

            try
            {
                response.ListOfRecentPosts = _blogPostRepo.List().OrderByDescending(x => x.TimeCreated).Take(5).ToList();
                response.RequestSuccessful = true;
            }
            catch (Exception)
            {
                response.RequestSuccessful = false;
            }
            return(response);
        }