Browse Source

UI is in place for insert.

pull/182/head
Bill Wagner 8 years ago
parent
commit
1da3897eda
3 changed files with 75 additions and 9 deletions
  1. +10
    -1
      src/Web/Catalog.WebForms/Catalog.WebForms/Default.aspx
  2. +50
    -0
      src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx
  3. +15
    -8
      src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx.cs

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

@ -4,7 +4,9 @@
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:ListView ID="catalogList" runat="server"
DataKeyNames="Id" GroupItemCount="3"
ItemType="eShopOnContainers.Core.Models.Catalog.CatalogItem" SelectMethod="GetCatalogDataAsync" DeleteMethod="DeleteCatalogItemAsync">
ItemType="eShopOnContainers.Core.Models.Catalog.CatalogItem"
SelectMethod="GetCatalogDataAsync"
DeleteMethod="DeleteCatalogItemAsync">
<EmptyDataTemplate>
<div class="row">
<span class="col-md-10 col-md-offset-1">There's nothing in the catalog to display at this time.
@ -44,4 +46,11 @@
</div>
</ItemTemplate>
</asp:ListView>
<div class="row">
<span class="esh-catalog-label col-md-4 col-md-offset-2l">
<a href="EditCatalogItem.aspx">
Insert item
</a>
</span>
</div>
</asp:Content>

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

@ -57,5 +57,55 @@
</div>
</div>
</EditItemTemplate>
<InsertItemTemplate>
<div class="row form-inline">
<div class="col-md-6">
<asp:FileUpload CssClass="esh-catalog-thumbnail" runat="server" />
</div>
<div class="col-md-6">
<div class="container">
<div class="row">
<div class="col-md-12 form-group">
<label>Name</label>
<asp:TextBox runat="server" ID="itemName" CssClass="form-control form-input form-input-center" Text='<%# Bind("Name")%>' />
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<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")%>' />
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<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")%>' />
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label class="control-label form-label" for="ItemBrand">Brand</label>
<asp:DropDownList ID="ItemBrand" runat="server" DataTextField="Brand" />
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label class="control-label form-label" for="ItemType">Type</label>
<asp:DropDownList ID="ItemType" runat="server" DataTextField="Type" />
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<asp:LinkButton runat="server" Text="Update" CommandName="Update" />
</div>
<div class="col-md-6 form-group">
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" />
</div>
</div>
</div>
</div>
</div>
</InsertItemTemplate>
</asp:FormView>
</asp:Content>

+ 15
- 8
src/Web/Catalog.WebForms/Catalog.WebForms/EditCatalogItem.aspx.cs View File

@ -32,17 +32,24 @@ namespace eShopOnContainers.Catalog.WebForms
// The id parameter should match the DataKeyNames value set on the control
// or be decorated with a value provider attribute, e.g. [QueryString]int id
public async Task<CatalogItem> GetCatalogItemAsync([QueryString]int id)
public async Task<CatalogItem> GetCatalogItemAsync([QueryString]int? id)
{
// TODO: If null, go into insert mode.
var itemToEdit = await catalog?.GetCatalogItemAsync(id.ToString());
return itemToEdit;
if (id.HasValue)
{
var itemToEdit = await catalog?.GetCatalogItemAsync(id.ToString());
return itemToEdit;
}
else
{
EditCatalogItemForm.ChangeMode(FormViewMode.Insert);
return new CatalogItem();
}
}
// The id parameter name should match the DataKeyNames value set on the control
public void UpdateCatalogItemAsync(int id)
{
eShopOnContainers.Core.Models.Catalog.CatalogItem item = null;
CatalogItem item = null;
// Load the item here, e.g. item = MyDataLayer.Find(id);
if (item == null)
{
@ -50,11 +57,11 @@ namespace eShopOnContainers.Catalog.WebForms
ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
return;
}
TryUpdateModel(item);
if (ModelState.IsValid)
if (TryUpdateModel(item) && (ModelState.IsValid))
{
// Save changes here, e.g. MyDataLayer.SaveChanges();
// Send the item to the Catalog Service.
}
}


Loading…
Cancel
Save