I'm working on a .Net WebApi project in which I've got Api controllers making calls to a service layer.
Let's say I want to set up an end-point to delete a resource if it exists. If nothing is found, return an error message to that effect.
I need some clarification on where best to place the logic for checking for whether an item exists before a deletion is performed.
Specifically, do I perform the item exists check on the controller level or within the service layer?
For clarification, I could:
i. have two methods in the service layer - GetItem and DeleteItem and from the controller first call GetItem and if Item exists then call DeleteItem. If Item does not exist, I return an error.
ii. alternatively, I could include the GetItem check within the DeleteItem method in the service layer and return that back up as an error to the controller.
Which of the above is the best place to do this logic check?