32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using AutoMapper;
|
|
using back.Entities.DTOs.Request;
|
|
using back.Entities;
|
|
using back.Infra;
|
|
using back.Application.Contracts.Persistence;
|
|
|
|
namespace back.Application.Services
|
|
{
|
|
public class CasaService : GenericService<Casa, CasaRequestDto, CasaUpdateRequestDto>
|
|
{
|
|
private readonly IMapper _mapper;
|
|
private readonly DireccionService dService;
|
|
private readonly IAsyncRepository<Casa> repo;
|
|
public CasaService(IMapper mapper, IAsyncRepository<Casa> _repo, DireccionService dService) : base(mapper, _repo)
|
|
{
|
|
_mapper = mapper;
|
|
this.dService = dService;
|
|
repo = _repo;
|
|
}
|
|
|
|
public async override Task<Casa> Add(CasaRequestDto dto)
|
|
{
|
|
var direccion = _mapper.Map<Direccion>(dto.Direction);
|
|
var d = await dService.AddOne(direccion);
|
|
var casa = _mapper.Map<Casa>(dto);
|
|
casa.Direccion = d;
|
|
|
|
return await repo.AddAsync(casa);
|
|
}
|
|
}
|
|
}
|