A7 Security: Authorization (ViewModels or DTO classes) (Wpf) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki

  • Before we start run "File explorer" and open the folder
    • %appdata%

picture

  • Then go to "%appdata%\local"

picture

  • At the end open the folder "%appdata%\Local\Microsoft\VisualStudio\XXX\Extensions\YYY", where "XXX" and "YYY" are the names that were defined during the CS2WPF installation and may differ from those shown in the figure below. This is the folder where CS2WPF was installed.

  • navigate to subfolder

    • %appdata\Local\Microsoft\VisualStudio\16.0_5e517fbc\Extensions\4kzuptvv.hsg\Templates\ContextsToImport%
      • "16.0_5e517fbc" and "4kzuptvv.hsg" folders were generated dynamically at installation time. So in your case these will be other names.

picture

  • copy "aspnetchckdbcontext.json" file in a temporary place where it will be easy to open with "Open File"-Dialog
    • Suppose, it'll be "C:\Development"-folder
      • So, new file name with a path will be "C:\Development\aspnetchckdbcontext.json"
      • This file will be used in the next steps

Note: The creation order of Views is important. Master entities first:

  1. aspnetdashboard
  2. aspnetmodel
  3. aspnetrole [dummy(mock) class]
  4. aspnetuser [dummy(mock) class]
  5. aspnetrolemask
  6. aspnetusermask [dummy(mock) class]
  7. aspnetuserroles [dummy(mock) class]
  • Step 1: Right click "AspNetMaskSecurity"-folder of Dm03Views-project and select "ViewModelViews Wizard".
  • Step 2: On the first page (invitation page) click "next"-button.
  • Step 3: On the second page, select "DbContextClassLibrary"-project and "aspnetchckdbcontext"-Dbccontext and click next.

picture

  • Step 4: On the third page, select "DbEntitiesClassLibrary"-project and "aspnetdashboard"-entity and click "Next"-button

picture

  • Step 5: On the fifth page, click "Import"-button. "File open" dialog will be shown. Select the "aspnetchckdbcontext.json". How to find aspnetchckdbcontext.json-file was described above in this article.

picture

  • Step 6: On the same fifth page, select "aspnetdashboardView", check "Select View" and click "Next"-button.

picture

  • Step 7: On the sixth page, expand "Properties"-node to make sure that all setting are the same as it is shown below. Click "next"-button.

picture

  • Step 8: On the seventh page, select "ViewModel.cs.t4"-script and click "Next"-button.

picture

  • Step 8: On the eighth page, click "Save"-button and then click "Next"-button.
  • Step 9: On the nineth page, select "ViewModelPage.cs.t4"-script and click "Next"-button.

picture

  • Step 10: On the tenth page, click "Save"-button. Two new files have been created for the DbModelsClassLibrary-project. DO NOT CLOSE THE WIZARD. Click "Next"-button.
  • Step 11: We are on the third page again. select "DbEntitiesClassLibrary"-project and "aspnetmodel"-entity and click "Next"-button.
  • Step 12: Repeat steps 5-11 for the "aspnetmodel"-entity. Two new files have been created for the DbModelsClassLibrary-project. DO NOT CLOSE THE WIZARD. Click "Next"-button.
  • Step 13: We are on the third page again. select "DbEntitiesClassLibrary"-project and "aspnetrole"-entity and click "Next"-button.
  • Step 14: Repeat steps 5-11 for the "aspnetrole"-entity. Two new files have been created for the DbModelsClassLibrary-project. DO NOT CLOSE THE WIZARD. Click "Next"-button.
  • Step 15: We are on the third page again. select "DbEntitiesClassLibrary"-project and "aspnetuser"-entity and click "Next"-button.
  • Step 16: Repeat steps 5-11 for the "aspnetuser"-entity. Two new files have been created for the DbModelsClassLibrary-project. DO NOT CLOSE THE WIZARD. Click "Next"-button.
  • Step 17: We are on the third page again. select "DbEntitiesClassLibrary"-project and "aspnetrolemask"-entity and click "Next"-button.
  • Step 18: Repeat steps 5-11 for the "aspnetrolemask"-entity. Two new files have been created for the DbModelsClassLibrary-project. DO NOT CLOSE THE WIZARD. Click "Next"-button.
  • Step 19: We are on the third page again. select "DbEntitiesClassLibrary"-project and "aspnetusermask"-entity and click "Next"-button.
  • Step 20: Repeat steps 5-11 for the "aspnetusermask"-entity. Two new files have been created for the DbModelsClassLibrary-project. DO NOT CLOSE THE WIZARD. Click "Next"-button.
  • Step 21: We are on the third page again. select "DbEntitiesClassLibrary"-project and "aspnetuserroles"-entity and click "Next"-button.
  • Step 22: Repeat steps 5-11 for the "aspnetuserroles"-entity. Two new files have been created for the DbModelsClassLibrary-project. CLOSE THE WIZARD.

Close ModelViews Wizard

Delete dummy classes and generate product version of aspnetchckdbcontext

  • Delete dummy(mock) classes of Dm01Entity.csproj project

    • aspnetrole.cs [dummy(mock) class]
    • aspnetuser.cs [dummy(mock) class]
    • aspnetuserroles.cs [dummy(mock) class]
    • aspnetusermask.cs [dummy(mock) class]
  • Regenerate aspnetchckdbcontext.cs class of Dm02Context.csproj project

    • follow the same steps described by "A6 Security: Authorization"-article
    • use "AspNetDbContextProd.json"-script instead of "AspNetDbContextDev.json"-script