Exemple #1
0
        public ReservationInfoDTO GetReservationInfoForCar(int carId)
        {
            var reservationsForCar = new ReservationInfoDTO {
                CarId = carId
            };

            int currentReservationId = GetCurrentReservationId(carId);
            int nextReservationId    = GetNextReservationId(carId, currentReservationId);

            int reservationCount = _context.Reservations.Where(r => r.CarId == carId).Count();

            if (reservationCount == 0)
            {
                reservationsForCar.AtClient = false;
                reservationsForCar.NowAt    = _context.Cars
                                              .Include(c => c.PickUpLocation)
                                              .Where(c => c.Id == carId)
                                              .Select(c => c.PickUpLocation)
                                              .FirstOrDefault();
            }
            else if (currentReservationId == 0)
            {
                reservationsForCar.AtClient = false;
                reservationsForCar.NowAt    = _context.Reservations.Include(r => r.DropDownLocation)
                                              .Where(r => r.CarId == carId)
                                              .OrderBy(r => Math.Abs((DateTime.Now - r.ReserveTo).TotalDays))
                                              .Select(r => r.DropDownLocation)
                                              .FirstOrDefault();
            }
            else if (currentReservationId != 0)
            {
                Reservation current = _context.Reservations
                                      .Include(r => r.DropDownLocation)
                                      .Where(r => r.Id == currentReservationId)
                                      .First();

                reservationsForCar.CurrentReservationReturnDate     = current.ReserveTo;
                reservationsForCar.CurrentReservationReturnLocation = current.DropDownLocation;

                reservationsForCar.AtClient    = true;
                reservationsForCar.ClientEmail = _context
                                                 .Reservations
                                                 .Include(r => r.User)
                                                 .Where(r => r.Id == currentReservationId).Select(r => r.User.Email).First();
            }

            if (nextReservationId != 0)
            {
                Reservation next = _context
                                   .Reservations
                                   .Include(r => r.PickUpLocation)
                                   .Where(r => r.Id == nextReservationId)
                                   .First();

                reservationsForCar.NextReservationStartDate      = next.ReserveFrom;
                reservationsForCar.NextReservationPickUpLocation = next.PickUpLocation;
            }

            return(reservationsForCar);
        }
Exemple #2
0
        public async Task <PagedReservationUsersDTO> GetNotSignedUpUsers(
            int pageNumber,
            int pageSize,
            int trainingId,
            string userId,
            UserFilterData filterData)
        {
            var users = await _userRepository.GetNotSignedUpUsers(trainingId, userId);

            var pagedUsers = GetUsers(pageNumber, pageSize, users, filterData);
            var training   = await _trainingService.GetTraining(trainingId);

            var pagedReservationUsers = new List <ReservationUserDTO>();

            foreach (var user in pagedUsers.Users)
            {
                var reservation = await _reservationRepository.GetReservation(trainingId, user.Id);

                var reservationInfo = new ReservationInfoDTO();
                if (reservation != null)
                {
                    reservationInfo.IsSignedUp    = true;
                    reservationInfo.IsReserveList = reservation.IsReserveList;
                }
                else
                {
                    reservationInfo.IsSignedUp    = false;
                    reservationInfo.IsReserveList = false;
                }
                pagedReservationUsers.Add(new ReservationUserDTO
                {
                    User            = user,
                    ReservationInfo = reservationInfo
                });
            }

            return(new PagedReservationUsersDTO
            {
                TotalCount = pagedUsers.TotalCount,
                TotalPages = pagedUsers.TotalPages,
                Users = pagedReservationUsers,
                Training = training
            });
        }
Exemple #3
0
        public async Task <ReservationInfoDTO> GetReservationInfo(string userId, int trainingId)
        {
            var result    = new ReservationInfoDTO();
            var trainings = await _trainingRepository.GetReservedTrainings(userId);

            if (trainings.Any(t => t.Id == trainingId))
            {
                result.IsSignedUp = true;
                var reservation = await _reservationRepository.GetReservation(trainingId, userId);

                result.IsReserveList = reservation.IsReserveList;
            }
            else
            {
                result.IsSignedUp    = false;
                result.IsReserveList = false;
            }
            return(result);
        }