Exemple #1
0
 public IActionResult GetReservationById(string id)
 {
     try
     {
         Reservation res = _reservationService.GetReservation(id);
         if (res == null)
         {
             return(NotFound("Reservation with id not found"));
         }
         Account acc = res.Account;
         // Regular user can get only his resrvations
         if (acc.Id != HttpContext.GetUserId() && HttpContext.GetUserRole() != "Worker")
         {
             return(BadRequest("You don't own reservation you are trying to get."));
         }
         WorkDay        workDay = _workDaysService.GetWorkDay(res.WorkDayId);
         ReservationDto result  = _mapper.Map <ReservationDto>(
             res, opt =>
         {
             opt.Items["workDay"] = workDay;
         });
         return(Ok(result));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
        public IActionResult Get(int id)
        {
            try
            {
                var reservation = _reservationsService.GetReservation(id);

                return(Ok(reservation));
            }
            catch (ReservationNotFoundException)
            {
                return(NotFound());
            }
        }
Exemple #3
0
        private void setPaymentFields(Payment payment)
        {
            WorkerAccount w = _accountsService.GetWorkerAccount(payment.WorkerAccount.Id);

            if (w == null)
            {
                throw new InvalidForeignKeyException("Invalid workerAccountId");
            }
            Reservation r = _reservationsService.GetReservation(payment.Reservation.Id);

            if (r == null)
            {
                throw new InvalidForeignKeyException("Invalid reservationId");
            }
            payment.WorkerAccount = w;
            payment.Reservation   = r;
        }
Exemple #4
0
 public ActionResult <EditReservationViewModel> GetReservation(int id)
 {
     return(_reservationsService.GetReservation(id));
 }