| | 1 | | using AutoMapper; |
| | 2 | | using Domain.Core.Aggreggates; |
| | 3 | | using Repository.Persistency.Generic; |
| | 4 | |
|
| | 5 | | namespace Despesas.Application.Abstractions.Generic; |
| | 6 | |
|
| | 7 | | public class GenericBusiness<Dto, Entity> : IBusiness<Dto, Entity> where Dto : class where Entity : BaseDomain, new() |
| | 8 | | { |
| | 9 | | private readonly IRepositorio<Entity> _repositorio; |
| | 10 | | private readonly IMapper _mapper; |
| | 11 | |
|
| 9 | 12 | | public GenericBusiness(IMapper mapper, IRepositorio<Entity> repositorio) |
| 9 | 13 | | { |
| 9 | 14 | | _mapper = mapper; |
| 9 | 15 | | _repositorio = repositorio; |
| 9 | 16 | | } |
| | 17 | | public Dto Create(Dto obj) |
| 1 | 18 | | { |
| 1 | 19 | | var entity = _mapper.Map<Entity>(obj); |
| 1 | 20 | | _repositorio.Insert(entity); |
| 1 | 21 | | return _mapper.Map<Dto>(entity); |
| 1 | 22 | | } |
| | 23 | |
|
| | 24 | | public List<Dto> FindAll(Guid idUsuario) |
| 1 | 25 | | { |
| 1 | 26 | | return _mapper.Map<List<Dto>>(_repositorio.GetAll()); |
| 1 | 27 | | } |
| | 28 | |
|
| | 29 | | public virtual Dto FindById(Guid id, Guid idUsuario) |
| 1 | 30 | | { |
| 1 | 31 | | return _mapper.Map<Dto>(_repositorio.Get(id)); |
| 1 | 32 | | } |
| | 33 | |
|
| | 34 | | public Dto Update(Dto obj) |
| 1 | 35 | | { |
| 1 | 36 | | var entity = _mapper.Map<Entity>(obj); |
| 1 | 37 | | _repositorio.Update(entity); |
| 1 | 38 | | return _mapper.Map<Dto>(obj); |
| 1 | 39 | | } |
| | 40 | |
|
| | 41 | | public bool Delete(Dto obj) |
| 1 | 42 | | { |
| 1 | 43 | | var entity = _mapper.Map<Entity>(obj); |
| 1 | 44 | | _repositorio.Delete(entity); |
| 1 | 45 | | return true; |
| 1 | 46 | | } |
| | 47 | | } |