当前位置: 首页>>代码示例>>C#>>正文


C# Models.Car类代码示例

本文整理汇总了C#中Cars.Models.Car的典型用法代码示例。如果您正苦于以下问题:C# Car类的具体用法?C# Car怎么用?C# Car使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Car类属于Cars.Models命名空间,在下文中一共展示了Car类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Import

        public void Import(string directoryPath)
        {
            var files = Directory.EnumerateFiles(directoryPath);

            foreach (var file in files)
            {
                using (var reader = new StreamReader(file))
                {
                    string json = reader.ReadToEnd();
                    var cars = JsonConvert.DeserializeObject<List<JsonCarModel>>(json);

                    foreach (var jsonCarModel in cars)
                    {
                        var newCar = new Car
                        {
                            Model = jsonCarModel.Model,
                            Year = jsonCarModel.Year,
                            Price = jsonCarModel.Price,
                            Dealer = GetOrCreateDealer(jsonCarModel.Dealer.Name),
                            Manufacturer = GetOrCreateManifacturer(jsonCarModel.ManufacturerName),
                            Transmission = GetOrCreateTransmission(jsonCarModel.TransmissionType)
                        };

                        _carsContext.Cars.Add(newCar);
                        _carsContext.SaveChanges();
                    }
                }
            }
        }
开发者ID:didimitrov,项目名称:Algo,代码行数:29,代码来源:DataJsonImporter.cs

示例2: ParseAllFiles

        public void ParseAllFiles()
        {
            Console.WriteLine("Importing cars from JSON");
            db.Configuration.AutoDetectChangesEnabled = false;
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("From file No {0}", i + 1);
                currentListOfCars = this.LoadFile(rootPath + "data." + i + ".json");
                var index = 0;
                foreach (var car in currentListOfCars)
                {
                    var currentCarToImport = new Car
                    {
                        Year = car.Year,
                        TransmissionType = (TransmissionType)car.TransmissionType,
                        Model = car.Model,
                        Price = car.Price
                    };
                    var manufacturer = this.db.Manufacturers.FirstOrDefault(m => m.Name == car.ManufacturerName);
                    if (manufacturer == null)
                    {
                        manufacturer = new Manufacturer
                        {
                            Name = car.ManufacturerName
                        };
                    }
                    currentCarToImport.Manufacturer = manufacturer;

                    var dealer = this.db.Dealers.FirstOrDefault(d => d.Name == car.Dealer.Name);
                    if (dealer == null)
                    {
                        dealer = new Dealer
                        {
                            Name = car.Dealer.Name
                        };
                    }
                    var city = this.db.Cities.FirstOrDefault(c => c.Name == car.Dealer.City);
                    if (city == null)
                    {
                        city = new City
                        {
                            Name = car.Dealer.City
                        };
                    }
                    dealer.Cities.Add(city);
                    currentCarToImport.Dealer = dealer;
                    db.Cars.Add(currentCarToImport);
                    db.SaveChanges();
                    index++;
                    if (index % 100 == 0)
                    {
                        Console.Write(".");
                    }
                }
                db.SaveChanges();
                Console.WriteLine("Importing from file No {0} finished!", i + 1);
            }
            db.Configuration.AutoDetectChangesEnabled = true;
            Console.WriteLine("Importing cars from JSON finished!");
        }
开发者ID:Elinos,项目名称:TelerikAcademy,代码行数:60,代码来源:JsonParser.cs

示例3: Main

        static void Main()
        {
            // Working!
            var db = new CarsDbContext();
            db.Configuration.AutoDetectChangesEnabled = false;

            for (int i = 0; i <= 4; i++)
            {
                var filePath = "../../../../JSONData/data." + i + ".json";
                var jsonText = File.ReadAllText(filePath);

                JArray allCars = JArray.Parse(jsonText);

                Console.WriteLine("Adding cars from file: {0}", filePath);
                int counter = 0;
                foreach (var car in allCars)
                {
                    Manufacturer newManufacturer = new Manufacturer
                    {
                        Name = car["ManufacturerName"].ToString()
                    };


                    Dealer newDealer = new Dealer
                    {
                        Name = car["Dealer"]["Name"].ToString()
                    };
                    newDealer.Cities.Add(new City { Name = car["Dealer"]["City"].ToString() });

                    Car newCar = new Car
                    {
                        Model = car["Model"].ToString(),
                        TransmisionType = int.Parse(car["TransmissionType"].ToString()),
                        Price = decimal.Parse(car["Price"].ToString()),
                        Year = int.Parse(car["Year"].ToString()),
                        Manufacturer = newManufacturer,
                        Dealer = newDealer
                    };

                    newManufacturer.Cars.Add(newCar);
                    newDealer.Cars.Add(newCar);

                    db.Manufacturers.Add(newManufacturer);
                    db.Dealers.Add(newDealer);
                    db.Cars.Add(newCar);
                    Console.Write(".");

                    if (counter % 100 == 0)
                    {
                        db.SaveChanges();
                    }

                    counter++;
                }
                db.SaveChanges();
                Console.WriteLine("\nFile Read Complete -> All Cars where added successfuly!");
                Console.WriteLine("\n");
            }
            db.Configuration.AutoDetectChangesEnabled = false;
        }
开发者ID:nzhul,项目名称:TelerikAcademy,代码行数:60,代码来源:Program.cs

示例4: SeedDataFromJsonObjects

        public void SeedDataFromJsonObjects(IList<CarMap> jsonObjects)
        {
            Console.WriteLine("Seed JSON objects to MSSQL Database...");

            for (int i = 0; i < jsonObjects.Count; i++)
            {
                var jsonObj = jsonObjects[i];

                var car = new Car()
                {
                    Year = jsonObj.Year,
                    TransmissionType = (TransmissionType)jsonObj.TransmissionType,
                    Manufacturer = this.GetOrCreateManufacturer(jsonObj.ManufacturerName),
                    Model = jsonObj.Model,
                    Price = (decimal)jsonObj.Price,
                    Dealer = this.GetDealer(jsonObj.Dealer)
                };

                this.carsDbContext.Cars.Add(car);

                if (i % 100 == 0)
                {
                    Console.Write(".");
                    this.carsDbContext.SaveChanges();
                }
            }

            this.carsDbContext.SaveChanges();

            Console.WriteLine("\nJSON Objects were deserialized and seeded to database sucessfully!\n");
        }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:31,代码来源:DatabaseSeeder.cs

示例5: ExpectAddingCarsInRepoThenReturnSortedByYearToHaveCorrectResults

        public void ExpectAddingCarsInRepoThenReturnSortedByYearToHaveCorrectResults()
        {
            byte specialCounter = 20;
            short[] years = { 2013, 2001, 2004, 2000, 2010 };

            List<int> expectedResultYears = new List<int>();
            this.fakeCarsData.Remove(new Car());

            for (var i = 0; i < specialCounter; i++)
            {
                var vartburg = new Car()
                {
                    Id = (i + 1) * 1945,
                    Make = "GDR2",
                    Model = "Kombi" + i,
                    Year = years[i % years.Length]
                };

                this.controller.Add(vartburg);
                expectedResultYears.Add(vartburg.Year);
            }

            var collection = (IList<Car>)this.GetModel(() => this.controller.Sort("year"));

            expectedResultYears.Sort();

            for (int car = 0; car < expectedResultYears.Count; car++)
            {
                Assert.AreEqual(expectedResultYears[car], collection[car].Year);
            }
        }
开发者ID:kiko81,项目名称:Teleric-Academy-Homeworks,代码行数:31,代码来源:MissingTests.cs

示例6: GenerateDealerXElement

        private XElement GenerateDealerXElement(Car car, XElement carDealerCitiesXml)
        {
            var dealerXml = new XElement("Dealer",
                new XAttribute("Name", car.Dealer.Name),
                carDealerCitiesXml);

            return dealerXml;
        }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:8,代码来源:XmlQueryWriter.cs

示例7: Remove

        public void Remove(Car car)
        {
            if (car == null)
            {
                throw new ArgumentNullException("car", "Cannot remove null car.");
            }

            this.Data.Cars.Remove(car);
        }
开发者ID:EBojilova,项目名称:CSharpHQC,代码行数:9,代码来源:CarRepository.cs

示例8: Add

        public void Add(Car car)
        {
            if (car == null)
            {
                throw new ArgumentNullException("car", "Cannot add null car.");
            }

            this.Data.Cars.Add(car);
        }
开发者ID:EBojilova,项目名称:CSharpHQC,代码行数:9,代码来源:CarRepository.cs

示例9: Add

        public void Add(Car car)
        {
            if (car == null)
            {
                throw new ArgumentException("Null car cannot be added");
            }

            this.Data.Cars.Add(car);
        }
开发者ID:Xristinaaaa,项目名称:Telerik2016,代码行数:9,代码来源:CarsRepository.cs

示例10: Remove

        public void Remove(Car car)
        {
            if (car == null)
            {
                throw new ArgumentException("Null car cannot be removed");
            }

            this.Data.Cars.Remove(car);
        }
开发者ID:Xristinaaaa,项目名称:Telerik2016,代码行数:9,代码来源:CarsRepository.cs

示例11: GenerateCarXElement

        private XElement GenerateCarXElement(Car car)
        {
            var carXml = new XElement("Car",
                new XAttribute("Manufacturer", car.Manufacturer.Name),
                new XAttribute("Model", car.Model),
                new XAttribute("Year", car.Year),
                new XAttribute("Price", Math.Round(car.Price, 2)),
                new XElement("TransmissionType", car.TransmissionType.ToString().ToLower()));

            return carXml;
        }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:11,代码来源:XmlQueryWriter.cs

示例12: AddingCarShouldReturnADetail

        public void AddingCarShouldReturnADetail()
        {
            var car = new Car { Id = 15, Make = "BMW", Model = "330d", Year = 2014 };

            var model = (Car)GetModel(() => this.controller.Add(car));

            Assert.AreEqual(1, model.Id);
            Assert.AreEqual("Audi", model.Make);
            Assert.AreEqual("A4", model.Model);
            Assert.AreEqual(2005, model.Year);
        }
开发者ID:hrist0stoichev,项目名称:Telerik-Homeworks,代码行数:11,代码来源:CarsControllerTests.cs

示例13: GenerateCityXElement

        private XElement GenerateCityXElement(Car car)
        {
            var carDealerCitiesXml = new XElement("Cities");

            foreach (var carDealerCity in car.Dealer.Cities)
            {
                var cityXml = new XElement("City", carDealerCity.Name);
                carDealerCitiesXml.Add(cityXml);
            }

            return carDealerCitiesXml;
        }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:12,代码来源:XmlQueryWriter.cs

示例14: AddingCarShouldThrowArgumentNullExceptionIfCarMakeIsNull

        public void AddingCarShouldThrowArgumentNullExceptionIfCarMakeIsNull()
        {
            var car = new Car
            {
                Id = 15,
                Make = "",
                Model = "330d",
                Year = 2014
            };

            var model = (Car)this.GetModel(() => this.controller.Add(car));
        }
开发者ID:Alex223124,项目名称:High-Quality-Code,代码行数:12,代码来源:CarsControllerTests.cs

示例15: Create

        public ActionResult Create(CarInputModel model)
        {
            if (ModelState.IsValid && model!=null)
            {
                var allShippersNames = Data.Shippers.All().Select(x => x.Name);

                if (model.ShipperName!=null && !allShippersNames.Contains(model.ShipperName))
                {
                    var newShipper = new Shipper
                    {
                        Name = model.ShipperName
                    };
                    Data.Shippers.Add(newShipper);
                    Data.SaveChanges();

                    var newCar = new Car
                    {
                        Id = model.Id,
                        Brand = model.Brand,
                        Description = model.Description,
                        Power = model.Power,
                        ShipperId = newShipper.Id,
                        Year = model.Year
                    };
                    _cars.Add(newCar);
                    _cars.SaveChanges();

                    return RedirectToAction("Index");
                }

                if (allShippersNames.Contains(model.ShipperName))
                {
                    var shipperId = Data.Shippers.All().SingleOrDefault(x => x.Name == model.ShipperName).Id;
                    var newCar = new Car
                    {
                        Id = model.Id,
                        Brand = model.Brand,
                        Description = model.Description,
                        Power = model.Power,
                        ShipperId = shipperId,
                        Year = model.Year
                    };

                    _cars.Add(newCar);
                    _cars.SaveChanges();

                    return RedirectToAction("Index");
                }
            }
            return View();
        }
开发者ID:didimitrov,项目名称:Cars,代码行数:51,代码来源:CarsController.cs


注:本文中的Cars.Models.Car类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。