コード例 #1
0
ファイル: Reservation.cs プロジェクト: MantasSidabras/Hotel
 public Reservation(HotelDbEntities context)
 {
     _context = context;
 }
コード例 #2
0
ファイル: Menu.cs プロジェクト: MantasSidabras/Hotel
 public Menu(HotelDbEntities context, Reservation reservation)
 {
     _context     = context;
     _reservation = reservation;
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: MantasSidabras/Hotel
        static void Main(string[] args)
        {
            HotelDbEntities context     = new HotelDbEntities();
            Reservation     reservation = new Reservation(context);
            Menu            menu        = new Menu(context, reservation);

            SqlConnection con = new SqlConnection(conString);

            Service service = new Service(con);
            //service.DeleteAmenity(context.Rooms.Take(1).FirstOrDefault(), "Breakfast");


            var guests = new List <Person>();

            //reservation.ReserveRoom(guests, context.Rooms.FirstOrDefault(), DateTime.Now, DateTime.Now.AddDays(1));
            int      input;
            Room     room         = new Room();
            DateTime CheckInDate  = DateTime.MinValue;
            DateTime CheckOutDate = DateTime.MinValue;

            do
            {
                menu.DisplayCurrentSetup(room, guests, CheckInDate, CheckOutDate);
                menu.DisplayAvailableRooms();

                menu.DisplayOptions();

                int.TryParse(Console.ReadLine(), out input);

                int roomNumber = 0;

                switch (input)
                {
                case 1:
                    Console.WriteLine("Select available room");

                    int.TryParse(Console.ReadLine(), out roomNumber);
                    if (roomNumber != 0)
                    {
                        room = context.Rooms.Where(x => x.Nr == roomNumber).Select(x => x).FirstOrDefault();
                    }
                    break;

                case 2:
                    Console.Clear();
                    Console.WriteLine("Enter first name:");
                    string firstName = Console.ReadLine();
                    Console.WriteLine("Enter last name:");
                    string lastName = Console.ReadLine();
                    Console.WriteLine("Enter personal code:");
                    string personalCode = Console.ReadLine();
                    guests.Add(new Person()
                    {
                        FirstName = firstName, LastName = lastName, PersonalCode = personalCode
                    });
                    break;

                case 3:
                    menu.DisplayAmenitiesOptions();
                    int select;
                    int.TryParse(Console.ReadLine(), out select);
                    switch (select)
                    {
                    case 1:
                        Console.WriteLine("Enter name of amenity");
                        var name = Console.ReadLine();
                        Console.WriteLine("Enter price");
                        var price = double.Parse(Console.ReadLine());
                        Console.WriteLine("Select room number");
                        var num = int.Parse(Console.ReadLine());


                        service.AddAmenity(context.Rooms.Where(x => x.Nr == num).Select(x => x).FirstOrDefault(), name, price);
                        break;

                    case 2:
                        Console.WriteLine("Select room number");
                        var num2 = int.Parse(Console.ReadLine());
                        Console.WriteLine("Enter name of amenity");
                        var name2 = Console.ReadLine();
                        service.DeleteAmenity(context.Rooms.Where(x => x.Nr == num2).Select(x => x).FirstOrDefault(), name2);
                        break;

                    case 3:
                        Console.WriteLine("Select room number");
                        var num3 = int.Parse(Console.ReadLine());
                        Console.WriteLine("Enter name of amenity");
                        var name3 = Console.ReadLine();
                        Console.WriteLine("Enter new room number");
                        var roomId = int.Parse(Console.ReadLine());
                        service.UpdateAmenity(context.Rooms.Where(x => x.Nr == num3).Select(x => x).FirstOrDefault(), name3, context.Rooms.Where(x => x.Nr == roomId).Select(x => x).FirstOrDefault());
                        break;

                    default:
                        break;
                    }

                    break;

                case 4:
                    Console.WriteLine("Check in date: ");
                    DateTime.TryParse(Console.ReadLine(), out CheckInDate);
                    Console.WriteLine("Check out date: ");
                    DateTime.TryParse(Console.ReadLine(), out CheckOutDate);
                    break;


                case 5:
                    Console.Clear();
                    if (CheckInDate != DateTime.MinValue && guests.Capacity != 0)
                    {
                        var reservationConfirmed = reservation.ReserveRoom(guests, room, CheckInDate, CheckOutDate);
                        if (reservationConfirmed)
                        {
                            Console.Clear();
                            Console.WriteLine("reservation successful");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Failed to register. Make sure to fill all fields.");
                    }
                    break;

                case 6:
                    Console.WriteLine("Select room number to free up");
                    int roomNum = int.Parse(Console.ReadLine());
                    reservation.RemoveGuests(roomNum);
                    break;

                case 7:
                    break;

                default:
                    break;

                case 8:
                    Console.Clear();
                    menu.DisplayAllRooms();
                    break;

                case 9:
                    Console.Clear();
                    menu.ViewAllGuests();
                    break;

                case 10:
                    Console.WriteLine("Select room nr to change price");
                    int rNr = int.Parse(Console.ReadLine());
                    Console.WriteLine("Enter new price");
                    double newPrice = double.Parse(Console.ReadLine());
                    reservation.UpdateRoom(rNr, newPrice);
                    break;

                case 11:
                    menu.DisplayMostUsedRooms();

                    break;

                case 12:
                    Console.WriteLine("Enter guests first or second name");
                    var   searchKey  = Console.ReadLine();
                    Guest guestFound = reservation.SearchGuest(searchKey);
                    if (guestFound != null)
                    {
                        Console.WriteLine($"Guest {guestFound.FirstName} {guestFound.LastName} was found in {context.Rooms.Where(x => x.Id == guestFound.RoomId).FirstOrDefault().Nr} room");
                    }
                    else
                    {
                        Console.WriteLine("Guest not found");
                    }
                    break;

                case 13:
                    menu.DisplayMostExpensiveAmenities();
                    break;
                }
            } while (input != 22);
        }