B6 Security: Authorization. Obtaining list of ModelViews and Features for the given DBContext (Wpf, Xamarin) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki

On the last slides of 'B3' article all tabular forms were empty. Of course, it's possible to enter data with lform components of dashboardView and modelView. But it's time consuming and it's easy to mistype if the list of modelViews is long enough. On the other hand, this task can be easily automated. We need the data in two forms: one form will be used to modify AppGlblSettingsService.Views and AppGlblSettingsService.Dashboards and another form is for SQL insert commands.

Open "AppGlblSettingsSrvc\AppGlblSettingsService.cs"-file of "CommonServicesPrismModule"-prooject. By default, AppGlblSettingsService.Views and AppGlblSettingsService.Dashboards are defined by abstract samples. At the end, we will fill in the correct data.

        Dictionary<string, int> Views = new Dictionary<string, int>()
        {
            { "LitAuthorView", 0 },
            { "LitBookView", 1 },
        };
        Dictionary<string, int> Dashboards = new Dictionary<string, int>()
        {
            { "ManuscriptDFeatureFtrComponent", 0 },
            { "ManuscriptRFeatureFtrComponent", 1 },
        };

Instructions:

  • Right click root-node of any project. For instance, "ModelServicesPrismModule"
  • open FeatureScripts Wizard

picture

  • on the first page
    • click Next-button

picture

  • on the second page
    • select LitDbContext
    • click Next-button

picture

  • on the third page
    • select any feature that was created before. For instance, 'ManuscriptRfeature'
    • click Next-button

picture

  • on the fourth page
    • select 30180-AllModelViews.sql
    • click Next-button

picture

  • on the fifth page
    • select AllModelViews.sql.t4

picture

  • on the fifth page

    • modify the value for startFromId-variable
      • For very first DbContext of the project startFromId must be equal to 0
      • Suppose, for very first DbContext the last generated ID will be equal to N
      • Then for the next DbContext the value for startFromId must be equal to N + 1
  • on the fifth page

    • click Next-button
  • on the sixth page

    • DO NOT click Save-button. Just copy generated code into the clipboard
  • The generated SQL code consists of two fragments

    • we only need inserts into '[dbo].[aspnetmodels]'

picture

  • Execute generated SQL code against Database

picture

  • on the sixth page
    • click Next-button
  • you are on the third page again
    • click Next-button
  • on the fourth page
    • select 30185-AllModelViews.cs
    • click Next-button
  • on the fifth page
    • select AllModelViews.cs.t4
    • Pay special attention to the magnitude of the variable: int currentId= 0;
    • Apply the same rules as mentioned above
  • on the sixth page
    • DO NOT click Save-button. Just copy generated code into the clipboard

picture

  • open CommonServicesPrismModule\AppGlblSettingsSrvc\AppGlblSettingsService.cs-file
  • modify definition of the AppGlblSettingsService.Views-variable
        Dictionary<string, int> Views = new Dictionary<string, int>()
        {
             {"LitGenreView", 0 },
             {"LitEditionView", 1 },
             {"LitCountryView", 2 },
             {"LitLanguageView", 3 },
             {"LitDialectView", 4 },
             {"LitPublisherView", 5 },
             {"LitAuthorView", 6 },
             {"LitManuscriptView", 7 },
             {"LitBookView", 8 },
        };
  • on the sixth page
    • click Next-button
  • you are on the third page again
    • click Next-button
  • on the fourth page
    • select 30190-AllDashBoards.sql
    • click Next-button
  • on the fifth page
    • select AllDashBoards.sql.t4
    • Pay special attention to the magnitude of the variable: int startFromId= 0;
    • Apply the same rules as mentioned above
  • on the fifth page
    • click Next-button
  • on the sixth page
    • DO NOT click Save-button. Just copy generated code into the clipboard
  • The generated SQL code consists of two fragments
    • we only need inserts into [dbo].[aspnetdashboards]
  • Execute generated SQL code against Database

picture

  • on the sixth page
    • click Next-button
  • you are on the third page again
    • click Next-button
  • on the fourth page
    • select 30195-AllDashBoards.cs
    • click Next-button
  • on the fifth page
    • select AllDashBoards.cs.t4
    • Pay special attention to the magnitude of the variable: int currentId= 0;
    • Apply the same rules as mentioned above
  • on the fifth page
    • click Next-button
  • on the sixth page
    • DO NOT click Save-button. Just copy generated code into the clipboard

picture

  • open CommonServicesPrismModule\AppGlblSettingsSrvc\AppGlblSettingsService.cs-file
  • modify definition of the AppGlblSettingsService.Dashboards-variable
        Dictionary<string, int> Dashboards = new Dictionary<string, int>()
        {
            {"ManuscriptRFeatureFtrUserControl", 0},
        };

Repeat all the steps for aspnetchckdbcontext-DBContext.

Do not forget to define correct values for currentId and startFromId vars before generating the code.

Here is a result Wpf:

        Dictionary<string, int> Views = new Dictionary<string, int>()
        {
             {"LitGenreView", 0 },
             {"LitEditionView", 1 },
             {"LitCountryView", 2 },
             {"LitLanguageView", 3 },
             {"LitDialectView", 4 },
             {"LitPublisherView", 5 },
             {"LitAuthorView", 6 },
             {"LitManuscriptView", 7 },
             {"LitBookView", 8 },
             {"aspnetdashboardView", 9 },
             {"aspnetmodelView", 10 },
             {"aspnetroleView", 11 },
             {"aspnetrolemaskView", 12 },
             {"aspnetuserView", 13 },
             {"aspnetusermaskView", 14 },
             {"aspnetuserrolesView", 15 },
        };
        Dictionary<string, int> Dashboards = new Dictionary<string, int>()
        {
            {"ManuscriptRFeatureFtrUserControl", 0},
            {"AdminUsersFtrUserControl", 1},
            {"AdminRolesFtrUserControl", 2},
        };

Here is a result Xamarin:

        Dictionary<string, int> Views = new Dictionary<string, int>()
        {
             {"LitGenreView", 0 },
             {"LitEditionView", 1 },
             {"LitCountryView", 2 },
             {"LitLanguageView", 3 },
             {"LitDialectView", 4 },
             {"LitPublisherView", 5 },
             {"LitAuthorView", 6 },
             {"LitManuscriptView", 7 },
             {"LitBookView", 8 },
             {"aspnetdashboardView", 9 },
             {"aspnetmodelView", 10 },
             {"aspnetroleView", 11 },
             {"aspnetuserView", 12 },
             {"aspnetrolemaskView", 13 },
             {"aspnetusermaskView", 14 },
             {"aspnetuserrolesView", 15 },
        };
        Dictionary<string, int> Dashboards = new Dictionary<string, int>()
        {
            {"Ftr01FtrUserControl", 0},
            {"Ftr2FtrUserControl", 1},
            {"AdminRolesFtrUserControl", 2},
            {"AdminUsersFtrUserControl", 3},
        };

Server side Wpf:

picture

and

picture

Server side Xamarin:

picture

and

picture