Пример #1
0
        public ActionResult <ApartmentReadDTO> GetApartmentByID(int id)
        {
            ApartmentModel apartment = _repo.GetApartmentByID(id);

            if (apartment == null)
            {
                return(NotFound());
            }
            return(Ok(_mapper.Map <ApartmentModel>(apartment)));
        }
Пример #2
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));
        }