Beispiel #1
0
        public async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            bool isNumber = int.TryParse(formCrewId.SelectedValue.ToString(), out int crewId);

            if (isNumber && formDateOfBirth.Date.HasValue)
            {
                Stewardess f = new Stewardess()
                {
                    Name        = formName.Text,
                    Surname     = formSurname.Text,
                    CrewId      = (crewId),
                    DateOfBirth = formDateOfBirth.Date.Value.Date
                };
                if (StewardessService.Validate(f))
                {
                    Form.Visibility = Visibility.Collapsed;
                    if (FormTitle.Text == "New Stewardess")
                    {
                        if (!await StewardessService.Add(f))
                        {
                            WrongInput.Visibility = Visibility.Visible;
                        }
                        WrongInput.Visibility = Visibility.Collapsed;
                        return;
                    }
                    if (FormTitle.Text == "Edit Stewardess")
                    {
                        if (!await StewardessService.Update(f))
                        {
                            WrongInput.Visibility = Visibility.Visible;
                        }
                        WrongInput.Visibility = Visibility.Collapsed;
                        return;
                    }
                }
            }
            WrongInput.Visibility = Visibility.Visible;
        }
        public async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            bool isNumber2 = int.TryParse(formExperience.Text, out int experience);
            bool isNumber3 = int.TryParse(formNumberOfSeats.Text, out int numberOfSeats);
            bool isNumber4 = int.TryParse(formLoadCapacity.Text, out int loadCapacity);

            if (formReleaseDate.Date.HasValue && isNumber2 && isNumber3 && isNumber4 &&
                formArrivalTime.Date.HasValue && formTimeOfDeparture.Date.HasValue && formDateOfBirth.Date.HasValue &&
                formTimeOfDeparture2.Date.HasValue)
            {
                Stewardess s = new Stewardess()
                {
                    Name        = formStewardessName.Text,
                    Surname     = formStewardessSurname.Text,
                    CrewId      = 1,
                    DateOfBirth = formDateOfBirth.Date.Value.Date
                };

                Pilot pil = new Pilot()
                {
                    Name       = formPilotName.Text,
                    Surname    = formPilotSurname.Text,
                    Experience = experience
                };

                Plane p = new Plane()
                {
                    ReleaseDate = formReleaseDate.Date.Value.Date,
                    PlaneType   = new PlaneType()
                    {
                        Model         = formModel.Text,
                        NumberOfSeats = numberOfSeats,
                        LoadCapacity  = loadCapacity
                    }
                };
                Flight f = new Flight()
                {
                    Destination     = formDestination.Text,
                    DepartureFrom   = formDepartureFrom.Text,
                    ArrivalTime     = formArrivalTime.Date.Value.Date,
                    TimeOfDeparture = formTimeOfDeparture.Date.Value.Date
                };



                Departure d = new Departure()
                {
                    Crew = new Crew()
                    {
                        Pilot        = pil,
                        Stewardesses = new List <Stewardess>()
                        {
                            s
                        }
                    },
                    Flight          = f,
                    Plane           = p,
                    TimeOfDeparture = formTimeOfDeparture2.Date.Value.Date
                };

                if (DepartureService.Validate(d))
                {
                    Form.Visibility = Visibility.Collapsed;
                    if (FormTitle.Text == "New Departure")
                    {
                        if (!await DepartureService.Add(d))
                        {
                            WrongInput.Visibility = Visibility.Visible;
                        }
                        WrongInput.Visibility = Visibility.Collapsed;
                        return;
                    }
                    if (FormTitle.Text == "Edit Departure")
                    {
                        if (!await DepartureService.Update(d))
                        {
                            WrongInput.Visibility = Visibility.Visible;
                        }
                        WrongInput.Visibility = Visibility.Collapsed;
                        return;
                    }
                }
            }
            WrongInput.Visibility = Visibility.Visible;
        }