405 First Web Api Service (PhoneType) - chempkovsky/CS82ANGULAR GitHub Wiki
- Modify Directory.Build.props
- Run WebApi Wizard
- First page of the Wizard
- Second page of the Wizard
- Third page of the Wizard
- Fourth page of the Wizard
- Fifth page of the Wizard
- Modify again Directory.Build.props
- 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
Modify Directory.Build.props
-file as follows and save:
<Project>
<PropertyGroup>
<DefineConstants>XXNOTMODELING</DefineConstants>
</PropertyGroup>
</Project>
- To Generate Web Api service
- Run Visual Studio and Open
rupbes.firstapp
solution - Right Click
Phbk
of therupbes.firstapp.Domain.csproj
-project and selectWebApiServices Wizard
menu item to open the Wizard dialog
- Run Visual Studio and Open
Click to show the picture
- 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
- 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 thefirstappDbContext
class using the drop-down lists. ClickNext
-button.
Click to show the picture
- On the third page of the Wizard
-
- select View
-
- choose the props to be used for sorting and filtering
-
- choose WebApi methods to generate
-
- if to
generate localized typescript code
-CheckBox usingAngular i18n
- if to
-
- Route Prefix
-
- choose
1 IRepositoty(Interface)
- choose
-
- Click
Next
-button
Click to show the picture
- On the Fourth page of the Wizard we choose
AbpSimpleRepositoryInterface.Core.cs.t4
T4-template to generate the code. ClickNext
-button.
Click to show the picture
- On the Fifth page of the Wizard click
Save
-button. Close the Wizard.
Click to show the picture
The IPhbkPhoneTypeDtoRepo.cs
will be created in the Phbk
-folder of the rupbes.firstapp.Domain.csproj
-project
Modify Directory.Build.props
-file as follows and save:
<Project>
<PropertyGroup>
<DefineConstants>NOTMODELING</DefineConstants>
</PropertyGroup>
</Project>
- Repeat the steps as for IRepo with the following changes
-
Add
Phbk
-folder in therupbes.firstapp.EntityFrameworkCore.csproj
-project -
Right Click
Phbk
of therupbes.firstapp.EntityFrameworkCore.csproj
-project and selectWebApiServices 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 thePhbk
-folder of therupbes.firstapp.EntityFrameworkCore.csproj
-project
-
Add
DO NOT GENERATE Abp 3 Manager(Class)
class as we do not use it!!!
- Repeat the steps as for IRepo with the following changes
-
Right Click
Phbk
of therupbes.firstapp.Application.Contracts.csproj
-project and selectWebApiServices 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 thePhbk
-folder of therupbes.firstapp.Application.Contracts.csproj
-project
-
Right Click
- Repeat the steps as for IRepo with the following changes
-
Add
Phbk
-folder in therupbes.firstapp.Application.csproj
-project -
Right Click
Phbk
of therupbes.firstapp.Application.csproj
-project and selectWebApiServices 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 thePhbk
-folder of therupbes.firstapp.Application.csproj
-project
-
Add
- 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 therupbes.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 therupbes.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 therupbes.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 therupbes.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 theupdateone
-method to make sure thatChangeVals()
is used
public async Task<PhbkPhoneTypeDto?> updateone(PhbkPhoneTypeDto viewToUpdate) {
...
resultEntity.ChangeVals(
viewToUpdate.PhoneTypeName
, viewToUpdate.PhoneTypeDesc
, viewToUpdate.ConcurrencyStamp
);
...
}
- Open generated
PhbkPhoneTypeDtoService.cs
-file and goto theaddone
-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
);
...
}
- Repeat the steps as for IRepo with the following changes
-
Right Click
Controllers
of therupbes.firstapp.HttpApi.csproj
-project and selectWebApiServices 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 theControllers
-folder of therupbes.firstapp.HttpApi.csproj
-project
-
Right Click
- Open generated
PhbkPhoneTypeDtoWebApiController.cs
-file. It referencesfirstappRemoteServiceConsts
-class. In therupbes.firstapp.Application.Contracts.csproj
-project add thefirstappRemoteServiceConsts
-class
Click to show firstappRemoteServiceConsts.cs
namespace rupbes.firstapp
{
public class firstappRemoteServiceConsts
{
public const string RemoteServiceName = "firstapp";
public const string ModuleName = "firstapp";
}
}