Esempio n. 1
0
 public Room Get(int id)
 {
     using (HotelBookingContext ctx = new HotelBookingContext())
     {
         return(ctx.Rooms.FirstOrDefault(r => r.Id == id));
     }
 }
Esempio n. 2
0
 public IEnumerable <Room> GetAll()
 {
     using (HotelBookingContext ctx = new HotelBookingContext())
     {
         return(ctx.Rooms.ToList());
     }
 }
Esempio n. 3
0
 public IEnumerable <Booking> GetAll()
 {
     using (var ctx = new HotelBookingContext())
     {
         return(ctx.Bookings.Include(b => b.Customer).Include(b => b.Room).ToList());
     }
 }
Esempio n. 4
0
 public Booking Get(int id)
 {
     using (var ctx = new HotelBookingContext())
     {
         return(ctx.Bookings.FirstOrDefault(c => c.Id == id));
     }
 }
Esempio n. 5
0
 public IEnumerable <Customer> GetAll()
 {
     using (var ctx = new HotelBookingContext())
     {
         return(ctx.Customers.ToList());
     }
 }
Esempio n. 6
0
 public void Delete(int id)
 {
     using (var ctx = new HotelBookingContext())
     {
         var cus = ctx.Rooms.FirstOrDefault(x => x.Id == id);
         ctx.Rooms.Remove(cus);
         ctx.SaveChanges();
     }
 }
Esempio n. 7
0
 public Room Add(Room entity)
 {
     using (HotelBookingContext ctx = new HotelBookingContext())
     {
         Room newRoom = ctx.Rooms.Add(entity);
         ctx.SaveChanges();
         return(newRoom);
     }
 }
Esempio n. 8
0
        public Booking Add(Booking entity)
        {
            using (var ctx = new HotelBookingContext())
            {
                var result = ctx.Bookings.Add(entity);

                ctx.SaveChanges();

                return(result);
            }
        }
Esempio n. 9
0
        public Customer Add(Customer entity)
        {
            using (var ctx = new HotelBookingContext())
            {
                var result = ctx.Customers.Add(entity);

                ctx.SaveChanges();

                return(result);
            }
        }
Esempio n. 10
0
        public Room Update(Room entity)
        {
            using (HotelBookingContext ctx = new HotelBookingContext())
            {
                Room roomDB = ctx.Entry(entity).Entity;

                if (roomDB == null)
                {
                    return(null);
                }

                roomDB.Description = entity.Description;

                ctx.Entry(roomDB).State = EntityState.Modified;
                ctx.SaveChanges();
                return(roomDB);
            }
        }
Esempio n. 11
0
        public Customer Update(Customer entity)
        {
            using (var ctx = new HotelBookingContext())
            {
                Customer customerDB = ctx.Entry(entity).Entity;

                if (customerDB == null)
                {
                    return(null);
                }

                //var customerDB = ctx.Customers.FirstOrDefault(c => c.Id == customer.Id);
                customerDB.Email = entity.Email;
                customerDB.Name  = entity.Name;

                ctx.Entry(customerDB).State = EntityState.Modified;
                ctx.SaveChanges();
                return(customerDB);
            }
        }
Esempio n. 12
0
        public Booking Update(Booking entity)
        {
            using (var ctx = new HotelBookingContext())
            {
                Booking bookingDB = ctx.Entry(entity).Entity;

                if (bookingDB == null)
                {
                    return(null);
                }

                //var bookingDB = ctx.Bookings.FirstOrDefault(c => c.Id == booking.Id);
                bookingDB.IsActive   = entity.IsActive;
                bookingDB.StartDate  = entity.StartDate;
                bookingDB.EndDate    = entity.EndDate;
                bookingDB.RoomId     = entity.RoomId;
                bookingDB.CustomerId = entity.CustomerId;

                ctx.Entry(bookingDB).State = EntityState.Modified;
                ctx.SaveChanges();
                return(bookingDB);
            }
        }