Exemple #1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            try
            {
                var carBuilder   = new CarModelBuilder(new VINParserBase());
                var driverBulder = new DriverModelBuilder();

                var driver = EntityContextSingleton.FindDriverOrDefault(NameBox.Text, MiddleNameBox.Text, LastNameBox.Text);
                if (driver != null)
                {
                    driverBulder.WithId(driver.Id);
                }
                else
                {
                    new DriverCreatingForm().ShowDialog();
                    driver = EntityContextSingleton.FindDriverOrDefault(NameBox.Text, MiddleNameBox.Text, LastNameBox.Text);
                    driverBulder.WithId(driver.Id);
                }


                var completedCar = carBuilder
                                   .Color
                                   .WithColorCode(ColorBox.Text)
                                   .Model
                                   .WithManufacturer(0, ManufacturerBox.Text)
                                   .WithEngine(0, TypeOfEngine.Text)
                                   .Called(ModelBox.Text)
                                   .DriverType
                                   .WithType(DriveTypeBox.Text)
                                   .WithVIN(VINBox.Text)
                                   .WithYear(CarYearBox.Value.Year)
                                   .WithWeight(int.Parse(WeightBox.Text))
                                   .WithDriver(driverBulder)
                                   .Build();

                _controller.Insert(completedCar);
            }
            catch (Exception ex)
            {
                _controller.DialogService.ShowErrorMessage("Yay", ex.Message);
            }
            finally
            {
                _controller.DialogService.ShowMessage("Yay", "Yay");
            }
        }
        private void DoneButton_Click(object sender, EventArgs e)
        {
            try
            {
                Models.DriverModel driver = null;

                DriverModelBuilder driverBuilder = new DriverModelBuilder();
                if (DriverPhotoBox.Image == null)
                {
                    throw new Exception("Please upload driver photo !!!");
                }

                driver = driverBuilder
                         .WithId(0)
                         .WithName(NameBox.Text)
                         .WithMiddleName(MIddleNameBox.Text)
                         .WithLastName(LastNameBox.Text)
                         .WithDescription(DesriptionBox.Text)
                         .WithEmail(EmailBox.Text)
                         .WithPhone(PhoneBox.Text)
                         .WithImage(DriverPhotoBox.Image)
                         .Lives
                         .At(0, StreetBox.Text)
                         .WithHouseNumber(HouseNumberBox.Text)
                         .WithPostcode(PostcodeBox.Text)
                         .Works
                         .At(0, CompanyBox.Text)
                         .AsA(0, JobBox.Text)
                         .Passport
                         .WithSerial(int.Parse(PassportSerialBox.Text))
                         .WithNumber(int.Parse(PassportNumberBox.Text))
                         .Build();

                _controller.Insert(driver);
            }
            catch (Exception ex)
            {
                _controller.DialogService.ShowErrorMessage("ERROR", ex.Message);
            }
        }