示例#1
0
        private static void CheckAndHandleReservations()
        {
            List <Reservation> reservations = reservationsService.GetReservations();

            if (reservations.Count == 0)
            {
                return;
            }

            lock (reservations)
            {
                List <Reservation> reservationsForRemoving = new List <Reservation>();

                Zone         zone;
                ParkingPlace parkingPlace;

                foreach (Reservation reservation in reservations)
                {
                    if (reservation.GetEndDateTimeServer() < DateTime.Now)
                    {
                        zone = zonesService.GetZone(reservation.ParkingPlace.Zone.Id);
                        lock (zone)
                        {
                            parkingPlace = zone.GetParkingPlace(reservation.ParkingPlace.Id);
                            lock (parkingPlace)
                            {
                                parkingPlace.Status = ParkingPlaceStatus.EMPTY;
                            }

                            zone.Version++;
                            zone.AddParkingPlaceChange(parkingPlace.Id, parkingPlace.Status);
                        }
                        reservation.User.Reservation = null;
                        reservation.User.AddViolation(true);

                        reservationsForRemoving.Add(reservation);
                    }
                }

                if (reservationsForRemoving.Count > 0)
                {
                    reservations.RemoveAll(item => reservationsForRemoving.Contains(item));
                }
            }
        }
示例#2
0
 public IActionResult Get()
 {
     try
     {
         List <Reservation>    reservations = _reservationService.GetReservations();
         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)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
示例#3
0
 public async Task <ActionResult <IEnumerable <ReservationItem> > > Get()
 {
     return(Ok(await _service.GetReservations()));
 }
示例#4
0
 public ActionResult <IEnumerable <ReservationViewModel> > GetReservations()
 {
     return(_reservationsService.GetReservations());
 }