public void newClick() { Cars.Add(new CarsShowing() { Id = Cars[Cars.Count - 1].Id + 1 }); SelectedIndexValue = Cars.Count - 1; SelectedCar = _cars[_cars.Count - 1]; }
/// <summary> /// Helped logic /// </summary> public void LoadCars() { using (var context = new Context()) { var tempCars = context.Cars.Include(client => client.Clients) .Join(context.CarBrands, cars => cars.CarBrandId, brands => brands.Id, (cars, brands) => new { cars, brands }) // .Where(t => t.cars.CarBrandId==t.brands.Id) .OrderBy(x => x.cars.Id) .Select(x => new { x.cars.Id, x.brands.Brand, x.cars.Model, x.brands.CountryProducing, x.cars.Load, x.cars.Axel, x.cars.GearBox, x.cars.EngineCapacity, x.cars.FuelPerHunderdKm, x.cars.ProductionYear, x.cars.Price }).ToList(); _cars = new ObservableCollection <CarsShowing>(tempCars.ToList().Select(r => new CarsShowing { Id = r.Id, Brand = r.Brand, Model = r.Model, Country = r.CountryProducing, Load = r.Load, Axel = r.Axel, GearBox = r.GearBox, EngineCapacity = r.EngineCapacity, FuelPerHunderdKm = r.FuelPerHunderdKm, ProductionYear = r.ProductionYear, Price = r.Price }).ToList()); this.RaisePropertyChanged(() => this.Cars); this.RaisePropertyChanged(() => this.SelectedCar); SelectedIndexValue = 0; SelectedCar = _cars[0]; } }
public void maxPrice() { using (var context = new Context()) { if (_cars.Count == 0) { LoadCars(); } var max = _cars.Max(x => x.Price); _cars = new ObservableCollection <CarsShowing>(_cars.Where(r => r.Price == max) .ToList()); this.RaisePropertyChanged(() => this.Cars); if (_cars.Count > 0) { SelectedIndexValue = 0; SelectedCar = _cars[0]; } } }
public void searchPress() { try { using (var context = new Context()) { switch (_findingOption) { case "Brand": if (_cars.Count == 0) { LoadCars(); } _cars = new ObservableCollection <CarsShowing>(_cars.Where(r => r.Brand == FindingValue) .ToList()); this.RaisePropertyChanged(() => this.Cars); if (_cars.Count > 0) { SelectedIndexValue = 0; SelectedCar = _cars[0]; } break; case "Country": if (_cars.Count == 0) { LoadCars(); } _cars = new ObservableCollection <CarsShowing>(_cars.Where(r => r.Country == FindingValue) .ToList()); this.RaisePropertyChanged(() => this.Cars); if (_cars.Count > 0) { SelectedIndexValue = 0; SelectedCar = _cars[0]; } break; case "Price": if (_cars.Count == 0) { LoadCars(); } _cars = new ObservableCollection <CarsShowing>(_cars.Where(r => r.Price == Convert.ToDouble(FindingValue)) .ToList()); this.RaisePropertyChanged(() => this.Cars); if (_cars.Count > 0) { SelectedIndexValue = 0; SelectedCar = _cars[0]; } break; } } } catch (FormatException f) { MessageBox.Show(f.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }