I'm trying to thin down my Controllers, by using a service layer. But I can not workout or find an example of how to handle issues that arise in the service layer.
As an example, I have a controller action Add Item, which has a name and user defined ID.
The code must be unique in the database.
So my controller simply takes the viewmodel and passes it to ItemService.Add()
Inside of Add is the logic to check if the ID exists. If it doesn't the controller needs to send that information back to the user and get them to change their input.
So how do I send that info back to the controller so the error message is stored and the correct view is displayed?
Is there a standard way of doing this, nearly every example I can find shows how to take the logic from the controller a service, but not how to feed errors / exceptions back in.
What I have tried:
I've tried things using out parameters but that seams very 'hacky'.
And special return codes, but that won't be maintainable as the system grows.