Browse Source

Added a few custom methods to PersonAppService.

pull/96/head
Halil İbrahim Kalkan 9 years ago
parent
commit
aba80f85cf
  1. 2
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPersonAppService.cs
  2. 32
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PersonAppService.cs
  3. 6
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs

2
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPersonAppService.cs

@ -8,5 +8,7 @@ namespace Volo.Abp.TestApp.Application
public interface IPersonAppService : IAsyncCrudAppService<PersonDto> public interface IPersonAppService : IAsyncCrudAppService<PersonDto>
{ {
Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter filter); Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter filter);
Task<PhoneDto> AddPhone(Guid id, PhoneDto phoneDto);
} }
} }

32
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PersonAppService.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.TestApp.Domain; using Volo.Abp.TestApp.Domain;
@ -16,13 +17,34 @@ namespace Volo.Abp.TestApp.Application
} }
public async Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter input) //URL: [GET] /api/people/{id}?type=office
public async Task<ListResultDto<PhoneDto>> 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<PhoneDto>( return new ListResultDto<PhoneDto>(
ObjectMapper.Map<Collection<Phone>, Collection<PhoneDto>>(person.Phones) ObjectMapper.Map<List<Phone>, List<PhoneDto>>(phones)
); );
} }
//URL: [POST] /api/people/{id}/phones
public async Task<PhoneDto> 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, PhoneDto>(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);
}
} }
} }

6
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Phone.cs

@ -1,9 +1,12 @@
using System;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain namespace Volo.Abp.TestApp.Domain
{ {
public class Phone : Entity<long> public class Phone : Entity<long>
{ {
public virtual Guid PersonId { get; set; }
public virtual string Number { get; set; } public virtual string Number { get; set; }
public virtual PhoneType Type { 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; Number = number;
Type = type; Type = type;
} }

Loading…
Cancel
Save