Added phone entity in the sample application.

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

@ -209,17 +209,16 @@ namespace Volo.Abp.AspNetCore.Mvc
private void AddAbpServiceSelector(string moduleName, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration)
{
var verb = configuration?.UseConventionalHttpVerbs == true
? HttpVerbHelper.GetConventionalVerbForMethodName(action.ActionName)
: HttpVerbHelper.DefaultHttpVerb;
var abpServiceSelectorModel = new SelectorModel
{
AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action)
AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, verb),
ActionConstraints = { new HttpMethodActionConstraint(new[] { verb }) }
};
var verb = configuration?.UseConventionalHttpVerbs == true
? HttpVerbHelper.GetConventionalVerbForMethodName(action.ActionName)
: HttpVerbHelper.DefaultHttpVerb;
abpServiceSelectorModel.ActionConstraints.Add(new HttpMethodActionConstraint(new[] { verb }));
action.Selectors.Add(abpServiceSelectorModel);
}
@ -227,13 +226,11 @@ namespace Volo.Abp.AspNetCore.Mvc
{
foreach (var selector in action.Selectors)
{
//TODO: Revise this?
var method = selector.ActionConstraints.OfType<HttpMethodActionConstraint>().FirstOrDefault()?.HttpMethods?.FirstOrDefault();
if (selector.AttributeRouteModel == null)
{
selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(
moduleName,
controllerName,
action
);
selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, method);
}
}
}
@ -250,13 +247,17 @@ namespace Volo.Abp.AspNetCore.Mvc
return _configuration.Value.ControllerAssemblySettings.GetSettingOrNull(controllerType);
}
private static AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action)
private static AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action, string verb)
{
return new AttributeRouteModel(
new RouteAttribute(
$"api/services/{moduleName}/{controllerName}/{action.ActionName}"
)
);
//TODO: Implement via interfaces!
var url = $"api/services/{moduleName}/{controllerName}";
if (!verb.IsIn("POST"))
{
url += $"/{action.ActionName}";
}
return new AttributeRouteModel(new RouteAttribute(url));
}
private static void RemoveEmptySelectors(IList<SelectorModel> selectors)

@ -2,11 +2,9 @@ using System.Collections.Generic;
namespace Volo.Abp.Application.Dtos
{
public class ListResultDto<T>
public class ListResultDto<T> : IListResult<T>
{
/// <summary>
/// List of items.
/// </summary>
/// <inheritdoc />
public IReadOnlyList<T> Items
{
get { return _items ?? (_items = new List<T>()); }

@ -10,9 +10,7 @@ namespace Volo.Abp.Application.Dtos
[Serializable]
public class PagedResultDto<T> : ListResultDto<T>, IPagedResult<T>
{
/// <summary>
/// Total count of Items.
/// </summary>
/// <inheritdoc />
public int TotalCount { get; set; }
/// <summary>

@ -69,7 +69,7 @@ namespace Volo.Abp.AspNetCore.Mvc
//Ideally should be [POST] /api/app/person
var response = await Client.PostAsync(
"/api/services/app/person/Create",
"/api/services/app/person",
new StringContent(postData, Encoding.UTF8, "application/json")
);

@ -0,0 +1,9 @@
using Volo.Abp.TestApp.Domain;
namespace Volo.Abp.TestApp.Application
{
public class GetPersonPhonesFilter
{
public PhoneType? Type { get; set; }
}
}

@ -1,8 +1,12 @@
using Volo.Abp.Application.Services;
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace Volo.Abp.TestApp.Application
{
public interface IPersonAppService : IAsyncCrudAppService<PersonDto>
{
Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter filter);
}
}

@ -1,4 +1,8 @@
using Volo.Abp.TestApp.Domain;
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.TestApp.Domain;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Application.Services;
@ -9,6 +13,16 @@ namespace Volo.Abp.TestApp.Application
public PersonAppService(IQueryableRepository<Person> repository)
: base(repository)
{
}
public async Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter input)
{
var person = await GetEntityByIdAsync(id);
return new ListResultDto<PhoneDto>(
ObjectMapper.Map<Collection<Phone>, Collection<PhoneDto>>(person.Phones)
);
}
}
}

@ -0,0 +1,12 @@
using Volo.Abp.Application.Dtos;
using Volo.Abp.TestApp.Domain;
namespace Volo.Abp.TestApp.Application
{
public class PhoneDto : EntityDto<long>
{
public string Number { get; set; }
public PhoneType Type { get; set; }
}
}

@ -1,13 +1,16 @@
using System;
using System.Collections.ObjectModel;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain
{
public class Person : AggregateRoot
{
public string Name { get; set; }
public virtual string Name { get; set; }
public int Age { get; set; }
public virtual int Age { get; set; }
public virtual Collection<Phone> Phones { get; set; }
private Person()
{
@ -19,6 +22,8 @@ namespace Volo.Abp.TestApp.Domain
Id = id;
Name = name;
Age = age;
Phones = new Collection<Phone>();
}
}
}

@ -0,0 +1,22 @@
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain
{
public class Phone : Entity<long>
{
public virtual string Number { get; set; }
public virtual PhoneType Type { get; set; }
private Phone()
{
}
public Phone(string number, PhoneType type = PhoneType.Mobile)
{
Number = number;
Type = type;
}
}
}

@ -0,0 +1,9 @@
namespace Volo.Abp.TestApp.Domain
{
public enum PhoneType
{
Mobile,
Home,
Office
}
}

@ -24,16 +24,17 @@ namespace Volo.Abp.TestApp
{
services.Configure<AbpAutoMapperOptions>(options =>
{
options.Configurators.Add((IAbpAutoMapperConfigurationContext ctx) =>
options.Configurators.Add(ctx =>
{
ctx.MapperConfiguration.CreateMap<Person, PersonDto>().ReverseMap();
ctx.MapperConfiguration.CreateMap<Phone, PhoneDto>().ReverseMap();
});
});
}
private static void SeedTestData(ApplicationInitializationContext context)
{
using (IServiceScope scope = context.ServiceProvider.CreateScope())
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
.GetRequiredService<TestDataBuilder>()

Loading…
Cancel
Save