public GenericListResponse <RoomResponse> GetRoomsByOwner(long ownerId) { using (ReservationDataContext context = new ReservationDataContext()) { List <Objects.Room> rooms = context.Rooms.Where(x => x.OwnerId == ownerId).ToList(); RoomManipulationService roomManipulationService = new RoomManipulationService(); List <RoomResponse> roomResponses = rooms.Select(x => roomManipulationService.ConvertRoomToResponse(x, ownerId)).ToList(); return(new GenericListResponse <RoomResponse>(roomResponses, roomResponses.Count)); } }
public GenericObjectResponse <RoomResponse> GetRoomById(long roomId, long?userId, bool expand) { RoomManipulationService roomManipulationService = new RoomManipulationService(); using (ReservationDataContext context = new ReservationDataContext()) { var roomQuery = expand ? context.Rooms.Include(x => x.WorkingHours).Include(x => x.Reservations) : context.Rooms; var room = roomQuery.SingleOrDefault(x => x.Id == roomId); return(room != null ? new GenericObjectResponse <RoomResponse>(roomManipulationService.ConvertRoomToResponse(room, userId)) : new GenericObjectResponse <RoomResponse>("Room not found.")); } }
public GenericListResponse <RoomResponse> GetRoomsByNameOrCity(long?userId, string city, string name, int skip, int take) { RoomManipulationService roomManipulationService = new RoomManipulationService(); using (ReservationDataContext context = new ReservationDataContext()) { var roomsQuery = context.Rooms.Include(x => x.WorkingHours) .ToList() .Where(x => CompareStrings(city, x.City) || CompareStrings(name, x.Name)); List <RoomResponse> rooms = roomsQuery .OrderBy(x => x.Id) .Skip(skip) .Take(take) .ToList() .Select(x => roomManipulationService.ConvertRoomToResponse(x, userId)) .ToList(); int count = roomsQuery.Count(); return(new GenericListResponse <RoomResponse>(rooms, count)); } }
public GenericListResponse <RoomResponse> GetRoomsByLatLonAndRadius(long?userId, decimal lat, decimal lon, int radius, int skip = 0, int take = 10) { RoomManipulationService roomManipulationService = new RoomManipulationService(); using (ReservationDataContext context = new ReservationDataContext()) { var roomsQuery = context.Rooms.Include(x => x.WorkingHours) .Where(x => x.Lat.HasValue && x.Lon.HasValue) .ToList() .Select(x => new { Room = x, Distance = GetDistance(lon, lat, x.Lon.Value, x.Lat.Value) }) .Where(x => x.Distance <= radius); List <RoomResponse> rooms = roomsQuery .Skip(skip) .Take(take) .Select(x => roomManipulationService.ConvertRoomToResponse(x.Room, userId)) .ToList(); int count = roomsQuery.Count(); return(new GenericListResponse <RoomResponse>(rooms, count)); } }