public async Task <IActionResult> GetBackgrounds() { var query = new GetBackgroundsQuery(); var result = await _bus.Send(query); return(Ok(_mapper.Map <IEnumerable <BackgroundResponse> >(result))); }
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)); }
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); }
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); }