Browse Source

Delete Catalog item coded.

pull/136/head
Bill Wagner 7 years ago
parent
commit
bb34b173f5
4 changed files with 28 additions and 10 deletions
  1. +5
    -10
      src/Web/Catalog.WebForms/Catalog.WebForms/Default.aspx.cs
  2. +10
    -0
      src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogMockService.cs
  3. +12
    -0
      src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogService.cs
  4. +1
    -0
      src/Web/Catalog.WebForms/Catalog.WebForms/Services/ICatalogService.cs

+ 5
- 10
src/Web/Catalog.WebForms/Catalog.WebForms/Default.aspx.cs 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());
}
}
}

+ 10
- 0
src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogMockService.cs 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));
}
}
}

+ 12
- 0
src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogService.cs 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);
}
}
}

+ 1
- 0
src/Web/Catalog.WebForms/Catalog.WebForms/Services/ICatalogService.cs 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);
}
}

Loading…
Cancel
Save