예제 #1
0
        public List <Room> GetRoomsAvailable(DateTime Datum1, DateTime Datum2)
        {
            var Lista   = new List <Room>();
            var IntList = new List <int>();
            var Rooms   = GetRooms();

            var StartDate = Datum1.Date;
            var EndDate   = Datum2.Date;

            using (var db = new HotelCaliforniaEntities())
            {
                foreach (var Book in db.Bookings)
                {
                    if (((StartDate >= Book.DateStart && StartDate < Book.DateEnd) ||
                         (EndDate > Book.DateStart && EndDate <= Book.DateEnd)) ||
                        ((Book.DateStart >= StartDate && Book.DateStart < EndDate) ||
                         (Book.DateEnd > StartDate && Book.DateEnd <= EndDate)))
                    {
                        IntList.Add(Book.RoomID);
                    }
                }
                Lista = db.Rooms.Where(x => !IntList.Contains(x.RoomID)).ToList();
            }

            return(Lista);
        }
예제 #2
0
        public bool CheckRoomAvailable(int CustomerID, Room R, DateTime Datum1, DateTime Datum2)
        {
            var  StartDate = Datum1.Date;
            var  EndDate   = Datum2.Date;
            bool Booked    = true;

            using (var db = new HotelCaliforniaEntities())
            {
                foreach (var Book in db.Bookings)
                {
                    if (((StartDate >= Book.DateStart && StartDate < Book.DateEnd) ||
                         (EndDate > Book.DateStart && EndDate <= Book.DateEnd)) ||
                        ((Book.DateStart >= StartDate && Book.DateStart < EndDate) ||
                         (Book.DateEnd > StartDate && Book.DateEnd <= EndDate)))
                    {
                        if ((Book.CustomerID != CustomerID) && (Book.RoomID == R.RoomID))
                        {
                            Booked = false;
                        }
                    }
                    else
                    {
                        Booked = true;
                    }
                }
            }
            return(Booked);
        }
예제 #3
0
 public void UpdateBooking(Booking B)
 {
     using (var db = new HotelCaliforniaEntities())
     {
         db.Bookings.AddOrUpdate(B);
         db.SaveChanges();
     }
 }
예제 #4
0
 public void AddCustomer(Customer C)
 {
     using (var Data = new HotelCaliforniaEntities())
     {
         Data.Customers.Add(C);
         Data.SaveChanges();
     }
 }
예제 #5
0
 public void BookARoom(Booking B)
 {
     using (var db = new HotelCaliforniaEntities())
     {
         db.Bookings.Add(B);
         db.SaveChanges();
     }
 }
예제 #6
0
 public void DeleteCustomer(Customer C)
 {
     using (var db = new HotelCaliforniaEntities())
     {
         var Item = db.Customers.SingleOrDefault(x => x.CustomerID == C.CustomerID);
         db.Customers.Remove(Item);
         db.SaveChanges();
     }
 }
예제 #7
0
        public Room GetRoom(int Room_ID)
        {
            var R = new Room();

            using (var db = new HotelCaliforniaEntities())
            {
                R = (from r in db.Rooms where r.RoomID == Room_ID select r).FirstOrDefault();
            }
            return(R);
        }
예제 #8
0
        public Customer FindACustomer(int id)
        {
            var C = new Customer();

            using (HotelCaliforniaEntities db = new HotelCaliforniaEntities())
            {
                C = db.Customers.Where(x => x.CustomerID == id).FirstOrDefault();
            }
            return(C);
        }
예제 #9
0
        public List <Room> GetRooms()
        {
            var Lista = new List <Room>();

            using (var db = new HotelCaliforniaEntities())
            {
                Lista = (from R in db.Rooms select R).ToList();
            }

            return(Lista);
        }
예제 #10
0
 public void ChangeCustomer(Customer C)
 {
     using (var Data = new HotelCaliforniaEntities())
     {
         var Item = Data.Customers.First(a => a.CustomerID == C.CustomerID);
         Item.FirstName = C.FirstName;
         Item.LastName  = C.LastName;
         Item.PersonID  = C.PersonID;
         Data.SaveChanges();
     }
 }
예제 #11
0
        public Booking GetBooking(int id)
        {
            var B = new Booking();

            using (HotelCaliforniaEntities db = new HotelCaliforniaEntities())
            {
                B = (from b in db.Bookings
                     where b.BookingID == id
                     select b).FirstOrDefault();
            }
            return(B);
        }
예제 #12
0
        public List <Booking> GetBookings(Customer C)
        {
            var Lista = new List <Booking>();

            using (HotelCaliforniaEntities db = new HotelCaliforniaEntities())
            {
                Lista = (from b in db.Bookings
                         join c in db.Customers
                         on b.CustomerID equals c.CustomerID
                         where b.CustomerID == C.CustomerID
                         select b).ToList();
            }
            return(Lista);
        }
예제 #13
0
        public bool CheckPersonID(Customer c)
        {
            var C = new List <Customer>();

            using (HotelCaliforniaEntities db = new HotelCaliforniaEntities())
            {
                C = db.Customers.Where(x => x.PersonID == c.PersonID && x.CustomerID != c.CustomerID).ToList();
            }
            if (C.Count < 1)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #14
0
        public void CreateInvoice(Booking B)
        {
            var     Get   = new GetData();
            Room    R     = Get.GetRoom(int.Parse(B.RoomID.ToString()));
            decimal Price = decimal.Parse(((B.DateEnd - B.DateStart).TotalDays * R.Price).ToString());
            var     I     = new Invoice();

            I.BookingID  = B.BookingID;
            I.Complete   = 0;
            I.BookedDate = DateTime.Now;
            I.TotalPrice = Price;

            using (var db = new HotelCaliforniaEntities())
            {
                db.Invoices.Add(I);
                db.SaveChanges();
            }
        }
예제 #15
0
        public List <Customer> FindCustomer(string name)
        {
            using (HotelCaliforniaEntities db = new HotelCaliforniaEntities())
            {
                List <Customer> Lista = new List <Customer>();

                if (name.Length < 1)
                {
                    Lista = (from c in db.Customers select c).ToList();
                }
                else
                {
                    Lista = (from c in db.Customers
                             where c.FirstName.Contains(name)
                             select c).ToList();
                }
                return(Lista);
            }
        }
예제 #16
0
        public void DeleteBooking(Booking B)
        {
            using (var db = new HotelCaliforniaEntities())
            {
                var Item = db.Bookings.SingleOrDefault(x => x.BookingID == B.BookingID);
                db.Bookings.Remove(Item);

                var Invoice = db.Invoices.SingleOrDefault(x => x.BookingID == B.BookingID);

                if (Invoice == null)
                {
                    db.SaveChanges();
                }
                else
                {
                    db.Invoices.Remove(Invoice);
                    db.SaveChanges();
                }
            }
        }