• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Models.Car类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Add

        public IView Add(Car car)
        {
            if (car== null)
            {
                throw new ArgumentNullException("car","Car cannot be null.");
            }

            if (string.IsNullOrEmpty(car.Make)||(string.IsNullOrEmpty(car.Model)))
            {
                throw new ArgumentOutOfRangeException("car", "Car make and model can not be empty.");
            }
            this.carsData.Add(car);
            return this.Details(car.Id);
        }
开发者ID:EBojilova,项目名称:CSharpHQC,代码行数:14,代码来源:CarsController.cs


示例17: Add_ShouldAddCarToCarRepository

        public void Add_ShouldAddCarToCarRepository()
        {
            // Arrange
            var car = new Car { Id = 1, Make = "Audi", Model = "A5", Year = 2005 };
            var db = new Database();
            db.Cars = new List<Car>();
            var count = db.Cars.Count;
            var carsRepository = new CarsRepository(db);

            // Act
            carsRepository.Add(car);

            // Assert
            Assert.AreEqual(1, db.Cars.Count);
        }
开发者ID:todor-enikov,项目名称:TelerikAcademy,代码行数:15,代码来源:CarsRepositoryTests.cs


示例18: GetById_ShouldFindCarById

        public void GetById_ShouldFindCarById()
        {
            // Arrange
            var car = new Car { Id = 1, Make = "Audi", Model = "A5", Year = 2005 };
            var mock = new Mock<IDatabase>();
            mock.Setup(m => m.Cars).Returns(new List<Car>() { });
            var fakeDB = mock.Object;
            fakeDB.Cars.Add(car);
            var carsRepository = new CarsRepository(fakeDB);

            // Act
            var result = carsRepository.GetById(1);

            // Assert
            mock.Verify(m => m.Cars, Times.Exactly(2));
        }
开发者ID:todor-enikov,项目名称:TelerikAcademy,代码行数:16,代码来源:CarsRepositoryTests.cs


示例19: AddShouldReturnDetail

        public void AddShouldReturnDetail()
        {
            Car car = new Car()
            {
                Id = 15,
                Make = "Audi",
                Model = "A4",
                Year = 2005
            };

            var view = this.controller.Add(car);
            var model = (Car)view.Model;

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


示例20: Add

        public IView Add(Car car)
        {
            if (car == null)
            {
                throw new ArgumentNullException("car", "Car cannot be null");
            }

            if (string.IsNullOrEmpty(car.Make) || string.IsNullOrEmpty(car.Model))
            {
                throw new ArgumentNullException("car", "Car make and model cannot be empty");
            }

            // homework add year validation
            if (1900 > car.Year || car.Year > DateTime.Now.Year)
            {
                throw new ArgumentOutOfRangeException("car", "Car year is invalid");
            }

            this.carsData.Add(car);
            return this.Details(car.Id);
        }
开发者ID:VDGone,项目名称:TelerikAcademy-1,代码行数:21,代码来源:CarsController.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cassandra.Session类代码示例发布时间:2022-05-24
下一篇:
C# Data.CarrotCMSDataContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap