public VehicleModel(VehicleMake vehicleMake, string description, decimal currentYearPrice) { BaseConstructor(vehicleMake, description); if (VehiclePrices == null) { VehiclePrices = new List <VehiclePrice>(); } var currentPrice = VehiclePrices.FirstOrDefault(p => p.Year == DateTime.Now.Year); if (currentPrice != null) { // update existing one currentPrice.Price = currentYearPrice; } else { // add current year price VehiclePrices.Add(new VehiclePrice { Year = DateTime.Now.Year, Price = currentYearPrice }); } }
private void BaseConstructor(VehicleMake vehicleMake, string description) { if (!string.IsNullOrEmpty(description)) { this.Description = description; } else { throw new ArgumentNullException(nameof(Description)); } this.VehicleMake = vehicleMake; }
static void Main(string[] args) { Console.WriteLine("Start"); //implementation for g VehicleMake vehicleMake = new VehicleMake("Mercedes-Benz"); //implementation for h VehicleModel vehicleModel = new VehicleModel(vehicleMake, "A180", 300000); Console.WriteLine("Complete"); Console.ReadKey(); }
public VehicleModel(VehicleMake vehicleMake, string description) { BaseConstructor(vehicleMake, description); }