public GenericListResponse <ReservationRequestResponse> GetUserReservations(long userId) { using (ReservationDataContext context = new ReservationDataContext()) { List <ReservationRequest> reservations = context.ReservationRequests.Include(x => x.Room).Where(x => x.UserId == userId).ToList(); ReservationManipulationService reservationManipulationService = new ReservationManipulationService(); List <ReservationRequestResponse> reservationResponses = reservations.Select(x => { bool returnAllData = x.Room.OwnerId == userId || x.UserId == userId; return(reservationManipulationService.ConvertToResponse(x, returnAllData)); }).OrderBy(x => x.RentStart).ToList(); return(new GenericListResponse <ReservationRequestResponse>(reservationResponses, reservationResponses.Count)); } }
public GenericListResponse <ReservationRequestResponse> GetReservationsByDate(long roomId, DateTime startDate, DateTime endDate, long userId, int skip, int take) { using (ReservationDataContext context = new ReservationDataContext()) { Room room = context.Rooms.Include(x => x.Reservations).Single(x => x.Id == roomId); IEnumerable <ReservationRequest> reservationsQuery = room.Reservations.Where(x => x.RentStart >= startDate && x.RentStart <= endDate && (x.Status != ReservationStatus.Rejected || (room.OwnerId == userId || x.UserId == userId))); List <ReservationRequest> reservationList = reservationsQuery.Skip(skip).Take(take).ToList(); int totalCount = reservationsQuery.Count(); long[] reservationIds = reservationList.Select(x => x.Id).ToArray(); List <ReservationRequest> expandedReservationList = context.ReservationRequests.Include(x => x.User).Where(x => reservationIds.Contains(x.Id)).ToList(); ReservationManipulationService reservationManipulationService = new ReservationManipulationService(); List <ReservationRequestResponse> reservationResponses = expandedReservationList.Select(x => { bool returnAllData = room.OwnerId == userId || x.UserId == userId; return(reservationManipulationService.ConvertToResponse(x, returnAllData)); }).OrderBy(x => x.RentStart).ToList(); return(new GenericListResponse <ReservationRequestResponse>(reservationResponses, totalCount)); } }