Beispiel #1
0
        private void FindCars()
        {
            Dictionary <string, string> values = GetFilterValues();

            // find all cars
            CarModel[] cars = RentACarLibrary.GlobalConfig.CarModelConection.Filter(
                model =>
            {
                Dictionary <string, string> carDict = model.ToDict();
                foreach (string key in values.Keys)
                {
                    if (carDict[key] != values[key])
                    {
                        return(false);
                    }
                }
                // Check for created year and cubic capacity ranges
                bool cubicValuesPicked = view.CubicCapacityFrom.ValuePicked() && view.CubicCapacityTo.ValuePicked();
                if (cubicValuesPicked)
                {
                    double cubicCapacityFrom = double.Parse(view.CubicCapacityFrom);
                    double cubicCapacityTo   = double.Parse(view.CubicCapacityTo);
                    bool inCubicRange        = cubicCapacityFrom <= model.CubicCapacity && model.CubicCapacity <= cubicCapacityTo;
                    if (!inCubicRange)
                    {
                        return(false);
                    }
                }

                bool yearValuesPicked = view.CreatedYearFrom.ValuePicked() && view.CreatedYearTo.ValuePicked();
                if (yearValuesPicked)
                {
                    int createdYearFrom     = int.Parse(view.CreatedYearFrom);
                    int createdYearTo       = int.Parse(view.CreatedYearTo);
                    bool inCreatedYearRange = createdYearFrom <= model.CreatedYear && model.CreatedYear <= createdYearTo;
                    if (!inCreatedYearRange)
                    {
                        return(false);
                    }
                }

                return(true);
            }
                );
            // send selected cars via event aggregator
            CarsFoundMessage carsFoundMessage = new CarsFoundMessage(cars);

            eventAggregator.Publish(carsFoundMessage);
            if (cars.Length > 0)
            {
                AlertMessage successMessage = new AlertMessage(
                    AlertMessage.MessageType.Success,
                    "Pronašli smo željene automobile");
                eventAggregator.Publish(successMessage);
            }
            else
            {
                AlertMessage warningMessage = new AlertMessage(
                    AlertMessage.MessageType.Warning,
                    "Nismo pronašli željene automobile");
                eventAggregator.Publish(warningMessage);
            }
        }
Beispiel #2
0
 private void CarsFoundHandler(CarsFoundMessage message)
 {
     SetCarsDataSource(message.cars);
 }