Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eShopOnWeb/eShop.MVC/Controllers/CatalogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public IActionResult Create()
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create([Bind("Id", "Name", "Description", "Price", "PictureFileName", "CatalogTypeId", "CatalogBrandId", "AvailableStock", "RestockThreshold", "MaxStockThreshold", "OnReorder")] CatalogItem catalogItem)
public IActionResult Create([Bind("Id", "Name", "Description", "Price", "PictureFileName", "CatalogTypeId", "CatalogBrandId", "AvailableStock", "OnReorder")] CatalogItem catalogItem)
{
_log.Info($"Now processing... /Catalog/Create?catalogItemName={catalogItem.Name}");
if (ModelState.IsValid)
Expand Down Expand Up @@ -98,7 +98,7 @@ public IActionResult Edit(int? id)
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Edit([Bind("Id", "Name", "Description", "Price", "PictureFileName", "CatalogTypeId", "CatalogBrandId", "AvailableStock", "RestockThreshold", "MaxStockThreshold", "OnReorder")] CatalogItem catalogItem)
public IActionResult Edit([Bind("Id", "Name", "Description", "Price", "PictureFileName", "CatalogTypeId", "CatalogBrandId", "AvailableStock", "OnReorder")] CatalogItem catalogItem)
{
_log.Info($"Now processing... /Catalog/Edit?id={catalogItem.Id}");
if (ModelState.IsValid)
Expand Down
10 changes: 1 addition & 9 deletions eShopOnWeb/eShop.MVC/Models/CatalogItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,9 @@ public CatalogItem()
[Display(Name = "Stock")]
public int AvailableStock { get; set; }

// Available stock at which we should reorder
[Display(Name = "Restock")]
public int RestockThreshold { get; set; }

// Maximum number of units that can be in-stock at any time (due to physicial/logistical constraints in warehouses)
[Display(Name = "Max stock")]
public int MaxStockThreshold { get; set; }

/// <summary>
/// True if item is on reorder
/// </summary>
public bool OnReorder { get; set; }
}
}
}
38 changes: 2 additions & 36 deletions eShopOnWeb/eShop.MVC/Models/Infrastructure/CatalogDBInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ IEnumerable<CatalogItem> GetCatalogItemsFromFile(CatalogDBContext context)

string[] csvheaders;
string[] requiredHeaders = { "catalogtypename", "catalogbrandname", "description", "name", "price", "pictureFileName" };
string[] optionalheaders = { "availablestock", "restockthreshold", "maxstockthreshold", "onreorder" };
string[] optionalheaders = { "availablestock", "onreorder" };
csvheaders = GetHeaders(csvFileCatalogItems, requiredHeaders, optionalheaders);

var catalogTypeIdLookup = context.CatalogTypes.ToDictionary(ct => ct.Type, ct => ct.Id);
Expand Down Expand Up @@ -239,40 +239,6 @@ static CatalogItem CreateCatalogItem(string[] column, string[] headers, Dictiona
}
}

int restockThresholdIndex = Array.IndexOf(headers, "restockthreshold");
if (restockThresholdIndex != -1)
{
string restockThresholdString = column[restockThresholdIndex].Trim('"').Trim();
if (!String.IsNullOrEmpty(restockThresholdString))
{
if (int.TryParse(restockThresholdString, out int restockThreshold))
{
catalogItem.RestockThreshold = restockThreshold;
}
else
{
throw new Exception($"restockThreshold={restockThreshold} is not a valid integer");
}
}
}

int maxStockThresholdIndex = Array.IndexOf(headers, "maxstockthreshold");
if (maxStockThresholdIndex != -1)
{
string maxStockThresholdString = column[maxStockThresholdIndex].Trim('"').Trim();
if (!String.IsNullOrEmpty(maxStockThresholdString))
{
if (int.TryParse(maxStockThresholdString, out int maxStockThreshold))
{
catalogItem.MaxStockThreshold = maxStockThreshold;
}
else
{
throw new Exception($"maxStockThreshold={maxStockThreshold} is not a valid integer");
}
}
}

int onReorderIndex = Array.IndexOf(headers, "onreorder");
if (onReorderIndex != -1)
{
Expand Down Expand Up @@ -351,4 +317,4 @@ private void AddCatalogItemPictures()
ZipFile.ExtractToDirectory(zipFileCatalogItemPictures, picturePath.ToString());
}
}
}
}
2 changes: 1 addition & 1 deletion eShopOnWeb/eShop.MVC/Services/CatalogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ public void Dispose()
db.Dispose();
}
}
}
}
2 changes: 1 addition & 1 deletion eShopOnWeb/eShop.MVC/Services/CatalogServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ private List<CatalogItem> ComposeCatalogItems(List<CatalogItem> items)
;
}
}
}
}
14 changes: 1 addition & 13 deletions eShopOnWeb/eShop.MVC/Views/Catalog/CatalogTable.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
<th>
@Html.DisplayNameFor(model => model.AvailableStock)
</th>
<th>
@Html.DisplayNameFor(model => model.RestockThreshold)
</th>
<th>
@Html.DisplayNameFor(model => model.MaxStockThreshold)
</th>
<th></th>
</tr>
</thead>
Expand Down Expand Up @@ -63,12 +57,6 @@
<td>
@Html.DisplayFor(modelItem => item.AvailableStock)
</td>
<td>
@Html.DisplayFor(modelItem => item.RestockThreshold)
</td>
<td>
@Html.DisplayFor(modelItem => item.MaxStockThreshold)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "esh-table-link" }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }, new { @class = "esh-table-link" }) |
Expand All @@ -78,4 +66,4 @@
}
</tbody>

</table>
</table>
14 changes: 0 additions & 14 deletions eShopOnWeb/eShop.MVC/Views/Catalog/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,6 @@
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.RestockThreshold, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-3">
@Html.EditorFor(model => model.RestockThreshold, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.MaxStockThreshold, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-3">
@Html.EditorFor(model => model.MaxStockThreshold, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-3 text-right esh-button-actions">
@Html.ActionLink("[ Cancel ]", "Index", null, new { @class = "btn esh-button esh-button-secondary" })
Expand Down
16 changes: 0 additions & 16 deletions eShopOnWeb/eShop.MVC/Views/Catalog/Details.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,6 @@
@Html.DisplayFor(model => model.AvailableStock)
</dd>

<dt>
@Html.DisplayNameFor(model => model.RestockThreshold)
</dt>

<dd>
@Html.DisplayFor(model => model.RestockThreshold)
</dd>

<dt>
@Html.DisplayNameFor(model => model.MaxStockThreshold)
</dt>

<dd>
@Html.DisplayFor(model => model.MaxStockThreshold)
</dd>

</dl>
</div>
<p class="esh-link-list esh-link-item--margin">
Expand Down
14 changes: 0 additions & 14 deletions eShopOnWeb/eShop.MVC/Views/Catalog/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.RestockThreshold, htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-8">
@Html.EditorFor(model => model.RestockThreshold, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.MaxStockThreshold, htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-8">
@Html.EditorFor(model => model.MaxStockThreshold, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>

<div class="form-group">
<div class="col-md-12 text-right esh-button-actions">
@Html.ActionLink("[ Cancel ]", "Index", null, new { @class = "btn esh-button esh-button-secondary" })
Expand Down