Тёмный

User Permissions and Error Handling - A TimCo Retail Manager Video 

IAmTimCorey
Подписаться 416 тыс.
Просмотров 10 тыс.
50% 1

In this video, we are going to be handling what happens when a user does not have the permissions necessary to perform a task. We will end up creating a custom dialog box that works with MVVM. Note that there is also an announcement about the upcoming .NET Core conversion.
** TimCo source code now at: www.iamtimcorey.com/courses/b...
Full Courses: www.iamtimcorey.com
Mailing List: signup.iamtimcorey.com/
One-off tutorials are awesome but they aren't the only thing you should be doing to learn C#. Another vital part of learning is learning how to put it all together. This interactive course is all about putting the pieces together. You can watch each video on its own or you can watch them in order and see a bigger picture. The choice is yours.
This course focuses on real-world development. As such, we are simulating that we work for TimCo Enterprise Solutions on a brand new product, the TimCo Retail Manager. Just like in the real world, we are starting out with one set of requirements but know that over time they will change.

Опубликовано:

 

22 сен 2019

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 52   
@Ivolution091
@Ivolution091 3 года назад
Hello! At 21:27 - using this approach creates strong coupling. Instead, you can add dependency in the constructor, like "Func statusInfoViewModelFunc", save statusInfoViewModelFunc in a readonly field (e.g. _statusInfoViewModelFunc) and call the _statusInfoViewModelFunc.Invoke() when you need to create an instance. Factory function injection is well documented in the Stylet documentation. I learned about Stylet from your other video. Thanks a lot for the great content!
@benthornhill9106
@benthornhill9106 3 года назад
Awesome video as always Tim!
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks!
@stinefelt
@stinefelt 3 года назад
Really enjoyed how the Dialog Box is created and utilized.
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks
@rc2893
@rc2893 4 года назад
If you want visual studio to create the private fields with the leading underscore as shown in the videos. Here is a link that describes how to configure it in VS. stackoverflow.com/questions/45736659/how-do-i-customize-visual-studios-private-field-generation-shortcut-for-constru
@rlyonsiii
@rlyonsiii 4 года назад
Hi Tim, nice video as usual... I wanted to point out that at 23:08 in the video you can remove the _window.ShowDialog call from the if/else and move right before the TryClose() so its not repeated. Keep up the good work.
@IAmTimCorey
@IAmTimCorey 4 года назад
True. Good catch.
@hchoi84
@hchoi84 3 года назад
For anyone interested: 19:26 Documentation docs.microsoft.com/en-us/dotnet/api/system.windows.window?view=netcore-3.1 CTRL + F "Appearance and Behavior"
@SuperDre74
@SuperDre74 4 года назад
Another great video, and a good way to use Messagebox from MVVM.. Personally I wouldn't even want the user to see the salespage if they don't have the permission, so maybe it would be possible to hide it before showing the messagebox.
@IAmTimCorey
@IAmTimCorey 4 года назад
Yep, that is possible.
@mjaguilar923
@mjaguilar923 4 года назад
Thank you
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@objectaware5296
@objectaware5296 4 года назад
I would create an Authorize attribute an implement the HandleUnautorizedRequest. Doing so allows you to handle all such unauthorized requests from a single point.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thanks for the suggestion.
@roycelithgo3968
@roycelithgo3968 4 года назад
Great to see an example of a modal message box implemented in MVVM! Personally I'm not a huge fan of partially initialized screens showing messages at startup and then getting kicked out. What's the harm in putting the TryClose() before the call to ShowDialog()? It actually works and you only briefly see the Sales form doing it this way (but the modal dialog remains). eg. TryClose(); if(ex.Message == "Unauthorized") { _status.UpdateMessage("Unauthorized Access", "You do not have permission to interact with the Sales Form."); } else { _status.UpdateMessage("Fatal Exception", ex.Message); } _window.ShowDialog(_status, null, settings);
@IAmTimCorey
@IAmTimCorey 4 года назад
Putting the TryClose before the messagebox is hacky. It isn't guaranteed to work, even though it does sometimes. Ideally, we shouldn't even arrive at this page. We should be putting security rules in place to stop a link from being active if the user doesn't have permission to navigate to the given page. This check is just in place so that if they got to it anyway, they could not do anything. I prefer to add the logic in this order because then we know that the fallback works before we add in another layer.
@karlism.5604
@karlism.5604 Год назад
I had an issue debugger was not allowing try/catch to handle the error and it was breaking earlier. What helped is restoring list in Exception Settings to the default. Debug > Windows > Exception Settings > Restore the list to the default settings
@IAmTimCorey
@IAmTimCorey Год назад
Interesting. Thanks for sharing.
@bwatson4000
@bwatson4000 Год назад
Thank you, same problem here - appreciate it!
@mov4736
@mov4736 3 года назад
Why didn't we just do an event and listen to it in the shellviewmodel? I thought that the shellviewmodel is responsible for overall view stuff and juggling viewmodels around (being the conductor and all)
@hamidrezaashkiyan
@hamidrezaashkiyan 4 года назад
Hi and thanks a lot Mr.Corey Please add azure devops CI/CD to project i love to learn how to add pipeline and CI/CD to project but i can't find really good tutorial like yours.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thanks for the suggestion.
@infinite_monkey590
@infinite_monkey590 2 года назад
Yes, the standard MessageBox breaks the MVVM principle. But since you're using settings, window size etc. here, doesn't that break MVVM just as much? Another thing: isn't the IoC.Get a Service Locator, which is considered an antipattern?
@vprushak
@vprushak 4 года назад
HI Tim, I've just began watching you and have a question (maybe someone asked before) - what're your comp specs?
@IAmTimCorey
@IAmTimCorey 4 года назад
Custom computer - Intel i7 with 32GB of RAM and a 512GB M.2 SSD.
@yasinalpay6496
@yasinalpay6496 4 года назад
In the SalesViewModel, you didnt mark the private fields as private before, but in this video you added two more fields which are private and readonly. To be consistent, you should have marked the previous fields as private as well?
@IAmTimCorey
@IAmTimCorey 4 года назад
Yep, I just forgot to set it.
@andywalter7426
@andywalter7426 4 года назад
I saw the part of the video about not having messageboxes in view models. I actually found a mvvm friendly way to do messageboxes. I used it and it worked great. What I did was create an interface with a method called messagebox. Then wpf can implement it. I used it for xamarin forms and wpf and it worked great. the view model does not know how the messagebox will be displayed but whoever implements it can do what it wants to display a message box. What do you think of that idea? I used that in my mvvm framework and it still seemed to work great and the view models are actually in the .net standard library too with no reference to xamarin forms or any wpf stuff.
@IAmTimCorey
@IAmTimCorey 4 года назад
Interesting idea.
@bluescanfly1981
@bluescanfly1981 4 года назад
Nice use of Dependency Inversion from SoliD principles (Higher level code does not depend on lower level details)
@TehDarkWolf
@TehDarkWolf 4 года назад
.NET Core 3 releases today, will you be doing any videos related to it?
@hqcart1
@hqcart1 4 года назад
It's candidate release. Not final.
@TehDarkWolf
@TehDarkWolf 4 года назад
It releases during .NET Conf which is in a couple of hours
@IAmTimCorey
@IAmTimCorey 4 года назад
The video next week will be on something that was released with .NET Core 3.0. I will definitely be doing more videos using it and the new things in it.
@hqcart1
@hqcart1 4 года назад
@@IAmTimCorey i would love if you talk about the advantage disadvantage of blazer and jquery. thanks!
@villesipola
@villesipola 4 года назад
Hi again Tim! This video got me thinking: could project like this benefit and to be more future-proof if this sort of error checking would be done in the API layer? This could come in handy if one or more client applications gets added later to the project, so there's no need to build the error checking from ground-up in every front end client separately. This might require some sort of "shared connection class" using generics between API and all of the client applications which would then be used to transmit information about if there was some error in processing client calls in API and of course contain the actual objects handled by the calls. If there is need for language variants in client applications UI , the database could hold information about user preferred UI language and thus the error messages could be returned accordingly. This increases the data transmitted via the wire and server resource usage but i think it would greatly simplify the unification of different client applications. Thoughts about this? I realize these videos have been done for some time ago now and there's probably no chance for impacting the route of development in this project anymore by commenting, but i guess my comments (which i've been sending in a few lately) are more of a "would this be smart to do or are there some major draw-backs if i do it like this" type of questions. Any thoughts would be highly appreciated. I've been coding for 1,5 years now with C# (self / youtube taught :D) with just moderate previous experience with VBA programming in MS Excel. In front-end side i am most familiar with WPF since the project i've been mostly working with in these past 1,5 years is WPF project. Must say that i really like C# and the frameworks that MS provides. Really looking forward to getting into .Net Core and especially .Net 5.0. The .Net Stack really feels like i jumped to the right train considering all the effort MS is putting to all of the modern solutions like Blazor, Xamarin and the .Net 5 a whole not to mention Visual Studio. I'm currently trying to get familiar with .Net web based technologies in front and back-end so these videos of yours are truly invaluable for me! As always, got really inspired by your great tutorials! Keep 'em coming! br. Ville
@IAmTimCorey
@IAmTimCorey 4 года назад
Yes, you can do error checking on the API side and have it done once for all. However, you still want to do error checking on the client so that you aren't sending data to the server, getting it rejected, then updating the display. You want more real-time error checking as well.
@piotrc966
@piotrc966 4 года назад
Maby after serve 'unauthirozed ex' put line like this ((IConductor)this.Parent).ActivateItem(IoC.Get()); to not live empty form, but come back to login in this case.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thanks for the suggestion.
@orlanino
@orlanino 2 года назад
Tim, I am doing this video 3 years late with the new version of Caliburn.Micro and many calls are now Async. Can you maybe address this in one of your videos, please?
@IAmTimCorey
@IAmTimCorey 2 года назад
We address it in this video when we upgrade. That’s part of the goal with this app.
@CoderboyPB
@CoderboyPB 3 года назад
Hi Team, what's the difference between IoC.Get() and new StatusInfoViewModel(); Didn't get it yet ... For me, both do the same. Where am I wrong?
@IAmTimCorey
@IAmTimCorey 3 года назад
We want to allow the dependency injection system to create all of the instances. This allows us to put all of the creation logic in one place. Ideally, we would also ask for an interface instead of a strong type like we did here so that we could replace the implementation with a different view model if we wanted. That would break the dependency on the specific ViewModel.
@CoderboyPB
@CoderboyPB 3 года назад
@@IAmTimCorey Gotcha! Got it! Thanx :-)
@cesaritomartinez
@cesaritomartinez 4 года назад
Hello Tim! Great tutorials! I've followed this one from the beginnig and it has worked all the time - except from now. When i try: _window.ShowDialog(_status, null, null); in SalesViewModel, it fails with the exception: Exception User-Unhandled System.InvalidOperationException: 'The calling thread must be STA, because many UI components require this' This exception was originally thrown at this call stack: [External Code] TRMDesktopUI.Views.StatusInfoView.StatusInfoView() in StatusInfoView.xaml.cs and jumps to StatusInfoView.xaml.cs and marks the public StatusInfoView() I copied your code and everything work but this. Any idea of why? Can't find any solution online.
@IAmTimCorey
@IAmTimCorey 4 года назад
Not sure why you are receiving this issue. I don't remember triggering this on a different thread, but that is what it sounds like is happening.
@cesaritomartinez
@cesaritomartinez 4 года назад
After a good night's sleep it started to work without doing any changes! Strange!
@heartbreakkid8966
@heartbreakkid8966 4 года назад
still waiting for next 2 videos
@IAmTimCorey
@IAmTimCorey 4 года назад
New videos in this series come out about every other week.
Далее
Managing User Roles - A TimCo Retail Manager Video
1:12:42
Этот Пёс Кое-Что Наделал 😳
00:31
Cool Tech You’ll LOVE!
21:41
Просмотров 72 тыс.
Brutally honest advice for new .NET Web Developers
7:19
Programming Is NOT Enough | Add these 7 skills…
13:19