private static void Generate02Inserts(ISession session) { var newCar = new NewCar() { AvailableFrom = DateTime.Now, ConstructionDate = DateTime.Now, Manufacturer = "BMW", StickerPrice = 130000, VIN = "123456789", WasRefreshed = true }; var usedCar = new UsedCar() { Manufacturer = "BMW", VIN = "23456789", ConstructionDate = DateTime.Now, StickerPrice = 130000, IsFirstOwner = true, LastOwnerName = "Jan", LastOwnerSurname = "Kowalski" }; session.Save(newCar); session.Save(usedCar); }
private void DisplayCars(List <Car> cars) { try { lstCars.Items.Clear(); float total = 0f; float currentValue = 0f; foreach (Car car in cars) { string info = $"License Plate: {car.LicensePlateNo}, Make: {car.Make}, Type: {car.CarType}, Purchase Price: {car.PurchasePrice}"; total += (float)car.PurchasePrice; if (car.GetType() == typeof(UsedCar)) { UsedCar usedCar = (UsedCar)car; info += $", Model: {usedCar.Model}, Mileage: {usedCar.Mileage}, Insurance Depreciation: {usedCar.InsuranceDepreciation}, Total Depreciation: {usedCar.TotalDepreciation}"; currentValue += (float)(usedCar.PurchasePrice - (float)(usedCar.TotalDepreciation * (float)usedCar.PurchasePrice)); } else { currentValue += (float)car.PurchasePrice; } lstCars.Items.Add(info); } txtTotalPrice.Text = total.ToString("F2"); txtCurrentValue.Text = currentValue.ToString("F2"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public UsedCar Delete(UsedCar car) { MongoClient client = new MongoClient("mongodb://localhost:27017"); IMongoDatabase database = client.GetDatabase("UsedCars"); var collection = database.GetCollection <Entity>("Cars"); BsonDocument findCarDoc = new BsonDocument(new BsonElement(car)); return(collection.FindOneAndDelete(findCarDoc)); }
public ActionResult <UsedCar> Get(int id) { UsedCar car = _manager.GetById(id); if (car == null) { return(NotFound("No car with id: " + id)); } return(Ok(car)); }
static async void Insert(UsedCar car) { MongoClient client = new MongoClient("mongodb://localhost:27017"); IMongoDatabase database = client.GetDatabase("UsedCars"); var collection = database.GetCollection <Entity>("Cars"); await collection.InsertOneAsync(new Entity { _id = ObjectId.GenerateNewId(), Model = car.Model, Description = car.Description, Year = car.Year, Brand = car.Brand, Kilometers = car.Kilometers, Predicate = car.Price }); }
static void Main() { Console.OutputEncoding = Encoding.UTF8; SellController sellController = new SellController(); Car car = new Car() { Model = "Ford Focus II", IssueYear = 2007, Price = "245 000 руб", Equipment = "Хэтчбек 5 дв.", ProducingCountry = "Россия", SaleDate = DateTime.Now, Buyer = "Иванов Иван Иванович" }; Car car1 = new SportCar() { Seconds = "5", EngineDisplacement = "5 литров", Power = "200 лошадиных сил", Model = "Ford Focus II", IssueYear = 2007, Price = "245 000 руб", Equipment = "Хэтчбек 5 дв.", ProducingCountry = "Россия", SaleDate = DateTime.Now, Buyer = "Иванов Иван Иванович" }; Car car2 = new UsedCar() { SafetyDegree = "Не битая", Owner = "Петров Петр Петрович", Mileage = "100 000 км", Model = "Ford Focus II", IssueYear = 2007, Price = "245 000 руб", Equipment = "Хэтчбек 5 дв.", ProducingCountry = "Россия", SaleDate = DateTime.Now, Buyer = "Иванов Иван Иванович" }; sellController.SellCar(car); sellController.SellCar(car1); sellController.SellCar(car2); sellController.PrintList(); }
public CarRepository() { var ctx = HttpContext.Current; if (ctx != null) { if (ctx.Cache[CacheKey] == null) { this.UsedCarAdvertisements = new List <CarAdvertisement>(); Fuel GasFuel = new Fuel(); GasFuel.CurrentFuel = "Gasoline"; int id = 1; string title = "BMW E89 Z4 Roadster"; int price = 23459; bool newCar = false; int newMileage = 33000; string registeredDate = "01/08/2008"; DateTime NewFirstRegistration = new DateTime(); NewFirstRegistration = Convert.ToDateTime(registeredDate); UsedCar TestCar1 = new UsedCar(id, title, GasFuel, price, newCar, newMileage, NewFirstRegistration); this.UsedCarAdvertisements.Add(TestCar1); /* * UsedCar MyCar = new UsedCar[] * { * new UsedCar * { * Id = 1, Name = "Glenn Block" * }, * new UsedCar * { * Id = 2, Name = "Dan Roth" * } * }; */ ctx.Cache[CacheKey] = this.UsedCarAdvertisements.ToArray(); } } }
public static void Initialize(IServiceProvider sp) { var db = sp.GetService <ApplicationDbContext>(); if (!db.NewCars.Any()) { var cars = new NewCar[] { new NewCar { Year = 2000, Make = "VW", Model = "GTI" }, new NewCar { Year = 2002, Make = "Ford", Model = "Focus" }, new NewCar { Year = 2003, Make = "Honda", Model = "Civic" }, }; db.NewCars.AddRange(cars); db.SaveChanges(); } if (!db.UsedCars.Any()) { var usedCars = new UsedCar[] { new UsedCar { Year = 1990, Make = "VW", Model = "Fox", Miles = 5000 }, new UsedCar { Year = 1995, Make = "Dodge", Model = "Charger", Miles = 8000 }, new UsedCar { Year = 1999, Make = "Hyundai", Model = "Sonata", Miles = 9000 }, }; db.UsedCars.AddRange(usedCars); db.SaveChanges(); } }
private void AddUsedCar() { Console.Clear(); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Введите данные через запятую пример: Состояние, ФИО хозяина, Пробег, марка, год производства, цена, описание, страна производства, Дата продажи, ФИО покапутеля"); Console.ForegroundColor = ConsoleColor.White; this.command = this.GetString(); Console.ForegroundColor = ConsoleColor.Blue; try { string[] items = this.command.Split(","); UsedCar сar = new UsedCar() { SafetyDegree = items[0], Owner = items[1], Mileage = items[2], Model = items[3], IssueYear = Int32.Parse(items[4]), Price = items[5], Equipment = items[6], ProducingCountry = items[7], SaleDate = DateTime.Parse(items[8]), Buyer = items[9], }; sellController.SellCar(сar); Console.WriteLine("Автомобиль добавлен успешно"); } catch { Console.WriteLine("У вас ошибка, повторите попытку"); } Console.ForegroundColor = ConsoleColor.White; this.ShowMenu(); }
public void AddVehicle() { Console.Clear(); List <NewCar> newCars = NewCars; List <UsedCar> usedCars = UsedCars; List <NewMotorcycle> newMotorcycles = NewMotorcycles; List <UsedMotorcycle> usedMotorcycles = UsedMotorcycles; Menus.PrintAddVehicle(); var addChoice = Console.ReadKey(true).Key; switch (addChoice) { case ConsoleKey.D1: case ConsoleKey.NumPad1: NewCar newCar = new NewCar(); Console.WriteLine("What brand is it: "); newCar.Brand = Console.ReadLine(); Console.WriteLine("What model is it: "); newCar.Model = Console.ReadLine(); Console.WriteLine("What is the price: "); newCar.Price = int.Parse(Console.ReadLine()); newCars.Add(newCar); break; case ConsoleKey.D2: case ConsoleKey.NumPad2: UsedCar usedCar = new UsedCar(); Console.WriteLine("What brand is it: "); usedCar.Brand = Console.ReadLine(); Console.WriteLine("What model is it: "); usedCar.Model = Console.ReadLine(); Console.WriteLine("What is the price: "); usedCar.Price = int.Parse(Console.ReadLine()); usedCars.Add(usedCar); break; case ConsoleKey.D3: case ConsoleKey.NumPad3: NewMotorcycle newMotorcycle = new NewMotorcycle(); Console.WriteLine("What brand is it: "); newMotorcycle.Brand = Console.ReadLine(); Console.WriteLine("What model is it: "); newMotorcycle.Model = Console.ReadLine(); Console.WriteLine("What is the price: "); newMotorcycle.Price = int.Parse(Console.ReadLine()); newMotorcycles.Add(newMotorcycle); break; case ConsoleKey.D4: case ConsoleKey.NumPad4: UsedMotorcycle usedMotorcycle = new UsedMotorcycle(); Console.WriteLine("What brand is it: "); usedMotorcycle.Brand = Console.ReadLine(); Console.WriteLine("What model is it: "); usedMotorcycle.Model = Console.ReadLine(); Console.WriteLine("What is the price: "); usedMotorcycle.Price = int.Parse(Console.ReadLine()); usedMotorcycles.Add(usedMotorcycle); break; } }