Exemplo n.º 1
0
 public List <Booking> GetBookingsByOtel(int?otelId)
 {
     using (var context = new ResitalContext())
     {
         var bookings = context.Booking.Where(i => i.IsActive).AsQueryable();
         if (otelId != null)
         {
             bookings = bookings
                        .Include(i => i.Otel)
                        .Where(i => i.OtelId == otelId);
         }
         return(bookings.ToList());
     }
 }
        public static void Initialize(ResitalContext context)
        {
            context.Database.EnsureDeleted();


            context.Database.EnsureCreated();

            // Look for any bookings.
            if (context.Booking.Any())
            {
                return;   // DB has been seeded
            }


            List <Room> rooms = new List <Room>
            {
                new Room {
                    Description = "A"
                },
                new Room {
                    Description = "B"
                },
                new Room {
                    Description = "C"
                }
            };

            DateTime       date     = DateTime.Today.AddDays(4);
            List <Booking> bookings = new List <Booking>
            {
                new Booking {
                    StartDate = date, EndDate = date.AddDays(14), IsActive = true, RoomId = 1
                },
                new Booking {
                    StartDate = date, EndDate = date.AddDays(14), IsActive = true, RoomId = 2
                },
                new Booking {
                    StartDate = date, EndDate = date.AddDays(14), IsActive = true, RoomId = 3
                }
            };


            context.Room.AddRange(rooms);
            context.SaveChanges();
            context.Booking.AddRange(bookings);
            context.SaveChanges();
        }
        public List <Room> GetRoomsByOtel(int otelId)
        {
            using (var context = new ResitalContext())
            {
                var rooms = context.Room.AsQueryable();
                //if (!string.IsNullOrEmpty(name))
                //{
                //    rooms = rooms
                //        .Include(i => i.Otel)
                //        .Where(i => i.OtelAd.ToLower() == name.ToLower());

                //}
                DateTime now = DateTime.Now.AddDays(-1);
                rooms = rooms.Include(x => x.Otel).Include(x => x.Bookings).Where(x => x.OtelId == otelId && !x.Bookings
                                                                                  .Any(i => i.StartDate <now && i.EndDate> now)); //oda boş ise
                return(rooms.ToList());
            }
        }
 public RoomRepository()
 {
     db = new ResitalContext();
 }
Exemplo n.º 5
0
 public BookingRepository()
 {
     db = new ResitalContext();
 }