From e968d9f24dc74aea8eea18ff57dd23510d17b829 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Thu, 23 Mar 2017 15:06:56 -0400 Subject: [PATCH] insert works --- .../Services/Catalog/CatalogMockService.cs | 12 ++++++++++++ .../Services/Catalog/ICatalogService.cs | 2 +- .../Catalog.WebForms/Default.aspx.cs | 1 - .../Catalog.WebForms/EditCatalogItem.aspx | 10 +++++----- .../Catalog.WebForms/EditCatalogItem.aspx.cs | 5 +++-- .../Catalog.WebForms/Services/CatalogService.cs | 13 +++++++++++++ 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/CatalogMockService.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/CatalogMockService.cs index 82eac3105..c19a1a8a4 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/CatalogMockService.cs +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/CatalogMockService.cs @@ -96,5 +96,17 @@ namespace eShopOnContainers.Core.Services.Catalog return itemToChange; } + public async Task CreateCatalogItemAsync(CatalogItem item) + { + // set the Id + var nextId = MockCatalog.Max(c => int.Parse(c.Id)) + 1; + item.Id = nextId.ToString(); + await Task.Delay(500); + + // add. + MockCatalog.Add(item); + return item; + } + } } \ No newline at end of file diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/ICatalogService.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/ICatalogService.cs index 70de68c0f..7ea3cf565 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/ICatalogService.cs +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/ICatalogService.cs @@ -13,6 +13,6 @@ namespace eShopOnContainers.Core.Services.Catalog Task GetCatalogItemAsync(string id); Task DeleteCatalogItemAsync(string catalogItemId); Task UpdateCatalogItemAsync(CatalogItem item); - + Task CreateCatalogItemAsync(CatalogItem item); } } diff --git a/src/Web/Catalog.WebForms/Catalog.WebForms/Default.aspx.cs b/src/Web/Catalog.WebForms/Catalog.WebForms/Default.aspx.cs index 711437104..6e001ff4d 100644 --- a/src/Web/Catalog.WebForms/Catalog.WebForms/Default.aspx.cs +++ b/src/Web/Catalog.WebForms/Catalog.WebForms/Default.aspx.cs @@ -13,7 +13,6 @@ namespace eShopOnContainers.Catalog.WebForms public partial class _Default : Page { private ICatalogService catalog; - private CatalogItem itemToEdit; protected _Default() { } diff --git a/src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx b/src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx index af932d2d3..040878b20 100644 --- a/src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx +++ b/src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx @@ -24,13 +24,13 @@
- +
- +
@@ -74,13 +74,13 @@
- +
- +
@@ -97,7 +97,7 @@
- +
diff --git a/src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx.cs b/src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx.cs index 88382a4b7..44d9f6c13 100644 --- a/src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx.cs +++ b/src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx.cs @@ -63,14 +63,15 @@ namespace eShopOnContainers.Catalog.WebForms } } - public void InsertCatalogItemAsync() + public async Task InsertCatalogItemAsync() { var item = new eShopOnContainers.Core.Models.Catalog.CatalogItem(); TryUpdateModel(item); if (ModelState.IsValid) { // Save changes here - + await catalog?.CreateCatalogItemAsync(item); + Response.Redirect("~"); } } } diff --git a/src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogService.cs b/src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogService.cs index 88e1cd97f..f77eb11d4 100644 --- a/src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogService.cs +++ b/src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogService.cs @@ -151,5 +151,18 @@ namespace eShopOnContainers.Core.Services.Catalog return _requestProvider.PostAsync(uri, item); } + + public Task CreateCatalogItemAsync(CatalogItem item) + { + // TODO: + UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */); + + builder.Path = "api/v1/catalog/create"; + + string uri = builder.ToString(); + + return _requestProvider.PostAsync(uri, item); + + } } }