using AutoMapper; using back.Application.Contracts.Persistence; using back.Application.Contracts.Services; using back.Entities; using back.Infra; namespace back.Application.Services { public class GenericService : IBaseService where T : BaseEntity { private readonly IMapper mapper; private readonly IAsyncRepository repo; public GenericService(IMapper mapper, IAsyncRepository repo) { this.mapper = mapper; this.repo = repo; } public virtual async Task Add(A dto) { T entity = mapper.Map(dto); return await repo.AddAsync(entity); } public virtual async Task Delete(int id) { T entityExists = await repo.GetByIdAsync(id); if(entityExists == null) { return false; } await repo.DeleteAsync(entityExists); return true; } public virtual async Task> GetAll() { return await repo.GetAllAsync(); } public virtual async Task GetOne(int id) { return await repo.GetByIdAsync(id); } public virtual async Task Update(U dto) { T entity = mapper.Map(dto); await repo.UpdateAsync(entity); return entity; } } }