Exemple #1
0
        public void OnCustomerGroupAdd(object source, GroupEventArgs e)
        {
            CustomerSystem.CustomerGroup groupObject = e.Group;
            DatabaseHelper.QueueDatabaseAction((database) =>
            {
                var group = new CustomerGroup
                {
                    CityInstance = Instance,
                    Trip         = null
                };

                foreach (var customer in groupObject.Customers)
                {
                    database.Customers.Add(new Customer
                    {
                        FirstName     = customer.Name.Split(' ')[0],
                        LastName      = customer.Name.Split(' ')[1],
                        Age           = customer.Age,
                        Gender        = DatabaseHelper.GetGender(customer.Gender),
                        CustomerGroup = group
                    });
                }

                database.SaveChanges();
            });
        }
Exemple #2
0
 public TripEventArgs(CustomerSystem.CustomerGroup group, System.Windows.Vector start, System.Windows.Vector end, CarSystem.Car car)
 {
     Group = group;
     Start = start;
     End   = end;
     Car   = car;
 }
Exemple #3
0
        public void OnTripEnd(object source, TripEventArgs e)
        {
            CustomerSystem.CustomerGroup group = e.Group;
            System.Windows.Vector        start = e.Start;
            System.Windows.Vector        end   = e.End;
            CarSystem.Car carObject            = e.Car;
            var           garageLoc            = carObject.Garage.Location;

            DatabaseHelper.QueueDatabaseRequest(
                database => (from garage in database.Garages
                             let loc = garage.Location
                                       where loc.X == garageLoc.X && loc.Y == garageLoc.Y
                                       select garage).ToList(),
                data =>
            {
                if (data.Count == 0)
                {
                    throw new Exception("Cannot find garage in database");
                }
                else
                {
                    var garage = data.First();
                    DatabaseHelper.QueueDatabaseAction((database) =>
                    {
                        if (garage == null)
                        {
                            throw new Exception($"Unknown garage {carObject.Garage}");
                        }

                        var car = new Car
                        {
                            CityInstance      = Instance,
                            Garage            = garage,
                            Model             = carObject.Model.Name,
                            DistanceTravelled = (int)Math.Round(carObject.DistanceTraveled)
                        };

                        var trip = new Trip
                        {
                            Car           = car,
                            Distance      = carObject.DistanceTraveled,
                            StartLocation = DatabaseHelper.CreateDBVector(start),
                            EndLocation   = DatabaseHelper.CreateDBVector(end),
                            Price         = 0.0
                        };

                        database.Trips.Add(trip);
                        database.SaveChanges();
                    });
                }
            },
                MainScreen.CommandLoop
                );
        }
Exemple #4
0
 public GroupEventArgs(CustomerSystem.CustomerGroup group, List <CustomerSystem.Customer> customers)
 {
     Group     = group;
     Customers = customers;
 }