Ejemplo n.º 1
0
 public IActionResult GetReservationsForAccount(string id)
 {
     try
     {
         if (id != HttpContext.GetUserId() && HttpContext.GetUserRole() != "Worker")
         {
             return(BadRequest("You don't own reservations you are trying to get."));
         }
         List <Reservation>    reservations = _reservationService.GetReservationsForAccount(id);
         List <ReservationDto> result       = new List <ReservationDto>();
         foreach (Reservation res in reservations)
         {
             WorkDay        workDay = _workDaysService.GetWorkDay(res.WorkDayId);
             ReservationDto dto     = _mapper.Map <ReservationDto>(
                 res, opt =>
             {
                 opt.Items["workDay"] = workDay;
             });
             result.Add(dto);
         }
         return(Ok(result));
     }
     catch (Exception ex)
     {
         if (ex.GetType().IsAssignableFrom(typeof(InvalidForeignKeyException)))
         {
             //TODO: Appropriate statuse code
             return(StatusCode(StatusCodes.Status409Conflict, ex.Message));
         }
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }