public ActionResult <ResidentReadDTO> CreateResident(ResidentCreateDTO model) { var residentModel = _mapper.Map <ResidentModel>(model); if (_apartmentRepo.GetApartmentByID(residentModel.ID_Apartment) == null) { return(BadRequest($"Apartment With ID {model.ID_Apartment} was not found \n Use https://localhost:44359/api/apartments from list of avalibale apartments! ")); } _repo.CreateResident(residentModel); _repo.SaveChanges(); var residentReadDto = _mapper.Map <ResidentReadDTO>(residentModel); return(CreatedAtRoute(nameof(GetResidentByID), new { ID = residentReadDto.ID_Reasident }, residentReadDto)); }
public async Task CreateResident(ResidentDTO dto) { var resident = _mapper.Map <Resident>(dto); await _repo.CreateResident(resident); }