public async Task <ActionResult <ApartmentDto> > Post(CreateApartmentDto createApartmentDto) { var location = await _locationsRepo.GetAsync(createApartmentDto.LocationId); if (location is null) { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, "The location with the specified Id does not exist.")); } var existingApartmentForLocation = await _apartmentsRepo.GetByLocationIdAsync(createApartmentDto.LocationId); if (existingApartmentForLocation != null) { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, "The apartment in this location already been added.")); } var apartment = _mapper.Map <Apartment>(createApartmentDto); await _apartmentsRepo.AddAsync(apartment); apartment.Location = location; var apartmentDto = _mapper.Map <ApartmentDto>(apartment); return(CreatedAtAction("Get", new { apartmentId = apartment.Id }, apartmentDto)); }
public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var location = await _locationsRepository.GetAsync(id); if (location == null) { return(NotFound()); } return(View(location)); }
public async Task <ActionResult <LocationDto> > Get(int locationId) { var locationFromRepo = await _locationsRepo.GetAsync(locationId); if (locationFromRepo is null) { return(NotFound()); } var locationDto = _mapper.Map <LocationDto>(locationFromRepo); return(Ok(locationDto)); }
public async Task <Locations> GetLocationAsync(int locationId) { return(await _locationsRepository.GetAsync(locationId)); }