using System; using System.Linq; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; using Volo.Abp.Linq; namespace Volo.Abp.Application.Services { public abstract class AsyncCrudAppService : AsyncCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { protected AsyncCrudAppService(IQueryableRepository repository) : base(repository) { } } public abstract class AsyncCrudAppService : AsyncCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { protected AsyncCrudAppService(IQueryableRepository repository) : base(repository) { } } public abstract class AsyncCrudAppService : AsyncCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { protected AsyncCrudAppService(IQueryableRepository repository) : base(repository) { } } public abstract class AsyncCrudAppService : AsyncCrudAppService where TGetAllInput : IPagedAndSortedResultRequest where TEntity : class, IEntity where TEntityDto : IEntityDto where TCreateInput : IEntityDto { protected AsyncCrudAppService(IQueryableRepository repository) : base(repository) { } } public abstract class AsyncCrudAppService : CrudAppServiceBase, IAsyncCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { public IAsyncQueryableExecuter AsyncQueryableExecuter { get; set; } protected AsyncCrudAppService(IQueryableRepository repository) :base(repository) { AsyncQueryableExecuter = DefaultAsyncQueryableExecuter.Instance; } public virtual async Task Get(TPrimaryKey id) { CheckGetPermission(); var entity = await GetEntityByIdAsync(id); return MapToEntityDto(entity); } public virtual async Task> GetList(TGetAllInput input) { CheckGetAllPermission(); var query = CreateFilteredQuery(input); var totalCount = await AsyncQueryableExecuter.CountAsync(query); query = ApplySorting(query, input); query = ApplyPaging(query, input); var entities = await AsyncQueryableExecuter.ToListAsync(query); return new PagedResultDto( totalCount, entities.Select(MapToEntityDto).ToList() ); } public virtual async Task Create(TCreateInput input) { CheckCreatePermission(); var entity = MapToEntity(input); await Repository.InsertAsync(entity); await CurrentUnitOfWork.SaveChangesAsync(); return MapToEntityDto(entity); } public virtual async Task Update(TPrimaryKey id, TUpdateInput input) { CheckUpdatePermission(); var entity = await GetEntityByIdAsync(id); //TODO: Check if input has id different than given id and normalize if it's default value, throw ex otherwise MapToEntity(input, entity); await CurrentUnitOfWork.SaveChangesAsync(); return MapToEntityDto(entity); } public virtual Task Delete(TPrimaryKey id) { CheckDeletePermission(); return Repository.DeleteAsync(id); } protected virtual Task GetEntityByIdAsync(TPrimaryKey id) { return Repository.GetAsync(id); } } }