jbogard / ContosoUniversityCore

MIT License
591 stars 151 forks source link

Course edit database constraint error #13

Closed bobgodfrey closed 7 years ago

bobgodfrey commented 7 years ago

Jimmy,

First off I love your work, really interesting. I have a question and a issue.

The questions - where to you generally put core business validation logic. I am talking about a situation where the model state is valid, but the pending change violates some high-level business rule. (ex an instructor can only be assigned to two classes at a time).

The issue I found is an error if you modify a course and remove the selected department (set the drop down to nothing). When you save course, it passes model validation but it throws and error/ violates a database constraint given the null department . The end result in the sample application is the user is stuck on the course edit page with no error feedback. I know the simple answer would be to validate the model to make sure it has a valid department. What I wanted was some type of centralized valuation. I am assuming that I could add an additional filter and return json errors if appropriate?

Let me know your thoughts

jbogard commented 7 years ago

I actually just blogged about this! What do you think?

On Wed, Apr 19, 2017 at 12:20 PM, bobgodfrey notifications@github.com wrote:

Jimmy,

First off I love your work, really interesting. I have a question and a issue.

The questions - where to you generally put core business validation logic. I am talking about a situation where the model state is valid, but the pending change violates some high-level business rule. (ex an instructor can only be assigned to two classes at a time).

The issue I found is an error if you modify a course and remove the selected department (set the drop down to nothing). When you save course, it passes model validation but it throws and error/ violates a database constraint given the null department . The end result in the sample application is the user is stuck on the course edit page with no error feedback. I know the simple answer would be to validate the model to make sure it has a valid department. What I wanted was some type of centralized valuation. I am assuming that I could add an additional filter and return json errors if appropriate?

Let me know your thoughts

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jbogard/ContosoUniversityCore/issues/13, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGYMipvs3CVInUvjX0IXC1OHSI5QZ4aks5rxkJGgaJpZM4NB_KY .