Added a few custom methods to PersonAppService.

pull/96/head
Halil İbrahim Kalkan 8 years ago
parent 5bc7862095
commit aba80f85cf

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

@ -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<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>(
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);
}
}
}

@ -1,9 +1,12 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain
{
public class Phone : Entity<long>
{
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;
}

Loading…
Cancel
Save