405 First Web Api Service (PhoneType) - chempkovsky/CS82ANGULAR GitHub Wiki

Requirements

  • Before generating WebApi service the developer must define the set of View’s properties that
    • will be used for filtering
  • and the set of View’s properties that
    • will be used for sorting.
  • choose which Webapi methods to generate (Add/Update/Delete/Select One/Select many) for the given view

Steps required to accomplish the task

IRepo

Modify Directory.Build.props

Modify Directory.Build.props-file as follows and save:

<Project>
    <PropertyGroup>
        <DefineConstants>XXNOTMODELING</DefineConstants>
    </PropertyGroup>
</Project>
Run WebApi Wizard
  • To Generate Web Api service
    • Run Visual Studio and Open rupbes.firstapp solution
    • Right Click Phbk of the rupbes.firstapp.Domain.csproj-project and select WebApiServices 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 rupbes.firstapp.EntityFrameworkCore.csproj and the firstappDbContext 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
      1. select View
      1. choose the props to be used for sorting and filtering
      1. choose WebApi methods to generate
      1. if to generate localized typescript code-CheckBox using Angular i18n
      1. Route Prefix
      1. choose 1 IRepositoty(Interface)
  • Click Next-button
Click to show the picture

project structure

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

project structure

Fifth page of the Wizard
  • On the Fifth page of the Wizard click Save-button. Close the Wizard.
Click to show the picture

project structure

The IPhbkPhoneTypeDtoRepo.cs will be created in the Phbk-folder of the rupbes.firstapp.Domain.csproj-project

Modify again Directory.Build.props

Modify Directory.Build.props-file as follows and save:

<Project>
    <PropertyGroup>
        <DefineConstants>NOTMODELING</DefineConstants>
    </PropertyGroup>
</Project>

Repo

  • Repeat the steps as for IRepo with the following changes
    • Add Phbk-folder in the rupbes.firstapp.EntityFrameworkCore.csproj-project
    • Right Click Phbk of the rupbes.firstapp.EntityFrameworkCore.csproj-project and select WebApiServices Wizard menu item to open the Wizard dialog
    • On the third page of the Wizard choose 2 Repositoty(Class)
    • On the fourth page of the Wizard we choose AbpSimpleRepositoryClass.Core.cs.t4 T4-template to generate the code. Click Next-button.
    • At the end: the PhbkPhoneTypeDtoRepo.cs-file will be created in the Phbk-folder of the rupbes.firstapp.EntityFrameworkCore.csproj-project

Manager

DO NOT GENERATE Abp 3 Manager(Class) class as we do not use it!!!

IAbpService

  • Repeat the steps as for IRepo with the following changes
    • Right Click Phbk of the rupbes.firstapp.Application.Contracts.csproj-project and select WebApiServices Wizard menu item to open the Wizard dialog
    • On the third page of the Wizard choose 4 IAppService(Interface)
    • On the fourth page of the Wizard we choose AbpAppServiceInterface.Core.cs.t4 T4-template to generate the code. Click Next-button.
    • At the end: the IPhbkPhoneTypeDtoService.cs-file will be created in the Phbk-folder of the rupbes.firstapp.Application.Contracts.csproj-project

AbpService

  • Repeat the steps as for IRepo with the following changes
    • Add Phbk-folder in the rupbes.firstapp.Application.csproj-project
    • Right Click Phbk of the rupbes.firstapp.Application.csproj-project and select WebApiServices Wizard menu item to open the Wizard dialog
    • On the third page of the Wizard choose 5 AppService(Class)
    • On the fourth page of the Wizard we choose AbpAppServiceClass.Core.cs.t4 T4-template to generate the code. Click Next-button.
    • At the end: the PhbkPhoneTypeDtoService.cs-file will be created in the Phbk-folder of the rupbes.firstapp.Application.csproj-project
  • Open generated PhbkPhoneTypeDtoService.cs-file and follow the instructions at the beginning ogf the file
Click to show the instructions
/*
  // == 1 ==
  // modify "firstappPermissions"-class like seen

  public class firstappPermissions
  {

    ...

    public static class PhbkPhoneTypeDto
    {
        
        public const string Default = GroupName + ".PhbkPhoneTypeDto";
        public const string FullScan = Default + ".f";
        public const string Create = Default + ".a";
        public const string Edit = Default + ".u";
        public const string Delete = Default + ".d";
    }

    ...

  }

  // == 2 ==
  // modify "firstappPermissionDefinitionProvider"-class like seen

    public class firstappPermissionDefinitionProvider : PermissionDefinitionProvider
    {
        ...
        public override void Define(IPermissionDefinitionContext context)
        {
            var mdlGrp = context.AddGroup(firstappPermissions.GroupName, L("Psn:firstapp"));

            var perm = mdlGrp.AddPermission(firstappPermissions.PhbkPhoneTypeDto.Default, L("Psn:PhbkPhoneTypeDto"));
            perm.AddChild(firstappPermissions.PhbkPhoneTypeDto.FullScan, L("Psn:PhbkPhoneTypeDto.f"));
            perm.AddChild(firstappPermissions.PhbkPhoneTypeDto.Create, L("Psn:PhbkPhoneTypeDto.a"));
            perm.AddChild(firstappPermissions.PhbkPhoneTypeDto.Edit, L("Psn:PhbkPhoneTypeDto.u"));
            perm.AddChild(firstappPermissions.PhbkPhoneTypeDto.Delete, L("Psn:PhbkPhoneTypeDto.d"));
        }

        ...
    }




*/
  • open Permissions\firstappPermissions.cs of the rupbes.firstapp.Application.Contracts.csproj-project and modify as follows
Click to show firstappPermissions.cs
namespace rupbes.firstapp.Permissions;

public static class firstappPermissions
{
    public const string GroupName = "firstapp";



    //Add your own permission names. Example:
    //public const string MyPermission1 = GroupName + ".MyPermission1";
    public static class PhbkPhoneTypeDto
    {

        public const string Default = GroupName + ".PhbkPhoneTypeDto";
        public const string FullScan = Default + ".f";
        public const string Create = Default + ".a";
        public const string Edit = Default + ".u";
        public const string Delete = Default + ".d";
    }

}
  • open Permissions\firstappPermissionDefinitionProvider.cs of the rupbes.firstapp.Application.Contracts.csproj-project and modify as follows
Click to show firstappPermissionDefinitionProvider.cs
using rupbes.firstapp.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Localization;
using Volo.Abp.MultiTenancy;

namespace rupbes.firstapp.Permissions;

public class firstappPermissionDefinitionProvider : PermissionDefinitionProvider
{
    public override void Define(IPermissionDefinitionContext context)
    {
        //var myGroup = context.AddGroup(firstappPermissions.GroupName);

        //Define your own permissions here. Example:
        //myGroup.AddPermission(firstappPermissions.MyPermission1, L("Permission:MyPermission1"));
        var mdlGrp = context.AddGroup(firstappPermissions.GroupName, L("Psn:firstapp"));

        var perm = mdlGrp.AddPermission(firstappPermissions.PhbkPhoneTypeDto.Default, L("Psn:PhbkPhoneTypeDto"));
        perm.AddChild(firstappPermissions.PhbkPhoneTypeDto.FullScan, L("Psn:PhbkPhoneTypeDto.f"));
        perm.AddChild(firstappPermissions.PhbkPhoneTypeDto.Create, L("Psn:PhbkPhoneTypeDto.a"));
        perm.AddChild(firstappPermissions.PhbkPhoneTypeDto.Edit, L("Psn:PhbkPhoneTypeDto.u"));
        perm.AddChild(firstappPermissions.PhbkPhoneTypeDto.Delete, L("Psn:PhbkPhoneTypeDto.d"));
    }

    private static LocalizableString L(string name)
    {
        return LocalizableString.Create<firstappResource>(name);
    }
}
  • open Localization\firstapp\en.json of the rupbes.firstapp.Domain.Shared.csproj-project and modify as follows
Click to show en.json
{
  "Culture": "en",
  "Texts": {
    "AppName": "firstapp",
    "Menu:Home": "Home",
    "LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information visit",
    "Welcome": "Welcome",

    "Psn:firstapp": "first app",

    "Psn:PhbkPhoneTypeDto": "Phone type",
    "Psn:PhbkPhoneTypeDto.f": "Any filter",
    "Psn:PhbkPhoneTypeDto.a": "Add",
    "Psn:PhbkPhoneTypeDto.u": "Update",
    "Psn:PhbkPhoneTypeDto.d": "Delete"


  }
}
  • open Localization\firstapp\ru.json of the rupbes.firstapp.Domain.Shared.csproj-project and modify as follows
Click to show ru.json
{
  "culture": "ru",
  "texts": {
    "AppName": "firstapp",
    "Menu:Home": "Дома",
    "Menu:ContactUs": "Связаться с нами",
    "Menu:ArticleSample": "Образец статьи",
    "Home": "Дома",
    "Welcome": "Добро пожаловать",
    "LongWelcomeMessage": "Добро пожаловать в приложение. Это стартап-проект, основанный на структуре ABP. Для получения дополнительной информации посетите сайт",
    "Date": "датировать",
    "Permission:Dashboard": "Панель приборов",
    "Menu:Dashboard": "Панель приборов",
    "Menu:HomePage": "Домашняя страница",
    "Dashboard": "Панель приборов",
    "ExternalProvider:Google": "Google",
    "ExternalProvider:Google:ClientId": "ID клиента",
    "ExternalProvider:Google:ClientSecret": "Секрет клиента",
    "ExternalProvider:Microsoft": "Майкрософт",
    "ExternalProvider:Microsoft:ClientId": "ID клиента",
    "ExternalProvider:Microsoft:ClientSecret": "Секрет клиента",
    "ExternalProvider:Twitter": "Твиттер",
    "ExternalProvider:Twitter:ConsumerKey": "Потребительский ключ",
    "ExternalProvider:Twitter:ConsumerSecret": "Потребительский секрет",
    "NewsletterHeader": "Подпишитесь на рассылку!",
    "NewsletterInfo": "Получайте информацию о последних событиях.",
    "NewsletterPreference_Default": "Информационный бюллетень по умолчанию",
    "NewsletterPrivacyAcceptMessage": "Я принимаю <a href='/privacy-policy'>Политику конфиденциальности</a>.",
    "Language": "Язык",
    "Search": "Поиск",
    "LoadMore": "Загрузи больше",
    "Settings": "Настройки",
    "Theme": "Тема",
    "DeviceTheme": "Тема устройства",
    "Dark": "Темный",
    "Light": "Свет",
    "Unspecified": "Система",
    "SeeAllUsers": "Просмотреть всех пользователей",
    "TakePhoto": "Сделать фотографию",
    "ChoosePhoto": "Выбрать фото"



    "Psn:firstapp": "Первое приложение",

    "Psn:PhbkPhoneTypeDto": "Тип телефона",
    "Psn:PhbkPhoneTypeDto.f": "Любой фильтр",
    "Psn:PhbkPhoneTypeDto.a": "Добавить",
    "Psn:PhbkPhoneTypeDto.u": "Изменить",
    "Psn:PhbkPhoneTypeDto.d": "Удалить"

  }
}
  • in the rupbes.firstapp.Application.csproj-project add references on to LinqKit.Core-nuget package (https://github.com/scottksmith95/LINQKit)
  • Open generated PhbkPhoneTypeDtoService.cs-file goto the updateone-method to make sure that ChangeVals() is used
        public async Task<PhbkPhoneTypeDto?> updateone(PhbkPhoneTypeDto viewToUpdate) {
...
                resultEntity.ChangeVals( 
                        viewToUpdate.PhoneTypeName
                         ,  viewToUpdate.PhoneTypeDesc
                         ,  viewToUpdate.ConcurrencyStamp
    
                     
                );
...

        }
  • Open generated PhbkPhoneTypeDtoService.cs-file and goto the addone-method to make sure that non empty constructor is used
        public async Task<PhbkPhoneTypeDto> addone(PhbkPhoneTypeDto viewToAdd) {
...

                PhbkPhoneType entityToAdd = new PhbkPhoneType(
                        viewToAdd.Id
                         ,  viewToAdd.PhoneTypeName
                         ,  viewToAdd.PhoneTypeDesc
                );
...
        }

AbpController

  • Repeat the steps as for IRepo with the following changes
    • Right Click Controllers of the rupbes.firstapp.HttpApi.csproj-project and select WebApiServices Wizard menu item to open the Wizard dialog
    • On the third page of the Wizard choose 6 WebApi(Class)
    • On the fourth page of the Wizard we choose AbpWebApiService.Core.cs.t4 T4-template to generate the code. Click Next-button.
    • At the end: the PhbkPhoneTypeDtoWebApiController.cs-file will be created in the Controllers-folder of the rupbes.firstapp.HttpApi.csproj-project
  • Open generated PhbkPhoneTypeDtoWebApiController.cs-file. It references firstappRemoteServiceConsts-class. In the rupbes.firstapp.Application.Contracts.csproj-project add the firstappRemoteServiceConsts-class
Click to show firstappRemoteServiceConsts.cs
namespace rupbes.firstapp
{
    public class firstappRemoteServiceConsts
    {
        public const string RemoteServiceName = "firstapp";

        public const string ModuleName = "firstapp";
    }
}
⚠️ **GitHub.com Fallback** ⚠️