Delete Catalog item coded.

This commit is contained in:
Bill Wagner 2017-03-23 14:06:06 -04:00
parent aefc0a50bf
commit bb34b173f5
4 changed files with 28 additions and 10 deletions

View File

@ -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());
}
}
}

View File

@ -71,5 +71,15 @@ namespace eShopOnContainers.Core.Services.Catalog
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));
}
}
}

View File

@ -127,5 +127,17 @@ namespace eShopOnContainers.Core.Services.Catalog
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);
}
}
}

View File

@ -14,5 +14,6 @@ namespace eShopOnContainers.Core.Services.Catalog
Task<ObservableCollection<CatalogType>> GetCatalogTypeAsync();
Task<ObservableCollection<CatalogItem>> GetCatalogAsync();
Task<CatalogItem> GetCatalogItemAsync(string id);
Task DeleteCatalogItem(string catalogItemId);
}
}