Esempio n. 1
0
        public async Task <IActionResult> Get([FromCommaSeparatedQuery(Name = "include")] IEnumerable <string> includes)
        {
            var flags = EnumFlags.Parse <LandingIncludes>(includes);
            var query = new GetLandingQuery
            {
                IncludeHeroStory     = LandingIncludes.HeroStory == (flags & LandingIncludes.HeroStory),
                FeaturedStoriesCount = LandingIncludes.FeaturedStories == (flags & LandingIncludes.FeaturedStories)
                    ? blogSettings.FeaturedStoriesCount
                    : 0
                                       //StoriesFeedCount = LandingIncludes.StoriesFeed == (flags & LandingIncludes.StoriesFeed)
                                       //    ? blogSettings.FeedStoriesCount
                                       //    : 0
            };

            var result = await mediator.Send(query, HttpContext.RequestAborted);

            if (false == result.IsSuccess())
            {
                foreach (var exception in result.Exceptions)
                {
                    logger.LogError(exception, "[LandingController.Get] Exception");
                }

                return(BadRequest(result.Exceptions));
            }

            //return Ok(mapper.Map<LandingModel>(result.Data));

            return(Ok(new LandingModel
            {
                Title = "",
                Description = "",
                Data = Enumerable.Empty <FeedStoryModel>(),
                Hero = new HeroStoryModel(),
                Featured = Enumerable.Empty <FeedStoryModel>(),
                Meta = new ResourcesMetaInfo
                {
                    Resources = new AuthorsResource
                    {
                        Authors = Enumerable.Empty <AuthorModel>()
                    }
                }
            }));
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <IRequestResult <Models.Landing> > Handle(GetLandingQuery request, CancellationToken cancellationToken)
        {
            if (null == request)
            {
                throw new ArgumentNullException(nameof(request));
            }

            try
            {
                //var authenticated = request.User.Identity.IsAuthenticated;
                //var queryable = context.Settings.AsNoTracking();

                /*var landing = new LandingQueryResult
                 * {
                 *  Title = await GetStringValueAsync(queryable.Where(story => story.Name == "Landing.Title")),
                 *  Description = await GetStringValueAsync(queryable.Where(story => story.Name == "Landing.Description")),
                 *  HeroStory = await GetHeroStoryAsync(request.IncludeHeroStory, authenticated)
                 * };*/

                var featuredStories = await GetFeedStoriesAsync(
                    request.FeaturedStoriesCount,
                    //request.User.Identity.IsAuthenticated,
                    CancellationToken.None
                    );

                var featured = new List <FeedStory>();
                var authors  = new Collection <Author>();

                CreateMappedFeedStories(featured, authors, featuredStories);

                //FillFeaturedStories(landing.FeaturedStories, request.FeaturedStoriesCount, authenticated);
                //FillStoriesFeed(landing.FeedStories, request.StoriesFeedCount, authenticated);

                //return Models.Landing.Create(featured);
                return(null);
            }
            catch (Exception exception)
            {
                // RequestResult.Error<Models.LandingQueryResult>(exception);
                //return Models.Landing.Error(exception);
                return(null);
            }
        }