Ejemplo n.º 1
0
        static void fillReservationList()
        {
            string jsonText = File.ReadAllText("reservations.json");

            using (JsonDocument document = JsonDocument.Parse(jsonText))
            {
                JsonElement root            = document.RootElement;
                JsonElement reservationList = root;

                foreach (JsonElement ticket in reservationList.EnumerateArray())
                {
                    if (ticket.TryGetProperty("ReservationCode", out JsonElement ReservationCodeElement) &&
                        ticket.TryGetProperty("CustomerName", out JsonElement CustomerNameElement) &&
                        ticket.TryGetProperty("CustomerEmail", out JsonElement CustomerEmailElement) &&
                        ticket.TryGetProperty("MovieName", out JsonElement MovieNameElement) &&
                        ticket.TryGetProperty("NumberOfPeople", out JsonElement NumberOfPeopleElement) &&
                        ticket.TryGetProperty("IsVip", out JsonElement IsVipElement) &&
                        ticket.TryGetProperty("TotalPrice", out JsonElement TotalPriceElement) &&
                        ticket.TryGetProperty("SelectedSeat", out JsonElement SelectedSeatElement) &&
                        ticket.TryGetProperty("SelectedRow", out JsonElement SelectedRowElement))
                    {
                        string reservationCode = ReservationCodeElement.GetString();

                        string customerName   = CustomerNameElement.GetString();
                        string customerEmail  = CustomerEmailElement.GetString();
                        string movieName      = MovieNameElement.GetString();
                        int    numberOfPeople = NumberOfPeopleElement.GetInt32();
                        bool   isVip          = IsVipElement.GetBoolean();
                        double totalPrice     = TotalPriceElement.GetDouble();
                        int    selectedRow    = SelectedRowElement.GetInt32();
                        int    selectedSeat   = SelectedSeatElement.GetInt32();


                        Movies tempMovie = movies.Find(x => x.MovieName == movieName);

                        Ticket fillTicket = new Ticket(tempMovie, numberOfPeople, isVip, selectedRow, selectedSeat);
                        fillTicket.CustomerName    = customerName;
                        fillTicket.CustomerEmail   = customerEmail;
                        fillTicket.ReservationCode = reservationCode;
                        reservations.Add(fillTicket);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void cancelReservation()
        {
            Console.WriteLine("Weet u zeker dat u uw reservering wilt annuleren? (y/n)");
            string userChoice = "";

            while (userChoice != "y" || userChoice != "Y")
            {
                userChoice = Console.ReadLine();

                switch (userChoice)
                {
                case "Y":
                case "y":
                    Console.WriteLine("Wat is uw reserveringscode (Let op: hoofdletter gevoelig!):");
                    string reservationCodeCustomer = Console.ReadLine();
                    bool   reservationExists       = false;

                    string jsonText = File.ReadAllText("reservations.json");
                    using (JsonDocument document = JsonDocument.Parse(jsonText))
                    {
                        JsonElement root            = document.RootElement;
                        JsonElement reservationList = root;
                        reservations.Clear();
                        foreach (JsonElement ticket in reservationList.EnumerateArray())
                        {
                            if (ticket.TryGetProperty("ReservationCode", out JsonElement ReservationCodeElement) &&
                                ticket.TryGetProperty("CustomerName", out JsonElement CustomerNameElement) &&
                                ticket.TryGetProperty("CustomerEmail", out JsonElement CustomerEmailElement) &&
                                ticket.TryGetProperty("MovieName", out JsonElement MovieNameElement) &&
                                ticket.TryGetProperty("NumberOfPeople", out JsonElement NumberOfPeopleElement) &&
                                ticket.TryGetProperty("IsVip", out JsonElement IsVipElement) &&
                                ticket.TryGetProperty("TotalPrice", out JsonElement TotalPriceElement) &&
                                ticket.TryGetProperty("SelectedSeat", out JsonElement SelectedSeatElement) &&
                                ticket.TryGetProperty("SelectedRow", out JsonElement SelectedRowElement))
                            {
                                string reservationCode = ReservationCodeElement.GetString();
                                if (reservationCode == reservationCodeCustomer)
                                {
                                    int    numberOfPeople = NumberOfPeopleElement.GetInt32();
                                    int    selectedRow    = SelectedRowElement.GetInt32();
                                    int    selectedSeat   = SelectedSeatElement.GetInt32();
                                    string movieName      = MovieNameElement.GetString();
                                    Movies movieToCancel  = movies.Find(x => x.MovieName == movieName);
                                    movieToCancel.cancelReservation(selectedRow - 1, selectedSeat - 1, numberOfPeople);
                                    movieToCancel.saveMovieScreenJson();

                                    Console.WriteLine("Uw reservering is geannuleerd!");
                                    reservationExists = true;
                                }
                                else
                                {
                                    string customerName   = CustomerNameElement.GetString();
                                    string customerEmail  = CustomerEmailElement.GetString();
                                    string movieName      = MovieNameElement.GetString();
                                    int    numberOfPeople = NumberOfPeopleElement.GetInt32();
                                    bool   isVip          = IsVipElement.GetBoolean();
                                    double totalPrice     = TotalPriceElement.GetDouble();
                                    int    selectedRow    = SelectedRowElement.GetInt32();
                                    int    selectedSeat   = SelectedSeatElement.GetInt32();

                                    Movies tempMovie = movies.Find(x => x.MovieName == movieName);

                                    Ticket fillTicket = new Ticket(tempMovie, numberOfPeople, isVip, selectedRow, selectedSeat);
                                    fillTicket.CustomerName    = customerName;
                                    fillTicket.CustomerEmail   = customerEmail;
                                    fillTicket.ReservationCode = reservationCode;
                                    reservations.Add(fillTicket);
                                }
                            }
                        }

                        JsonSerializerOptions options = new JsonSerializerOptions();
                        options.WriteIndented = true;
                        var jsonString = JsonSerializer.Serialize(reservations, options);
                        File.WriteAllText("reservations.json", jsonString);

                        if (reservationExists == false)
                        {
                            Console.WriteLine("Onbekend reserveringsnummer!");
                        }
                    }
                    choiceMenu();
                    break;

                case "N":
                case "n":
                    choiceMenu();
                    break;

                default:
                    Console.WriteLine("Voer a.u.b. uw keuze in: ");
                    break;
                }
            }
        }