public override async Task <ActionResult <PagedList <CategoryDto> > > Handle(ListCategoriesCommand command) { var pagedCategories = await _listCategoriesQuery.Query(command); var pagedCategoriesDto = _mapper.Map(pagedCategories, new PagedList <CategoryDto>(), opt => opt.Items["WorkingLanguageId"] = command.LanguageId); return(Ok(pagedCategoriesDto.Items.ToPagedList(command))); }
public async Task ShouldListCategories() { // Arrange var listCategoriesCommand = new ListCategoriesCommand(2, WorkContext.WorkingLanguageId, true, pageIndex: 1, pageSize: 1); // Act var result = await _listCategoriesQueryHandler.Handle(listCategoriesCommand); // Assert Assert.IsNotNull(result?.Object); }
public async Task ShouldGetCategoryNavigations() { // Arrange var listCategoriesCommand = new ListCategoriesCommand(1, WorkContext.WorkingLanguageId, true); // Act var result = await _listCategoryNavigationsQueryHandler.Handle(listCategoriesCommand); // Assert Assert.IsNotNull(result?.Object); }
public async Task ShouldGetSubCategory() { // Arrange var listCategoriesCommand = new ListCategoriesCommand(1, WorkContext.WorkingLanguageId, true); var categoryId = (await _listCategoriesQuery.Query(listCategoriesCommand)).Items .FirstOrDefault(o => o.Route.AngularComponent.Code == AngularComponents.SubCategoryComponent).Id; var getCategoryCommand = new GetCategoryCommand(categoryId, WorkContext.WorkingLanguageId); // Act var result = await _getCategoryQueryHandler.Handle(getCategoryCommand); // Assert Assert.IsNotNull(result?.Object); }
public async Task <IActionResult> GetCategoryNavigations() { var listCategoriesCommand = new ListCategoriesCommand(2, WorkContext.WorkingLanguageId, true); var pagedNavigationsDtoResult = await QueryProcessor.GetQueryHandler <ListCategoriesCommand, PagedList <CategoryNavigationDto> >(listCategoriesCommand); if (pagedNavigationsDtoResult.Failure) { return(BadRequest(pagedNavigationsDtoResult.ErrorMessages)); } var pagedNavigationsDto = pagedNavigationsDtoResult.Object; return(Ok(pagedNavigationsDto.Items)); }
public async Task <IActionResult> ListCategories(ListCategoriesCommand listCategoriesCommand) { // TODO: fix workingLanguageId listCategoriesCommand.LanguageId = 1; listCategoriesCommand.InputFormId = 2; listCategoriesCommand.IsDefaultCategoriesIncluded = true; listCategoriesCommand.IsDisabledIncluded = true; var pagedCategoriesDtoResult = await QueryProcessor.GetQueryHandler <ListCategoriesCommand, PagedList <CategoryDto> >(listCategoriesCommand); if (pagedCategoriesDtoResult.Failure) { return(BadRequest(pagedCategoriesDtoResult.ErrorMessages)); } var pagedCategoriesDto = pagedCategoriesDtoResult.Object; return(Ok(pagedCategoriesDto)); }
public async Task ShouldGetCategory() { // Arrange var listCategoriesCommand = new ListCategoriesCommand(1, WorkContext.WorkingLanguageId, true); var categoryId = (await _listCategoriesQuery.Query(listCategoriesCommand)).Items .FirstOrDefault(o => o.Route.AngularComponent.Code == AngularComponents.ProductCategoryComponent).Id; var getCategoryCommand = new GetCategoryCommand(7, WorkContext.WorkingLanguageId); var listProductsByCategoryCommand = new ListProductsByCategoryCommand(7, WorkContext.WorkingLanguageId, pageIndex: 1, pageSize: 24); // Act var categoryDto = (await _getCategoryQueryHandler.Handle(getCategoryCommand)).Object; var productsDto = (await _listProductsByCategoryQueryHandler.Handle(listProductsByCategoryCommand)); // Assert Assert.IsNotNull(categoryDto); Assert.IsNotNull(productsDto); }
public override async Task <PagedList <Category> > Query(ListCategoriesCommand command) { // ServerSide paging of category list is doing in query handler only because it is too difficult to properly form navigations var query = DbContext.Categories .Include(o => o.Characteristics).ThenInclude(o => o.Characteristic) .Include(o => o.Characteristics) .Include(o => o.CategoryType) .Include(o => o.Route).ThenInclude(o => o.AngularComponent) .Include(o => o.Images).ThenInclude(o => o.ImageSizeType) .Include(o => o.Images).ThenInclude(o => o.Characteristics).ThenInclude(o => o.Characteristic) .Include(o => o.Images).ThenInclude(o => o.Characteristics) .Where(o => o.Route.InputFormId == command.InputFormId || (command.IsDefaultCategoriesIncluded && o.Route.InputForm.Code == InputFormCodes.CommonInputForm)); if (!string.IsNullOrWhiteSpace(command.Search)) { query = query.Where(o => o.Characteristics.Any(i => i.Characteristic.Code == CharacteristicCodes.Name && i.Value.Contains(command.Search))); } var pagedList = await query.ToPagedListAsync(); var categoryCharacteristicIds = pagedList.Items.SelectMany(o => o.Characteristics).Select(o => o.Id).Union(pagedList.Items.Where(o => o.Children != null).SelectMany(o => o.Children).SelectMany(o => o.Characteristics).Select(o => o.Id)); await DbContext.CategoryCharacteristicTranslations.Where(o => categoryCharacteristicIds.Contains(o.CharacteristicId) && o.LanguageId == command.LanguageId).LoadAsync(); var categoryImageCharacteristicIds = pagedList.Items.SelectMany(o => o.Images).SelectMany(o => o.Characteristics).Select(o => o.Id).Union(pagedList.Items.Where(o => o.Children != null).SelectMany(o => o.Children).SelectMany(o => o.Images).SelectMany(o => o.Characteristics).Select(o => o.Id)); await DbContext.ImageCharacteristicTranslations.Where(o => categoryImageCharacteristicIds.Contains(o.CharacteristicId) && o.LanguageId == command.LanguageId).LoadAsync(); pagedList.Items = pagedList.Items .Where(o => command.IsDisabledIncluded || (!command.IsDisabledIncluded && o.Characteristics.FirstOrDefault(i => i.Characteristic?.Code == CharacteristicCodes.IsDisabled)?.Value != "true")); pagedList.Items = pagedList.Items .OrderBy(o => o.Characteristics.FirstOrDefault(i => i.Characteristic.Code == CharacteristicCodes.Order)?.Value == null) .ThenBy(o => o.Characteristics.FirstOrDefault(i => i.Characteristic.Code == CharacteristicCodes.Order)?.Value) .ThenBy(o => o.Characteristics.FirstOrDefault(i => i.Characteristic.Code == CharacteristicCodes.NavigationName)?.Value ?? o.Characteristics.FirstOrDefault(i => i.Characteristic.Code == CharacteristicCodes.Name)?.Value); return(pagedList); }