Hey Guys,
I added my own delete routine to the Classifieds tutorial.
Oddly, it deletes new records differently than old records(?). My delete routine has a delete button and then a final CONFIRMation prompt. It seems to bypass the confirm prompt for only my new records(?). I don't know if it's a CACHE issue or something else.
Thanks for Looking AND your Great Books,
Edgy in Mesquite
*** my Delete Button: ************
<p><input type="submit" name="buttonDelete" value="Delete Item"
onclick="return confirm('Confirm:\nDelete this Item from Ads\n @title')" />
*** Delete Code snippet **********
if(IsPost && !Request["buttonDelete"].IsEmpty()){
itemId = Request.Form["itemId"];
var db = Database.Open("Classifieds");
var deleteCommand = "DELETE FROM Items WHERE ID = @0";
WebCache.Remove("cachedData");
db.Execute(deleteCommand, itemId);
Response.Redirect("~/Admin/Items");
**********************************************
******** the Complete Delete.cshtnl Code ************
Code:
@{
Page.Title = "Delete Ad";
var itemId = "";
var title = "";
var description = "";
var price = 0m;
var categoryId = 0;
var datePosted = "";
var duration = 0;
var condition = "";
var confirmLne = "Confirm: \n Delete This Item \n@title";
if(!IsPost){
if(!Request.QueryString["id"].IsEmpty() && Request.QueryString["id"].IsInt()){
itemId = Request.QueryString["id"];
var db = Database.Open("Classifieds");
var dbCommand = "SELECT * FROM Items WHERE Id = @0";
var row = db.QuerySingle(dbCommand,itemId);
if(row != null) {
title = row.Title;
description = row.Description;
price = row.Price;
categoryId = row.CategoryId;
condition = row.Condition;
datePosted = row.DatePosted.ToString("D");
//category = row.Category;
//itemId = row.Id;
}
else{
Validation.AddFormError("No Classified AD was found for that ID.");
}
}
else{
Validation.AddFormError("No Classified Ad was found for that ID.");
}
}
if(IsPost && !Request["buttonDelete"].IsEmpty()){
itemId = Request.Form["itemId"];
var db = Database.Open("Classifieds");
var deleteCommand = "DELETE FROM Items WHERE ID = @0";
WebCache.Remove("cachedData");
db.Execute(deleteCommand, itemId);
Response.Redirect("~/Admin/Items");
}
}
<html>
<head>
<title>Delete an Item</title>
</head>
<body>
<h1>Delete an Item</h1>
@Html.ValidationSummary()
@*<p><a href="~/Admin/EditItems">Return to Items listing</a></p>*@
<form method="post">
<fieldset>
<legend>Item Information</legend>
<p><span>Title:</span>
<span>@title</span></p>
<p><span>Description:</span>
<span>@description</span></p>
<p><span>Price:</span>
<span>@price.ToString("c")</span></p>
<p><span>Condition:</span>
<span>@condition</span></p>
<p><span>Date Posted:</span>
<span>@datePosted</span></p>
<input type="hidden" name="itemId" value="@itemId" />
<p><input type="submit" name="buttonDelete" value="Delete Item"
onclick="return confirm('Confirm:\nDelete this Item from Ads\n @title')" />
<input type="button" value="Cancel" name="Cancel" onclick="window.location.href='Items.cshtml'; return false;" /></p>
</fieldset>
<p><a href="~/Admin/Items">Return to Items listing</a></p>
</form>
</body>
</html>