insert works
This commit is contained in:
parent
ad71ed66f9
commit
7dd0d3f7f5
@ -13,7 +13,6 @@ namespace eShopOnContainers.Catalog.WebForms
|
|||||||
public partial class _Default : Page
|
public partial class _Default : Page
|
||||||
{
|
{
|
||||||
private ICatalogService catalog;
|
private ICatalogService catalog;
|
||||||
private CatalogItem itemToEdit;
|
|
||||||
|
|
||||||
protected _Default() { }
|
protected _Default() { }
|
||||||
|
|
||||||
|
@ -24,13 +24,13 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 form-group">
|
<div class="col-md-12 form-group">
|
||||||
<label for="ItemDescription">Description</label>
|
<label for="ItemDescription">Description</label>
|
||||||
<asp:TextBox runat="server" name="ItemDescription" Width="100%" ID="ItemDescription" CssClass="form-control form-input form-input-center" Text='<%# Bind("Description")%>' />
|
<asp:TextBox runat="server" Width="100%" ID="ItemDescription" CssClass="form-control form-input form-input-center" Text='<%# Bind("Description")%>' />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 form-group">
|
<div class="col-md-12 form-group">
|
||||||
<label for="ItemPrice">Price</label>
|
<label for="ItemPrice">Price</label>
|
||||||
<asp:TextBox runat="server" TextMode="Number" Width="75%" name="ItemPrice" ID="ItemPrice" CssClass="form-control form-input form-input-center" Text='<%# Bind("Price")%>' />
|
<asp:TextBox runat="server" TextMode="Number" Width="75%" ID="ItemPrice" CssClass="form-control form-input form-input-center" Text='<%# Bind("Price")%>' />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -74,13 +74,13 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 form-group">
|
<div class="col-md-12 form-group">
|
||||||
<label for="ItemDescription">Description</label>
|
<label for="ItemDescription">Description</label>
|
||||||
<asp:TextBox runat="server" name="ItemDescription" Width="100%" ID="ItemDescription" CssClass="form-control form-input form-input-center" Text='<%# Bind("Description")%>' />
|
<asp:TextBox runat="server" Width="100%" ID="ItemDescription" CssClass="form-control form-input form-input-center" Text='<%# Bind("Description")%>' />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 form-group">
|
<div class="col-md-12 form-group">
|
||||||
<label for="ItemPrice">Price</label>
|
<label for="ItemPrice">Price</label>
|
||||||
<asp:TextBox runat="server" TextMode="Number" Width="75%" name="ItemPrice" ID="ItemPrice" CssClass="form-control form-input form-input-center" Text='<%# Bind("Price")%>' />
|
<asp:TextBox runat="server" TextMode="Number" Width="75%" ID="ItemPrice" CssClass="form-control form-input form-input-center" Text='<%# Bind("Price")%>' />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -97,7 +97,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<asp:LinkButton runat="server" Text="Update" CommandName="Update" />
|
<asp:LinkButton runat="server" Text="Add" CommandName="Insert" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" />
|
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" />
|
||||||
|
@ -63,14 +63,15 @@ namespace eShopOnContainers.Catalog.WebForms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertCatalogItemAsync()
|
public async Task InsertCatalogItemAsync()
|
||||||
{
|
{
|
||||||
var item = new eShopOnContainers.Core.Models.Catalog.CatalogItem();
|
var item = new eShopOnContainers.Core.Models.Catalog.CatalogItem();
|
||||||
TryUpdateModel(item);
|
TryUpdateModel(item);
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
// Save changes here
|
// Save changes here
|
||||||
|
await catalog?.CreateCatalogItemAsync(item);
|
||||||
|
Response.Redirect("~");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,5 +100,17 @@ namespace eShopOnContainers.Core.Services.Catalog
|
|||||||
return itemToChange;
|
return itemToChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<CatalogItem> 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -151,5 +151,18 @@ namespace eShopOnContainers.Core.Services.Catalog
|
|||||||
|
|
||||||
return _requestProvider.PostAsync(uri, item);
|
return _requestProvider.PostAsync(uri, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<CatalogItem> 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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,6 @@ namespace eShopOnContainers.Core.Services.Catalog
|
|||||||
Task<CatalogItem> GetCatalogItemAsync(string id);
|
Task<CatalogItem> GetCatalogItemAsync(string id);
|
||||||
Task DeleteCatalogItemAsync(string catalogItemId);
|
Task DeleteCatalogItemAsync(string catalogItemId);
|
||||||
Task<CatalogItem> UpdateCatalogItemAsync(CatalogItem item);
|
Task<CatalogItem> UpdateCatalogItemAsync(CatalogItem item);
|
||||||
|
Task<CatalogItem> CreateCatalogItemAsync(CatalogItem item);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user