010 First View (PhoneType). Wizard repository. - chempkovsky/CS82ANGULAR GitHub Wiki

Definition

  • View (or ModelView) is the structure that the WebApi service sends to and receives from the client. For each entity, the developer must create at least one view.
  • View (or ModelView) is a Data Transfer Objects (DTO)
  • For a given entity, the View (or ModelView) is a subset of the properties of the given entity and a subset of the properties of the direct and indirect master entities (in terms of the master-detail relationship).
  • From the point of view of Sql constructions, for a given entity (table) View (or ModelView) is an sql View.

Steps required to accomplish the task

Run ModelViews Wizard
  • To Add a View to the project
    • Run Visual Studio and Open “PhonebookSolution” solution
    • Right Click “PhBk” of the “PhBkViews”-project and select “ModelView 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
Click to show the picture

project structure

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 we select Entity for the View. Choose PhBkEntity.csproj and PhbkPhoneType-class and click Next-button
Click to show the picture

project structure

Fourth page of the Wizard

  • On the fourth page of the Wizard we can select existing view to modify or import View-definition from another Repo. Since we have not any Views we just create Next-button.
Click to show the picture

project structure

Fifth page of the Wizard

  • On the fifth page of the Wizard we define subset of properties, we turn on Jenerate JsonProperty Attribute-CheckBox, we Title and Plural Title for the given view. Click Next-button.
Click to show the picture

project structure

Sixth page of the Wizard

  • On the Sixth page of the Wizard we choose ViewModel.cs.t4 T4-template to generate the code. Click Next-button.
Click to show the picture

project structure

Seventh page of the Wizard

  • On the Seventh page of the Wizard click Save-button. Click Next-button.
Click to show the picture

project structure

The PhbkPhoneTypeView.cs will be created in the PhBk-folder of the PhBkViews.csproj-project

Click to show the code
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Linq.Expressions;


namespace PhBkViews.PhBk {
    public class PhbkPhoneTypeView {
        [Required]
        [Display(Description="Row id",Name="Phone Type Id",Prompt="Enter Phone Type Id",ShortName="Phone Type Id")]
        public System.Int32  phoneTypeId { get; set; }

        [Required]
        [StringLength(20,MinimumLength=3,ErrorMessage="Invalid")]
        [Display(Description="Name of the Phone Type",Name="Phone Type Name",Prompt="Enter Phone Type Name",ShortName="Phone Type Name")]
        public System.String  phoneTypeName { get; set; } = null!;

        [Display(Description="Description of the Phone Type",Name="Phone Type Description",Prompt="Enter Phone Type Description",ShortName="Phone Type Description")]
        [StringLength(250,ErrorMessage="Invalid")]
        public System.String ?  phoneTypeDesc { get; set; }

    }
}

Eighth page of the Wizard

  • On the Eighth page of the Wizard choose ViewModelPage.cs.t4-T4-template and click Next-button.
Click to show the picture

project structure

Ninth page of the Wizard

  • On the Ninth page of the Wizard click Save-button and close the wizard.
Click to show the picture

project structure

The PhbkPhoneTypeViewPage.cs will be created in the PhBk-folder of the PhBkViews.csproj-project

Click to show the code
//using System;
//using System.Collections.Generic;
//using System.ComponentModel.DataAnnotations;
//using System.Linq;
//using System.Linq.Expressions;
// using Newtonsoft.Json;
// using Newtonsoft.Json.Serialization;


namespace PhBkViews.PhBk {

    public class PhbkPhoneTypeViewPage {
        public int page { get; set; }
        public int pagesize { get; set; }
        public int pagecount { get; set; }
        public int total { get; set; }
        public List<PhbkPhoneTypeView> items { get; set; } = null!;
    }

}

Repo file

  • After Save-operation in the solution folder the Wizard's repo file will be created(or updated).
  • A separate repo file is created for each DbContext.
  • The repo file is updated only when you click the save button.
Click to show the picture

project structure

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