Пример #1
0
        public IActionResult EditBooking([FromBody] BookingUpdateDto bookingUpdateDto, int id)
        {
            if (bookingUpdateDto == null)
            {
                return(BadRequest());
            }

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

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

            _repository.EditBooking(id, bookingDto);
            if (!_repository.SaveChanges())
            {
                return(StatusCode(500, "Changes has not been saved."));
            }
            return(Ok(_repository.GetBooking(id)));
        }
Пример #2
0
        public async Task <IActionResult> UpdateBookingAsync(int id, BookingUpdateDto bookingUpdateDto)
        {
            if (id != bookingUpdateDto.Id)
            {
                return(BadRequest());
            }

            var bookingFromRepo = await _repository.GetByIdAsync(id);

            if (bookingFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(bookingUpdateDto, bookingFromRepo);
            //_repository.UpdateBooking(bookingFromRepo.Value); // this is achieved by the previous code

            try
            {
                await _repository.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if ((await _repository.GetByIdAsync(id)) == null)
                {
                    return(NotFound());
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <ActionResult> UpdateBooking(BookingUpdateDto bookingUpdateDto)
        {
            var booking = await _bookingService.GetBookingAsync(bookingUpdateDto.Id);

            _mapper.Map(bookingUpdateDto, booking);

            _bookingService.UpdateBooking(bookingUpdateDto);

            if (await _bookingService.SaveAllAsync())
            {
                return(NoContent());
            }

            return(BadRequest("Failed to modify booking"));
        }
Пример #4
0
        public HttpResponseMessage UpdateBooking(BookingUpdateDto bookingDto)
        {
            if (!bookingBusiness.IsBookingIDValid(bookingDto.BookingID))
            {
                HttpError err = new HttpError("The bookingID you entered is not valid.");
                return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
            }
            else if (!bookingBusiness.IsStatusValid(bookingDto.Status))
            {
                HttpError err = new HttpError("The Status must be either Active, Completed or Cancelled.");
                return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
            }

            bookingBusiness.UpdateBooking(bookingDto.BookingID, bookingDto.Status);
            return(Request.CreateResponse(HttpStatusCode.OK, "Booking updated"));
        }
Пример #5
0
 public void UpdateBooking(BookingUpdateDto bookingDto)
 {
     _context.Entry(bookingDto).State = EntityState.Modified;
 }