public CarManufacturerModel GetMostExpensive() { var sumdetail = _dbManuf.GetAll().OrderBy(x => x.Cars.Max(y => y.Details.Sum(z => z.Price))).FirstOrDefault(); var mostexpensive = sumdetail.Cars.Select(x => new CarModel { Id = x.Id, Name = x.Name, Details = x.Details.Select(y => new DetailModel { Id = y.Id, Name = y.NameDetail, Cost = y.Price, }), }).ToList(); var maxCar = mostexpensive.OrderBy(y => y.Details.Sum(z => z.Cost)).FirstOrDefault(); var result = new CarManufacturerModel { CarsModel = new CarModel { Id = maxCar.Id, Name = maxCar.Name, Details = maxCar.Details.Select(y => new DetailModel { Name = y.Name }) }, ManufacturerModel = new ManufacturerModel { Id = sumdetail.Id, Name = sumdetail.Name, CarsModel = sumdetail.Cars.Select(x => new CarModel { Id = x.Id, Name = x.Name, Details = x.Details.Select(y => new DetailModel { Id = y.Id, Name = y.NameDetail, Cost = y.Price, }) }), DetailsModel = sumdetail.Details.Select(z => new DetailModel { Id = z.Id, Name = z.NameDetail, Cost = z.Price, ManufacturerId = z.ManufacturerId }) } //CarId = maxCar.Id, //CarName = maxCar.Name, //ManufId=sumdetail.Id, //ManufName=sumdetail.Name }; return(result); }
public CarManufacturerViewModel() { CarManufacturers = new ObservableCollection <CarManufacturerModel> { CarManufacturerModel.Create("Audi", CarModelModel.Create(new string[] { "A1", "A2", "A3", "A4", "A5" })), CarManufacturerModel.Create("Mercedes", CarModelModel.Create(new string[] { "A-Class", "B-Class", "C-Class", "E-Class", "S-Class" })), CarManufacturerModel.Create("BMW", CarModelModel.Create(new string[] { "1-Serie", "2-Serie", "3-Serie", "4-Serie", "5-Serie" })), CarManufacturerModel.Create("Volkswagen", CarModelModel.Create(new string[] { "Golf", "Passat", "Arteon", "T-Cross", "Up!" })), CarManufacturerModel.Create("Volvo", CarModelModel.Create(new string[] { "V60", "V70", "XC60", "XC90", "S90" })) }; //SelectedCarManufacturer = CarManufacturers.First(); }
public IEnumerable <CarManufacturerModel> GetMostExpensiveCar() { var mostExpensiveCar = manufacturerRepository.GetAll(); var result = mostExpensiveCar.Select(x => { var temp = x.Cars.OrderByDescending(y => y.Details.Sum(z => z.Price)).FirstOrDefault(); var manufacturerCar = new CarManufacturerModel { Manufacturer = new ManufacturerModel { Name = x.Name }, MostExpensiveCar = new CarModel { Model = temp.Model, ManufacturerId = temp.ManufacturerId } }; return(manufacturerCar); }).ToList(); return(result); }