Creating a New Person
Next step is to create a modal to add a new item to phone book.
Adding CreatePerson Method to PersonAppService
We first define CreatePerson method in IPersonAppService interface:
Then we create CreatePersonInput DTO that defines parameters of the method:
And create mapping in CustomDtoMapper.cs:
All properties are decorated with data annotation attributes to provide automatic validation. Notice that we use same consts defined in Person entity for MaxLength properties.
Here, the implementation of CreatePerson method:
A Person entity is created by mapping given input, then inserted to database. We used async/await pattern here. All methods in ASP.NET Zero startup project is async. It's advised to use async/await wherever possible.