public async Task <IEnumerable <DtoCategory> > Handle(GetAllCategoriesQuery request, CancellationToken cancellationToken) { try { if (request is null) { throw new CategoryMSException("The get all categories query can not be null") { StatusCode = 500 } } ; var categories = await _unitOfWork.Categories.GetAllAsync(); List <DtoCategory> result = new(); foreach (var category in categories) { result.Add(new DtoCategory() { CategoryId = category.CategoryId, CategoryName = category.CategoryName }); } return(result); } catch (Exception) { throw; } }
public async Task <IActionResult> Get([FromQuery] GetAllCategoriesQuery query) { if (query == null) { query = new GetAllCategoriesQuery(); } var results = await _queryExecutor.ExecuteAsync(query); var rootResults = results.ToLookup(x => x.RootCategory.Name, i => i); var sortedResult = new List <RootCategoryWithCategories>(); foreach (IGrouping <string, Category> groupItem in rootResults) { var el = new RootCategoryWithCategories() { Name = groupItem.Key, Categories = new List <Category>() }; foreach (var listEl in groupItem) { el.Categories.Add(listEl); } sortedResult.Add(el); } return(_apiResponseHelper.SimpleQueryResponse(this, sortedResult)); }
public async Task <IEnumerable <CategoryViewModel> > Handle(GetAllCategoriesQuery request, CancellationToken cancellationToken) { var categories = await context.Categories.ToListAsync(cancellationToken); var list = mapper.Map <IEnumerable <CategoryViewModel> >(categories); return(list); }
public async Task <List <GetAllCategoriesByUserIdQueryResponse> > Handle(GetAllCategoriesQuery request, CancellationToken cancellationToken) { return(await _context.Categories .Select(x => new GetAllCategoriesByUserIdQueryResponse { Id = x.Id, Text = x.Title }) .ToListAsync(cancellationToken)); }
public async Task GetAllCategoriesHandler_Returns_Categories() { var message = new GetAllCategoriesQuery(); var handlerContext = TestContext.CreateHandlerContext <IEnumerable <CategoryViewModel> >(RequestDbContext); var handler = new GetAllCategoriesQueryHandler(handlerContext); var result = await handler.Handle(message, CancellationToken.None); Assert.NotEmpty(result.Payload); }
public async Task GetAllCategoriesQueryTestAsync() { GetAllCategoriesQuery request = new GetAllCategoriesQuery(); GetAllCategoriesQueryHandler handler = new GetAllCategoriesQueryHandler(_fixture.Context); var expectedResult = await handler.Handle(request, new CancellationToken()); var expecteResultIds = expectedResult.Select(c => c.Id); Assert.Equal(expecteResultIds, new List <int> { 1, 2, 3 }); }
public async Task <IActionResult> Index() { var query = new GetAllCategoriesQuery(); var categories = await _mediator.Send(query); var categoryModels = _mapper.Map <IList <CategoryItemModel> >(categories); var viewModel = new CategoriesViewModel { CategoryItemModels = categoryModels, }; return(View(viewModel)); }
public async Task <IEnumerable <Category> > ExecuteAsync(GetAllCategoriesQuery query, IExecutionContext executionContext) { var customEntityQuery = new GetCustomEntityRenderSummariesByDefinitionCodeQuery(CategoryCustomEntityDefinition.DefinitionCode); var customEntities = await _customEntityRepository.GetCustomEntityRenderSummariesByDefinitionCodeAsync(customEntityQuery);; var categories = new List <Category>(); foreach (var cat in customEntities) { categories.Add(await MapCategory(cat)); } return(categories); }
public async Task <IEnumerable <CategoryViewModel> > Handle(GetAllCategoriesQuery request, CancellationToken cancellationToken) { var categories = await _allMarktQueryContext .Categories .ToListAsync(cancellationToken); return(from category in categories select new CategoryViewModel { Id = category.Id, Name = category.Name, Description = category.Description }); }