private async Task <Models.Catalog.Catalog> GetProducts(CatalogFilterData ci, ICatalogAIService catalogAIService, ICatalogService catalogService) { int?brandId = -1; if (!string.IsNullOrEmpty(ci.Brand)) { var brands = await catalogService.GetBrandsAsync(); brandId = Convert.ToInt32(brands.FirstOrDefault(b => b.Text.Equals(ci.Brand, StringComparison.InvariantCultureIgnoreCase))?.Id); } if (brandId < 1) { brandId = null; } int?typeId = -1; if (!string.IsNullOrEmpty(ci.Type)) { var types = await catalogService.GetTypesAsync(); typeId = Convert.ToInt32(types.FirstOrDefault(b => b.Text.Equals(ci.Type, StringComparison.InvariantCultureIgnoreCase))?.Id); } if (typeId < 1) { typeId = null; } var products = ci.Tags != null && !ci.Tags.Any() ? Models.Catalog.Catalog.Empty : await catalogAIService.GetCatalogItems(ci.PageIndex, CatalogFilterData.PageSize, brandId, typeId, ci.Tags); return(products); }
private async Task ShowCatalog(IDialogContext context) { var logged = await identityService.IsAuthenticatedAsync(context); var reply = context.MakeMessage(); reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; Catalog catalog; if (_filter.Tags != null) { if (_filter.Tags.Any()) { catalog = await catalogAIService.GetCatalogItems(_currentPage, _itemsPage, _filter.Brand, _filter.Type, _filter.Tags); } else { catalog = Catalog.Empty; } } else { catalog = await catalogService.GetCatalogItems(_currentPage, _itemsPage, _filter.Brand, _filter.Type); } int pageCount = (catalog.Count + _itemsPage - 1) / _itemsPage; if (catalog.Count != 0) { reply.Text = $"Page {_currentPage + 1} of {pageCount} ( {catalog.Count} items )"; reply.Attachments = CatalogCarousel(catalog, logged, !context.Activity.IsSkypeChannel()); } else { reply.Text = TextResources.There_are_no_results_matching_your_search; } reply.SuggestedActions = new SuggestedActions() { Actions = CreateHomeAndLoginButtons(pageCount, logged) }; await context.PostAsync(reply); }
public async Task <IActionResult> Index(int?BrandFilterApplied, int?TypesFilterApplied, int?page, IFormFile ImageFilter, string Tags, [FromQuery] string errorMsg) { var itemsPage = 12; IEnumerable <string> tags = null; var imageFilterActive = ImageFilter != null && ImageFilter.Length > 0; if (imageFilterActive) { using (var ms = new MemoryStream()) { await ImageFilter.CopyToAsync(ms); tags = await _productImageSearchService.ClassifyImageAsync(ms.ToArray()); } } else if (!String.IsNullOrEmpty(Tags)) { tags = Tags.Split(','); } var noTagsAvailable = (tags == null || !tags.Any()); var catalog = imageFilterActive && noTagsAvailable ? Catalog.Empty : await _catalogAISvc.GetCatalogItems(page ?? 0, itemsPage, BrandFilterApplied, TypesFilterApplied, tags); var vm = new IndexViewModel() { CatalogItems = catalog.Data, Brands = await _catalogSvc.GetBrands(), Types = await _catalogSvc.GetTypes(), BrandFilterApplied = BrandFilterApplied ?? 0, TypesFilterApplied = TypesFilterApplied ?? 0, Tags = noTagsAvailable ? String.Empty : String.Join(',', tags), TagsActive = noTagsAvailable ? String.Empty : "active", PaginationInfo = new PaginationInfo() { ActualPage = page ?? 0, ItemsPerPage = catalog.Data.Count, TotalItems = catalog.Count, TotalPages = (int)Math.Ceiling(((decimal)catalog.Count / itemsPage)) } }; if (catalog?.Data == null || !catalog.Data.Any()) { ViewBag.EmptyCatalogMsg = imageFilterActive ? "Sorry, we could not find any product similar to your sample image" : "Sorry, we could not find any product"; } vm.PaginationInfo.Next = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : ""; vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : ""; ViewBag.BasketInoperativeMsg = errorMsg; ViewBag.ProductSearchImageBasedLabel = $"product search image-based ({settings.Value.ProductSearchImageBased.Approach})"; return(View(vm)); }