Browse Source

Change crud add service base.

pull/96/head
Halil İbrahim Kalkan 9 years ago
parent
commit
e105079311
  1. 44
      src/Volo.Abp/Volo/Abp/Application/Services/AsyncCrudAppService.cs
  2. 44
      src/Volo.Abp/Volo/Abp/Application/Services/CrudAppService.cs
  3. 1
      src/Volo.Abp/Volo/Abp/Application/Services/CrudAppServiceBase.cs
  4. 34
      src/Volo.Abp/Volo/Abp/Application/Services/IAsyncCrudAppService.cs
  5. 34
      src/Volo.Abp/Volo/Abp/Application/Services/ICrudAppService.cs
  6. 4
      test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs

44
src/Volo.Abp/Volo/Abp/Application/Services/AsyncCrudAppService.cs

@ -59,40 +59,10 @@ namespace Volo.Abp.Application.Services
}
public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>
: AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, EntityDto<TPrimaryKey>>
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
{
protected AsyncCrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
}
}
public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput>
: AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, EntityDto<TPrimaryKey>>
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
where TGetInput : IEntityDto<TPrimaryKey>
{
protected AsyncCrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
}
}
public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, TDeleteInput>
: CrudAppServiceBase<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>,
IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, TDeleteInput>
IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
where TGetInput : IEntityDto<TPrimaryKey>
where TDeleteInput : IEntityDto<TPrimaryKey>
{
public IAsyncQueryableExecuter AsyncQueryableExecuter { get; set; }
@ -102,11 +72,11 @@ namespace Volo.Abp.Application.Services
AsyncQueryableExecuter = DefaultAsyncQueryableExecuter.Instance;
}
public virtual async Task<TEntityDto> Get(TGetInput input)
public virtual async Task<TEntityDto> Get(TPrimaryKey id)
{
CheckGetPermission();
var entity = await GetEntityByIdAsync(input.Id);
var entity = await GetEntityByIdAsync(id);
return MapToEntityDto(entity);
}
@ -141,11 +111,11 @@ namespace Volo.Abp.Application.Services
return MapToEntityDto(entity);
}
public virtual async Task<TEntityDto> Update(TUpdateInput input)
public virtual async Task<TEntityDto> Update(TPrimaryKey id, TUpdateInput input)
{
CheckUpdatePermission();
var entity = await GetEntityByIdAsync(input.Id);
var entity = await GetEntityByIdAsync(id);
MapToEntity(input, entity);
await CurrentUnitOfWork.SaveChangesAsync();
@ -153,11 +123,11 @@ namespace Volo.Abp.Application.Services
return MapToEntityDto(entity);
}
public virtual Task Delete(TDeleteInput input)
public virtual Task Delete(TPrimaryKey id)
{
CheckDeletePermission();
return Repository.DeleteAsync(input.Id);
return Repository.DeleteAsync(id);
}
protected virtual Task<TEntity> GetEntityByIdAsync(TPrimaryKey id)

44
src/Volo.Abp/Volo/Abp/Application/Services/CrudAppService.cs

@ -56,40 +56,10 @@ namespace Volo.Abp.Application.Services
}
public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>
: CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, EntityDto<TPrimaryKey>>
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
{
protected CrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
}
}
public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput>
: CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, EntityDto<TPrimaryKey>>
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
where TGetInput : IEntityDto<TPrimaryKey>
{
protected CrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
{
}
}
public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, TDeleteInput>
: CrudAppServiceBase<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>,
ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, TDeleteInput>
ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
where TGetInput : IEntityDto<TPrimaryKey>
where TDeleteInput : IEntityDto<TPrimaryKey>
{
protected CrudAppService(IQueryableRepository<TEntity, TPrimaryKey> repository)
: base(repository)
@ -97,11 +67,11 @@ namespace Volo.Abp.Application.Services
}
public virtual TEntityDto Get(TGetInput input)
public virtual TEntityDto Get(TPrimaryKey id)
{
CheckGetPermission();
var entity = GetEntityById(input.Id);
var entity = GetEntityById(id);
return MapToEntityDto(entity);
}
@ -136,11 +106,11 @@ namespace Volo.Abp.Application.Services
return MapToEntityDto(entity);
}
public virtual TEntityDto Update(TUpdateInput input)
public virtual TEntityDto Update(TPrimaryKey id, TUpdateInput input)
{
CheckUpdatePermission();
var entity = GetEntityById(input.Id);
var entity = GetEntityById(id);
MapToEntity(input, entity);
CurrentUnitOfWork.SaveChanges();
@ -148,11 +118,11 @@ namespace Volo.Abp.Application.Services
return MapToEntityDto(entity);
}
public virtual void Delete(TDeleteInput input)
public virtual void Delete(TPrimaryKey id)
{
CheckDeletePermission();
Repository.Delete(input.Id);
Repository.Delete(id);
}
protected virtual TEntity GetEntityById(TPrimaryKey id)

1
src/Volo.Abp/Volo/Abp/Application/Services/CrudAppServiceBase.cs

@ -15,7 +15,6 @@ namespace Volo.Abp.Application.Services
public abstract class CrudAppServiceBase<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput> : ApplicationService
where TEntity : class, IEntity<TPrimaryKey>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
{
protected IQueryableRepository<TEntity, TPrimaryKey> Repository { get; }

34
src/Volo.Abp/Volo/Abp/Application/Services/IAsyncCrudAppService.cs

@ -11,21 +11,21 @@ namespace Volo.Abp.Application.Services
}
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey>
public interface IAsyncCrudAppService<TEntityDto, in TPrimaryKey>
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, PagedAndSortedResultRequestDto>
where TEntityDto : IEntityDto<TPrimaryKey>
{
}
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput>
public interface IAsyncCrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput>
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TEntityDto, TEntityDto>
where TEntityDto : IEntityDto<TPrimaryKey>
{
}
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput>
public interface IAsyncCrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput, in TCreateInput>
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TCreateInput>
where TEntityDto : IEntityDto<TPrimaryKey>
where TCreateInput : IEntityDto<TPrimaryKey>
@ -33,38 +33,18 @@ namespace Volo.Abp.Application.Services
}
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput>
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, EntityDto<TPrimaryKey>>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
{
}
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput, in TGetInput>
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, EntityDto<TPrimaryKey>>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
where TGetInput : IEntityDto<TPrimaryKey>
{
}
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput, in TGetInput, in TDeleteInput>
public interface IAsyncCrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput>
: IApplicationService
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
where TGetInput : IEntityDto<TPrimaryKey>
where TDeleteInput : IEntityDto<TPrimaryKey>
{
Task<TEntityDto> Get(TGetInput input);
Task<TEntityDto> Get(TPrimaryKey id);
Task<PagedResultDto<TEntityDto>> GetAll(TGetAllInput input);
Task<TEntityDto> Create(TCreateInput input);
Task<TEntityDto> Update(TUpdateInput input);
Task<TEntityDto> Update(TPrimaryKey id, TUpdateInput input);
Task Delete(TDeleteInput input);
Task Delete(TPrimaryKey id);
}
}

34
src/Volo.Abp/Volo/Abp/Application/Services/ICrudAppService.cs

@ -10,21 +10,21 @@ namespace Volo.Abp.Application.Services
}
public interface ICrudAppService<TEntityDto, TPrimaryKey>
public interface ICrudAppService<TEntityDto, in TPrimaryKey>
: ICrudAppService<TEntityDto, TPrimaryKey, PagedAndSortedResultRequestDto>
where TEntityDto : IEntityDto<TPrimaryKey>
{
}
public interface ICrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput>
public interface ICrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput>
: ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TEntityDto, TEntityDto>
where TEntityDto : IEntityDto<TPrimaryKey>
{
}
public interface ICrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput>
public interface ICrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput, in TCreateInput>
: ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TCreateInput>
where TEntityDto : IEntityDto<TPrimaryKey>
where TCreateInput : IEntityDto<TPrimaryKey>
@ -32,38 +32,18 @@ namespace Volo.Abp.Application.Services
}
public interface ICrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput>
: ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, EntityDto<TPrimaryKey>>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
{
}
public interface ICrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput, in TGetInput>
: ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, EntityDto<TPrimaryKey>>
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
where TGetInput : IEntityDto<TPrimaryKey>
{
}
public interface ICrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput, in TGetInput, in TDeleteInput>
public interface ICrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput>
: IApplicationService
where TEntityDto : IEntityDto<TPrimaryKey>
where TUpdateInput : IEntityDto<TPrimaryKey>
where TGetInput : IEntityDto<TPrimaryKey>
where TDeleteInput : IEntityDto<TPrimaryKey>
{
TEntityDto Get(TGetInput input);
TEntityDto Get(TPrimaryKey id);
PagedResultDto<TEntityDto> GetAll(TGetAllInput input);
TEntityDto Create(TCreateInput input);
TEntityDto Update(TUpdateInput input);
TEntityDto Update(TPrimaryKey id, TUpdateInput input);
void Delete(TDeleteInput input);
void Delete(TPrimaryKey id);
}
}

4
test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs

@ -101,9 +101,9 @@ namespace Volo.Abp.AspNetCore.Mvc
//Act
//Ideally should be [PUT] /api/app/person
//Ideally should be [PUT] /api/app/person/{id}
var response = await Client.PutAsync(
"/api/services/app/person/Update/{id}",
"/api/services/app/person/Update?id=" + updateDto.Id,
new StringContent(putData, Encoding.UTF8, "application/json")
);

Loading…
Cancel
Save