From aba80f85cf06ea20b5f591edb24d728c154c7ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 9 Sep 2017 23:20:59 +0300 Subject: [PATCH] Added a few custom methods to PersonAppService. --- .../TestApp/Application/IPersonAppService.cs | 2 ++ .../TestApp/Application/PersonAppService.cs | 32 ++++++++++++++++--- .../Volo/Abp/TestApp/Domain/Phone.cs | 6 +++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPersonAppService.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPersonAppService.cs index f5bee1701a..e615bfa943 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPersonAppService.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPersonAppService.cs @@ -8,5 +8,7 @@ namespace Volo.Abp.TestApp.Application public interface IPersonAppService : IAsyncCrudAppService { Task> GetPhones(Guid id, GetPersonPhonesFilter filter); + + Task AddPhone(Guid id, PhoneDto phoneDto); } } \ No newline at end of file diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PersonAppService.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PersonAppService.cs index 20ad74f31a..1a124ef8bd 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PersonAppService.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PersonAppService.cs @@ -1,5 +1,6 @@ using System; -using System.Collections.ObjectModel; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.TestApp.Domain; @@ -16,13 +17,34 @@ namespace Volo.Abp.TestApp.Application } - public async Task> GetPhones(Guid id, GetPersonPhonesFilter input) + //URL: [GET] /api/people/{id}?type=office + public async Task> GetPhones(Guid id, GetPersonPhonesFilter filter) { - var person = await GetEntityByIdAsync(id); - + var phones = (await GetEntityByIdAsync(id)).Phones + .WhereIf(filter.Type.HasValue, p => p.Type == filter.Type) + .ToList(); + return new ListResultDto( - ObjectMapper.Map, Collection>(person.Phones) + ObjectMapper.Map, List>(phones) ); } + + //URL: [POST] /api/people/{id}/phones + public async Task AddPhone(Guid id, PhoneDto phoneDto) + { + var person = await GetEntityByIdAsync(id); + var phone = new Phone(person.Id, phoneDto.Number, phoneDto.Type); + + person.Phones.Add(phone); + + return ObjectMapper.Map(phone); + } + + //URL: [DELETE] /api/people/{id}/phones/{phoneId} + public async Task DeletePhone(Guid id, long phoneId) + { + var person = await GetEntityByIdAsync(id); + person.Phones.RemoveAll(p => p.Id == phoneId); + } } } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs index b541da9240..def35e0962 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs @@ -1,9 +1,12 @@ +using System; using Volo.Abp.Domain.Entities; namespace Volo.Abp.TestApp.Domain { public class Phone : Entity { + public virtual Guid PersonId { get; set; } + public virtual string Number { get; set; } public virtual PhoneType Type { get; set; } @@ -13,8 +16,9 @@ namespace Volo.Abp.TestApp.Domain } - public Phone(string number, PhoneType type = PhoneType.Mobile) + public Phone(Guid personId, string number, PhoneType type = PhoneType.Mobile) { + PersonId = personId; Number = number; Type = type; }