Exemple #1
0
        public IActionResult AddBooking([FromBody] BookingDto bookingDto)
        {
            if (bookingDto == null)
            {
                return(BadRequest());
            }

            var spot = _repository.GetSpot(bookingDto.SpotId);

            if (spot == null)
            {
                return(StatusCode(404, $"Couldn't find the spot that has an id: {bookingDto.SpotId}"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var bookingEntity = Mapper.Map <Booking>(bookingDto);

            _repository.AddBooking(bookingEntity);
            if (!_repository.SaveChanges())
            {
                return(StatusCode(500, "Changes has not been saved"));
            }

            return(Ok(_repository.GetBooking(bookingEntity.Id)));
        }
Exemple #2
0
        public async Task <Spot> GetSpotById(int id)
        {
            var result = _repository.GetSpot(id);

            return(result);
        }