Say I have a database containing Books and Users and these users have certain permissions on books(like editing, deleting, etc.). Now I would write methods like the following and expose this as both an API and WebService.
[WebMethod]
Book GetBook(User login, int id) {
if (!CheckLogin(login))
throw new Exception("Login error");
return new Book(id);
}
This seems all fine, but how would I save this book again when I modified it? It feels right to put a Save()
method on the Book object, since it(the object) should take care of itself. But the permissions checking doesn't feel right there. (I don't want the Book object to know anything about users)
Should I create SaveBook(Book book)
like methods to do this?
Is it anyway a good idea to check this way if some user has some permission? For a WebService I could imagine it's okay, but I have doubts about this being used as normal API(Assembly).