042 Lookup resource Helper Class for PhbkDivisionView - chempkovsky/CS82ANGULAR GitHub Wiki

Notes

  • Now we need the code, which updates Lookup resource database, i.e. we need the implementation of the Add, Update, Delete methods for the LpdDivision, LprDivision01 and LprDivision02 tables.
    • with 01020-.lookupheper.cs-Wizard's script we generate Lookup resource Helper Class which implements Add, Update, Delete methods.
  • we have two Database contexts: PhbkDbContext and LpPhbkDbContext
    • PhbkDbContext must be used to generate generate Lookup resource Helper Class

Steps required to accomplish the task

Create the Helpers folder to LpPhBkControllers project

  • with Visual Studio add Helpers-folder to LpPhBkControllers project
Click to show the picture

project structure

Run JavasScripts Wizard

  • To generate helper class
    • Run Visual Studio and Open PhonebookSolution solution
    • Right Click Helpers of the LpPhBkControllers-project and select JavasScripts Wizard menu item to open the Wizard dialog
Click to show the picture

project structure

First page of the Wizard

  • On the first page of the dialog the destination folder is shown. The destination folder is the folder in which the generated file will be created. Click Next-button

Second page of the Wizard

On the second page of the Wizard we select DbContext that will be used to choose the entity for the View. Select PhBkContext.csproj and the PhBkContext class using the drop-down lists. Click Next-button.

Click to show the picture

project structure

Third page of the Wizard

  • On the third page of the Wizard
    • select the View for which we need to generate the script
      • in our case we have selected PhbkDivisionView-View
Click to show the picture

project structure

Fourth page of the Wizard

  • On the Fourth page of the Wizard select 01020-.lookupheper.cs-script type and click Next-button
Click to show the picture

project structure

Fifth page of the Wizard

  • On the Fifth page of the Wizard select lookupheper.cs.t4-script and click Next-button
Click to show the picture

project structure

Sixth page of the Wizard

  • On the Sixth page of the Wizard click Save-button. close the Wizard
  • phbk-division-view.lookupheper.cs-file will be created.

Open generated file

Click to show the picture

project structure

  • We need to make modifications of the phbk-division-view.lookupheper.cs-file
Find and replace
  • replace the using PhBkEntity.PhBk;-line with the using LpPhBkEntity.PhBk;

  • replace the using PhBkContext.PhBk;-line with the using LpPhBkContext.PhBk;

  • replace the PhbkDbContext db-code with the code LpPhbkDbContext db in the phbk-division-view.lookupheper.cs-file

  • Note: The Lookup resource Helper and Consumer Classes are the only two classes that need to be modified after generation. We can not use LpPhbkDbContext to generate phbk-division-view.lookupheper.cs-file. Without additional foreign keys, the Wizard will not be able to recognize the group of tables as a lookup resource. To be recognizable as a lookup resource, LprDivision01 and LprDivision02 tables must have a foreign keys, which reference PhbkDivision-table. In addition LprDivision02 must have a foreign key, which references PhbkEnterprise-table... In short, find and replace-approach is optimal.

⚠️ **GitHub.com Fallback** ⚠️