Skip to content

Instantly share code, notes, and snippets.

@g0t4 g0t4/gist:4261025
Created Dec 11, 2012

Embed
What would you like to do?
KISS & AJAX Deletes
// I run across this type of code often (note ASP.Net MVC)
[HttpPost]
public string Delete(ObjectId id)
{
var record = _Database.Get<Record>(id);
if (record == null)
{
return "No matching record!";
}
_Database.Remove<Record>(id);
return "Deleted record!";
}
// If the user is interested in deleting the record, does it matter if someone else beat them to it?
[HttpPost]
public string Delete(ObjectId id)
{
_Database.Remove<Record>(id);
return "Deleted record!";
}
// Isn't the HTTP 200 OK status code enough to indicate success, the user or the software knows the context of the request it made:
[HttpPost]
public void Delete(ObjectId id)
{
_Database.Remove<Record>(id);
}
// Simple things to think about when reviewing code for simplicity, one line of code is much easier to maintain than seven.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.