F24_PROG1322_02.3_Step 3A - Validation and Database Errors

visibility 0 vues schedule il y a 1 ans timer 48:08
open_in_new Dailymotion
We add IValidatableObject for class level validation. Next we look at our controllers and see how we protect against Cross-Site Request Forgery (CSRF) attacks and Overposting Attacks. Then we explore how to catch errors coming from the database by using try/catch.<br /><br />Performance can be improved by using .AsNoTracking() in our LINQ when we are getting data from the database with no intention of changing the data. Finally we change the approach to the Edit process to follow industry best practice. Instead of just replacing the object in the database, we update it with TryUpdateModel.<br /><br />0:00 Class Level Validaiton - IValidatableObject<br />4:15 Validate Nullable "sometimes" for OHIP<br />9:00 Start new set of Migrations<br />11:45 Controller Improvements<br />12:45 LINQ and .Include() <br />16:45 .AsNoTracking()<br />20:45 ValidateAntiForgeryToken<br />22:10 Overposting Attacks<br />27:20 Database Errors - Try/Catch<br />32:10 Edit Get - .FindAsync()<br />33:20 Edit Post - TryUpdateModelAsync()<br />41:30 Delete - Don't forget to add the Summary in the View!