Beispiel #1
0
        public async Task <IActionResult> Update([FromBody] UpdateReservationDTO updatedReservation)
        {
            // check if requester is allowed to update this reservation
            if (!await _permissionService.CanUpdateReservation(updatedReservation.Id, HttpContext.GetUserIdFromToken()))
            {
                return(Forbid());
            }

            return(Ok(await _reservationService.UpdateReservation(updatedReservation)));
        }
Beispiel #2
0
        public async Task <ServiceResponse <GetReservationDTO> > UpdateReservation(UpdateReservationDTO updatedReservation)
        {
            ServiceResponse <GetReservationDTO> serviceResponse = new ServiceResponse <GetReservationDTO>();

            try
            {
                Reservation reservation = await _context.Reservations.FindAsync(updatedReservation.Id);

                if (reservation != null)
                {
                    reservation.Pickup      = updatedReservation.Pickup;
                    reservation.Price       = updatedReservation.Price;
                    reservation.UserComment = updatedReservation.UserComment;
                    // TODO: add items here (how to handle update items?)

                    _context.Reservations.Update(reservation);
                    await _context.SaveChangesAsync();

                    // TODO: add reservation updated user mail
                    // TODO: add reservation updated seller mail

                    serviceResponse.Data = _mapper.Map <GetReservationDTO>(reservation);
                }
                else
                {
                    serviceResponse.Success = false;
                    serviceResponse.Message = $"Could not found reservation with id '{updatedReservation.Id}'";
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Success   = false;
                serviceResponse.Exception = ex.Message;
            }
            return(serviceResponse);
        }