Ejemplo n.º 1
0
        protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            ICar car = new Car();
            car.Extres = new Extra();
            car.Producer = Server.HtmlEncode(this.DropDownListProducers.Text);
            car.Model = Server.HtmlEncode(this.DropDownListModels.Text);
            var extras = this.CheckBoxListExtres.Items;
            var engineTypes = this.RadioButtonListEnginType.Items;
            for (int i = 0; i < engineTypes.Count; i++)
            {
                if (engineTypes[i].Selected)
                {
                    car.EngineType = (EngineType)Enum.Parse(typeof(EngineType), engineTypes[i].Value);
                    break;
                }
            }

            for (int i = 0; i < extras.Count; i++)
            {
                if (extras[i].Selected)
                {
                    switch (extras[i].Value)
                    {
                        case "Alarm": car.Extres.HasAlarm = true; break;
                        case "Air Condition": car.Extres.HasAirCondition = true; break;
                        case "Electrical Glasses": car.Extres.HasElectricalGlasses = true; break;
                    }
                }
            }

            DisplayResult(car);
        }
Ejemplo n.º 2
0
        private static Car GetCarFromCarView(
            CarView carView,
            Dictionary<string, Manufacturer> manufacturers,
            Dictionary<string, Dealer> dealers,
            Dictionary<string, City> cities)
        {
            var car = new Car()
            {
                Year = carView.Year,
                TransmissionType = carView.TransmissionType,
                Model = carView.Model,
                Price = carView.Price,
            };

            var dealerName = carView.Dealer.Name;
            var cityName = carView.Dealer.City;
            var manufacturerName = carView.ManufacturerName;

            Dealer dealer = dealers.ContainsKey(dealerName) ? dealers[dealerName] : new Dealer() { Name = dealerName };
            City city = cities.ContainsKey(cityName) ? cities[cityName] : new City() { Name = cityName };
            Manufacturer manufacturer = manufacturers.ContainsKey(manufacturerName) ? manufacturers[manufacturerName] : new Manufacturer() { Name = manufacturerName };

            dealer.Cities.Add(city);
            car.Dealer = dealer;
            car.Manufacturer = manufacturer;

            if (!manufacturers.ContainsKey(manufacturer.Name))
            {
                manufacturers.Add(manufacturer.Name, manufacturer);
            }

            if (!dealers.ContainsKey(manufacturer.Name))
            {
                dealers.Add(dealer.Name, dealer);
            }

            if (!cities.ContainsKey(city.Name))
            {
                cities.Add(city.Name, city);
            }

            return car;
        }