Browse Source

edit using the mock service works

pull/182/head
Bill Wagner 7 years ago
parent
commit
83c697372b
6 changed files with 47 additions and 16 deletions
  1. +24
    -5
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/CatalogMockService.cs
  2. +3
    -1
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/ICatalogService.cs
  3. +1
    -1
      src/Web/Catalog.WebForms/Catalog.WebForms/Default.aspx.cs
  4. +1
    -1
      src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx
  5. +4
    -6
      src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx.cs
  6. +14
    -2
      src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogService.cs

+ 24
- 5
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/CatalogMockService.cs View File

@ -10,19 +10,21 @@ namespace eShopOnContainers.Core.Services.Catalog
{
public class CatalogMockService : ICatalogService
{
private ObservableCollection<CatalogBrand> MockCatalogBrand = new ObservableCollection<CatalogBrand>
// Change to static so these remain
// in scope between requests:
private static ObservableCollection<CatalogBrand> MockCatalogBrand = new ObservableCollection<CatalogBrand>
{
new CatalogBrand { Id = 1, Brand = "Azure" },
new CatalogBrand { Id = 2, Brand = "Visual Studio" }
};
private ObservableCollection<CatalogType> MockCatalogType = new ObservableCollection<CatalogType>
private static ObservableCollection<CatalogType> MockCatalogType = new ObservableCollection<CatalogType>
{
new CatalogType { Id = 1, Type = "Mug" },
new CatalogType { Id = 2, Type = "T-Shirt" }
};
private ObservableCollection<CatalogItem> MockCatalog = new ObservableCollection<CatalogItem>
private static ObservableCollection<CatalogItem> MockCatalog = new ObservableCollection<CatalogItem>
{
new CatalogItem { Id = Common.Common.MockCatalogItemId01, PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_01.png" : "Assets/fake_product_01.png", Name = ".NET Bot Blue Sweatshirt (M)", Price = 19.50M, CatalogBrandId = 2, CatalogBrand = "Visual Studio", CatalogTypeId = 2, CatalogType = "T-Shirt" },
new CatalogItem { Id = Common.Common.MockCatalogItemId02, PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_02.png" : "Assets/fake_product_02.png", Name = ".NET Bot Purple Sweatshirt (M)", Price = 19.50M, CatalogBrandId = 2, CatalogBrand = "Visual Studio", CatalogTypeId = 2, CatalogType = "T-Shirt" },
@ -35,7 +37,8 @@ namespace eShopOnContainers.Core.Services.Catalog
{
await Task.Delay(500);
return MockCatalog;
// copy so that edits must be changed here to take affect:
return new ObservableCollection<CatalogItem>(MockCatalog);
}
public async Task<ObservableCollection<CatalogItem>> FilterAsync(int catalogBrandId, int catalogTypeId)
@ -68,7 +71,7 @@ namespace eShopOnContainers.Core.Services.Catalog
return MockCatalog.FirstOrDefault(c => c.Id == id);
}
public async Task DeleteCatalogItem(string catalogItemId)
public async Task DeleteCatalogItemAsync(string catalogItemId)
{
var itemToRemove = MockCatalog.FirstOrDefault(c => c.Id == catalogItemId);
await Task.Delay(500);
@ -77,5 +80,21 @@ namespace eShopOnContainers.Core.Services.Catalog
else
throw new ArgumentException(message: "item could not be found", paramName: nameof(catalogItemId));
}
public async Task<CatalogItem> UpdateCatalogItemAsync(CatalogItem item)
{
var itemToChange = MockCatalog.FirstOrDefault(c => item.Id == c.Id);
await Task.Delay(500);
if (itemToChange != null)
{
itemToChange.CatalogBrandId = item.CatalogBrandId;
itemToChange.CatalogTypeId = item.CatalogTypeId;
itemToChange.Description = item.Description;
itemToChange.Name = item.Name;
itemToChange.Price = item.Price;
}
return itemToChange;
}
}
}

+ 3
- 1
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/ICatalogService.cs View File

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

+ 1
- 1
src/Web/Catalog.WebForms/Catalog.WebForms/Default.aspx.cs View File

@ -36,7 +36,7 @@ namespace eShopOnContainers.Catalog.WebForms
public Task DeleteCatalogItemAsync(int id)
{
return catalog?.DeleteCatalogItem(id.ToString());
return catalog?.DeleteCatalogItemAsync(id.ToString());
}
}
}

+ 1
- 1
src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx View File

@ -5,7 +5,7 @@
ItemType="eShopOnContainers.Core.Models.Catalog.CatalogItem" DataKeyNames="Id"
SelectMethod="GetCatalogItemAsync"
UpdateMethod="UpdateCatalogItemAsync"
InsertMethod="InsertCatalogItemAsync"
InsertMethod="InsertCatalogItemAsync"
CssClass="table-compact table-full-width">
<EditItemTemplate>
<div class="row form-inline">


+ 4
- 6
src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx.cs View File

@ -47,21 +47,19 @@ namespace eShopOnContainers.Catalog.WebForms
}
// The id parameter name should match the DataKeyNames value set on the control
public void UpdateCatalogItemAsync(int id)
public async Task UpdateCatalogItemAsync(int id)
{
CatalogItem item = null;
// Load the item here, e.g. item = MyDataLayer.Find(id);
CatalogItem item = await catalog?.GetCatalogItemAsync(id.ToString());
if (item == null)
{
// The item wasn't found
ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
return;
}
if (TryUpdateModel(item) && (ModelState.IsValid))
{
// Save changes here, e.g. MyDataLayer.SaveChanges();
// Send the item to the Catalog Service.
await catalog?.UpdateCatalogItemAsync(item);
Response.Redirect("~");
}
}


+ 14
- 2
src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogService.cs View File

@ -128,7 +128,7 @@ namespace eShopOnContainers.Core.Services.Catalog
}
}
public async Task DeleteCatalogItem(string catalogItemId)
public Task DeleteCatalogItemAsync(string catalogItemId)
{
// TODO:
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
@ -137,7 +137,19 @@ namespace eShopOnContainers.Core.Services.Catalog
string uri = builder.ToString();
await _requestProvider.DeleteAsync(uri);
return _requestProvider.DeleteAsync(uri);
}
public Task<CatalogItem> UpdateCatalogItemAsync(CatalogItem item)
{
// TODO:
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
builder.Path = "api/v1/catalog/edit";
string uri = builder.ToString();
return _requestProvider.PostAsync(uri, item);
}
}
}

Loading…
Cancel
Save