Delete Catalog item coded.
This commit is contained in:
parent
1da3897eda
commit
4ce36b468f
@ -61,5 +61,21 @@ namespace eShopOnContainers.Core.Services.Catalog
|
||||
|
||||
return MockCatalogType;
|
||||
}
|
||||
public async Task<CatalogItem> GetCatalogItemAsync(string id)
|
||||
{
|
||||
await Task.Delay(500);
|
||||
|
||||
return MockCatalog.FirstOrDefault(c => c.Id == id);
|
||||
}
|
||||
|
||||
public async Task DeleteCatalogItem(string catalogItemId)
|
||||
{
|
||||
var itemToRemove = MockCatalog.FirstOrDefault(c => c.Id == catalogItemId);
|
||||
await Task.Delay(500);
|
||||
if (itemToRemove != null)
|
||||
MockCatalog.Remove(itemToRemove);
|
||||
else
|
||||
throw new ArgumentException(message: "item could not be found", paramName: nameof(catalogItemId));
|
||||
}
|
||||
}
|
||||
}
|
@ -10,5 +10,7 @@ namespace eShopOnContainers.Core.Services.Catalog
|
||||
Task<ObservableCollection<CatalogItem>> FilterAsync(int catalogBrandId, int catalogTypeId);
|
||||
Task<ObservableCollection<CatalogType>> GetCatalogTypeAsync();
|
||||
Task<ObservableCollection<CatalogItem>> GetCatalogAsync();
|
||||
Task<CatalogItem> GetCatalogItemAsync(string id);
|
||||
Task DeleteCatalogItem(string catalogItemId);
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,8 @@ namespace eShopOnContainers.Catalog.WebForms
|
||||
|
||||
protected _Default() { }
|
||||
|
||||
public _Default(ICatalogService catalog)
|
||||
{
|
||||
public _Default(ICatalogService catalog) =>
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
@ -33,15 +31,12 @@ namespace eShopOnContainers.Catalog.WebForms
|
||||
// int startRowIndex
|
||||
// out int totalRowCount
|
||||
// string sortByExpression
|
||||
public async Task<IEnumerable<CatalogItem>> GetCatalogDataAsync()
|
||||
{
|
||||
return await catalog?.GetCatalogAsync();
|
||||
}
|
||||
public async Task<IEnumerable<CatalogItem>> GetCatalogDataAsync() =>
|
||||
(await catalog?.GetCatalogAsync()).AsEnumerable();
|
||||
|
||||
// The id parameter name should match the DataKeyNames value set on the control
|
||||
public async Task DeleteCatalogItemAsync(int id)
|
||||
public Task DeleteCatalogItemAsync(int id)
|
||||
{
|
||||
//TODO: Call the service.
|
||||
return catalog?.DeleteCatalogItem(id.ToString());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using eShopOnContainers.Core.Models.Catalog;
|
||||
using eShopOnContainers.Core.Services.RequestProvider;
|
||||
using eShopOnContainers.Core.Extensions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// from https://github.com/dotnet/eShopOnContainers/blob/vs2017/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/CatalogService.cs
|
||||
// TODO: DRY this stuff.
|
||||
namespace eShopOnContainers.Core.Services.Catalog
|
||||
{
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
private readonly IRequestProvider _requestProvider;
|
||||
|
||||
public CatalogService(IRequestProvider requestProvider)
|
||||
{
|
||||
_requestProvider = requestProvider;
|
||||
}
|
||||
|
||||
public async Task<ObservableCollection<CatalogItem>> FilterAsync(int catalogBrandId, int catalogTypeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO:
|
||||
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.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);
|
||||
|
||||
if (catalog?.Data != null)
|
||||
return catalog?.Data.ToObservableCollection();
|
||||
else
|
||||
return new ObservableCollection<CatalogItem>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new ObservableCollection<CatalogItem>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ObservableCollection<CatalogItem>> GetCatalogAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO:
|
||||
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
|
||||
|
||||
builder.Path = "api/v1/catalog/items";
|
||||
|
||||
string uri = builder.ToString();
|
||||
|
||||
CatalogRoot catalog =
|
||||
await _requestProvider.GetAsync<CatalogRoot>(uri);
|
||||
|
||||
if (catalog?.Data != null)
|
||||
{
|
||||
// TODO: ServicesHelper.FixCatalogItemPictureUri(catalog?.Data);
|
||||
|
||||
return catalog?.Data.ToObservableCollection();
|
||||
}
|
||||
else
|
||||
return new ObservableCollection<CatalogItem>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new ObservableCollection<CatalogItem>();
|
||||
}
|
||||
}
|
||||
|
||||
public Task<CatalogItem> GetCatalogItemAsync(string id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<ObservableCollection<CatalogBrand>> GetCatalogBrandAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO:
|
||||
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
|
||||
|
||||
builder.Path = "api/v1/catalog/catalogbrands";
|
||||
|
||||
string uri = builder.ToString();
|
||||
|
||||
IEnumerable<CatalogBrand> brands =
|
||||
await _requestProvider.GetAsync<IEnumerable<CatalogBrand>>(uri);
|
||||
|
||||
if (brands != null)
|
||||
return brands?.ToObservableCollection();
|
||||
else
|
||||
return new ObservableCollection<CatalogBrand>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new ObservableCollection<CatalogBrand>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ObservableCollection<CatalogType>> GetCatalogTypeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO:
|
||||
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
|
||||
|
||||
builder.Path = "api/v1/catalog/catalogtypes";
|
||||
|
||||
string uri = builder.ToString();
|
||||
|
||||
IEnumerable<CatalogType> types =
|
||||
await _requestProvider.GetAsync<IEnumerable<CatalogType>>(uri);
|
||||
|
||||
if (types != null)
|
||||
return types.ToObservableCollection();
|
||||
else
|
||||
return new ObservableCollection<CatalogType>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new ObservableCollection<CatalogType>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteCatalogItem(string catalogItemId)
|
||||
{
|
||||
// TODO:
|
||||
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
|
||||
|
||||
builder.Path = $"api/v1/catalog/{catalogItemId}";
|
||||
|
||||
string uri = builder.ToString();
|
||||
|
||||
await _requestProvider.DeleteAsync(uri);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user