Пример #1
0
        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));
        }
Пример #2
0
 public async Task CreateResident(ResidentDTO dto)
 {
     var resident = _mapper.Map <Resident>(dto);
     await _repo.CreateResident(resident);
 }