Integrated Filter API

This commit is contained in:
Javier Suárez Ruiz 2016-11-21 16:59:52 +01:00
parent 84d66877be
commit 0d2ec11c6a
4 changed files with 16 additions and 8 deletions

View File

@ -1,6 +1,5 @@
using eShopOnContainers.Core.Extensions;
using eShopOnContainers.Core.Models.Catalog;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
@ -38,13 +37,13 @@ namespace eShopOnContainers.Core.Services.Catalog
return MockCatalog;
}
public async Task<ObservableCollection<CatalogItem>> FilterAsync(string catalogBrand, string catalogType)
public async Task<ObservableCollection<CatalogItem>> FilterAsync(int catalogBrandId, int catalogTypeId)
{
await Task.Delay(500);
return MockCatalog
.Where(c => c.CatalogBrand.Equals(catalogBrand, StringComparison.CurrentCultureIgnoreCase) &&
c.CatalogType.Equals(catalogType, StringComparison.CurrentCultureIgnoreCase))
.Where(c => c.CatalogBrandId == catalogBrandId &&
c.CatalogTypeId == catalogTypeId)
.ToObservableCollection();
}

View File

@ -17,9 +17,18 @@ namespace eShopOnContainers.Core.Services.Catalog
_requestProvider = requestProvider;
}
public Task<ObservableCollection<CatalogItem>> FilterAsync(string catalogBrand, string catalogType)
public async Task<ObservableCollection<CatalogItem>> FilterAsync(int catalogBrandId, int catalogTypeId)
{
throw new NotImplementedException();
UriBuilder builder = new UriBuilder(GlobalSetting.CatalogEndpoint);
builder.Path = string.Format("api/v1/catalog/items/type/{0}/brand/{1}", catalogTypeId, catalogBrandId);
string uri = builder.ToString();
CatalogRoot catalog =
await _requestProvider.GetAsync<CatalogRoot>(uri);
return catalog?.Data?.ToObservableCollection();
}
public async Task<ObservableCollection<CatalogItem>> GetCatalogAsync()

View File

@ -7,7 +7,7 @@ namespace eShopOnContainers.Core.Services.Catalog
public interface ICatalogService
{
Task<ObservableCollection<CatalogBrand>> GetCatalogBrandAsync();
Task<ObservableCollection<CatalogItem>> FilterAsync(string catalogBrand, string catalogType);
Task<ObservableCollection<CatalogItem>> FilterAsync(int catalogBrandId, int catalogTypeId);
Task<ObservableCollection<CatalogType>> GetCatalogTypeAsync();
Task<ObservableCollection<CatalogItem>> GetCatalogAsync();
Task<CatalogItem> GetCatalogItemAsync(string id);

View File

@ -110,7 +110,7 @@ namespace eShopOnContainers.Core.ViewModels
IsBusy = true;
MessagingCenter.Send(this, MessengerKeys.Filter);
Products = await _productsService.FilterAsync(Brand.Brand, Type.Type);
Products = await _productsService.FilterAsync(Brand.Id, Type.Id);
IsBusy = false;
}