示例#1
0
        public async Task <IActionResult> GetBackgrounds()
        {
            var query  = new GetBackgroundsQuery();
            var result = await _bus.Send(query);

            return(Ok(_mapper.Map <IEnumerable <BackgroundResponse> >(result)));
        }
示例#2
0
        public JsonResult GetBackgrounds()
        {
            var backgroundsQuery = new GetBackgroundsQuery {
            };
            var backgroundsDto   = SendQuery <GetBackgroundsQuery, IEnumerable <BackgroundDTO> >(backgroundsQuery);
            var backgrounds      = new SelectList(backgroundsDto, nameof(BackgroundDTO.Id), nameof(BackgroundDTO.Name));

            return(Json(backgrounds));
        }
示例#3
0
        public async Task <IEnumerable <UnsplashImage> > Handle(GetBackgroundsQuery request,
                                                                CancellationToken cancellationToken)
        {
            var backgrounds = _mediaStore.GetBackgrounds();

            if (backgrounds != null)
            {
                return(backgrounds);
            }

            var newBackgrounds = (await _client.GetImagesAsync(cancellationToken)).ToList();

            _mediaStore.SetBackgrounds(newBackgrounds);

            return(newBackgrounds);
        }
示例#4
0
        IEnumerable <BackgroundDTO> IQueryHandler <GetBackgroundsQuery, IEnumerable <BackgroundDTO> > .Handle(GetBackgroundsQuery query)
        {
            var result = new List <BackgroundDTO>();

            var backgrounds = context.Background.ToList();

            foreach (var background in backgrounds)
            {
                result.Add(new BackgroundDTO
                {
                    Id          = background.Id,
                    Name        = background.Name,
                    Description = background.Description
                });
            }

            return(result);
        }