edit using the mock service works
This commit is contained in:
parent
bb34b173f5
commit
ad71ed66f9
@ -36,7 +36,7 @@ namespace eShopOnContainers.Catalog.WebForms
|
||||
|
||||
public Task DeleteCatalogItemAsync(int id)
|
||||
{
|
||||
return catalog?.DeleteCatalogItem(id.ToString());
|
||||
return catalog?.DeleteCatalogItemAsync(id.ToString());
|
||||
}
|
||||
}
|
||||
}
|
@ -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">
|
||||
|
@ -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("~");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,19 +13,21 @@ namespace eShopOnContainers.Core.Services.Catalog
|
||||
// Note: Device specific conditionals have been removed.
|
||||
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 = "Content/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 = "Content/fake_product_02.png", Name = ".NET Bot Purple Sweatshirt (M)", Price = 19.50M, CatalogBrandId = 2, CatalogBrand = "Visual Studio", CatalogTypeId = 2, CatalogType = "T-Shirt" },
|
||||
@ -38,7 +40,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)
|
||||
@ -72,7 +75,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);
|
||||
@ -81,5 +84,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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,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);
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user