Skip to content

Instantly share code, notes, and snippets.

@g0t4
Created December 11, 2012 18:56
Show Gist options
  • Save g0t4/4261025 to your computer and use it in GitHub Desktop.
Save g0t4/4261025 to your computer and use it in GitHub Desktop.
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