예제 #1
0
        private void buttonModify_Click(object sender, EventArgs e)
        {
            try
            {
                var selectedVehicleToModify         = this.comboBoxSelectVehicleToModify.SelectedItem as Vehicle;
                var newCapacity                     = (int)this.numericUpDownCapacity.Value;
                var newFuelConsumption              = (int)this.numericUpDownFuelConsumption.Value;
                ModifyVehicleInput newVehicleValues = new ModifyVehicleInput
                {
                    Registration             = selectedVehicleToModify.Registration,
                    NewCapacity              = newCapacity,
                    FuelConsumptionKmsPerLtr = newFuelConsumption
                };

                IVehicleLogic vehicleOperations = Provider.GetInstance.GetVehicleOperations();
                vehicleOperations.ModifyVehicle(newVehicleValues);
                this.labelSuccess.Visible = true;
                this.labelSuccess.Text    = "The vehicle was succesfully modified.";
                this.ClearForm();
                this.ReloadComboBoxSelectVehicleToModify();
            }
            catch (CoreException ex)
            {
                this.labelError.Visible = true;
                this.labelSuccess.Text  = ex.Message;
            }
            catch (Exception ex)
            {
                this.labelError.Visible = true;
                this.labelSuccess.Text  = ex.Message;
            }
        }
예제 #2
0
 public HomeController(IConfiguration config)
 {
     this._factory = new Factory.Factory(config);
     this._account = this._factory.AccountLogic();
     this._vehicle = this._factory.VehicleLogic();
     this._order   = this._factory.OrderLogic();
 }
예제 #3
0
        private void OrderByNumberOfTrips(string direction)
        {
            try
            {
                IVehicleLogic vehicleOperations = Provider.GetInstance.GetVehicleOperations();
                var           vehicles          = this.listBoxVehiclesOrderedByEfficiency.Items.Cast <Tuple <Vehicle, List <Student> > >().ToList();

                var orderedVehicles = new List <Tuple <Vehicle, List <Student> > >();

                if (direction.Equals("ASC"))
                {
                    orderedVehicles = vehicles.OrderBy(v => this.occurrences(v, vehicles)).ToList();
                }
                else
                {
                    orderedVehicles = vehicles.OrderByDescending(v => this.occurrences(v, vehicles)).ToList();
                }

                this.listBoxVehiclesOrderedByEfficiency.Items.Clear();
                for (int index = 0; index < orderedVehicles.Count; index++)
                {
                    this.listBoxVehiclesOrderedByEfficiency.Items.Add(orderedVehicles[index]);
                }
            }
            catch (CoreException ex)
            {
                this.labelError.Text    = ex.Message;
                this.labelError.Visible = true;
            }
            catch (Exception ex)
            {
                this.labelError.Text    = ex.Message;
                this.labelError.Visible = true;
            }
        }
예제 #4
0
 private void buttonDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (UserConfirmsThatWantToDeleteVehicle())
         {
             var           selectedVehicle   = this.comboBoxSelectVehicleToDelete.SelectedItem as Vehicle;
             IVehicleLogic vehicleOperations = Provider.GetInstance.GetVehicleOperations();
             vehicleOperations.DeleteVehicle(selectedVehicle);
             this.ShowMessageVehicleWasDeleted(selectedVehicle);
             this.ReloadComboBoxSelectVehicleToDelete();
             this.HideAllResultLabels();
         }
     }
     catch (CoreException ex)
     {
         this.labelError.Text    = ex.Message;
         this.labelError.Visible = true;
     }
     catch (Exception ex)
     {
         this.labelError.Text    = ex.Message;
         this.labelError.Visible = true;
     }
 }
예제 #5
0
        private object FindVehicleOnSystem(string registration)
        {
            IVehicleLogic  vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations();
            List <Vehicle> vehicles          = vehicleOperations.GetVehicles();

            return(vehicles.Find(x => x.GetRegistration() == registration));
        }
예제 #6
0
 public OrdersController(
     IOrderLogic orderLogic,
     IVehicleLogic vehicleLogic
     )
 {
     _orderLogic   = orderLogic;
     _vehicleLogic = vehicleLogic;
 }
예제 #7
0
 public RideController(IConfiguration config)
 {
     this._factory        = new Factory.Factory(config);
     this._rideLogic      = this._factory.RideLogic();
     this._accountLogic   = this._factory.AccountLogic();
     this._pickOrderLogic = this._factory.PickOrderLogic();
     this._vehicleLogic   = this._factory.VehicleLogic();
 }
예제 #8
0
 private Provider()
 {
     this.teachersLogic   = new TeacherLogic(new TeacherPersistance());
     this.studentsLogic   = new StudentLogic(new StudentPersistance());
     this.subjectsLogic   = new SubjectLogic(new SubjectPersistance());
     this.vehiclesLogic   = new VehicleLogic(new VehiclePersistance());
     this.activitiesLogic = new ActivityLogic(new ActivityPersistance());
     this.paymentsLogic   = new PaymentLogic(new PaymentPersistence());
 }
예제 #9
0
 public OrderLogic(
     IOrderEngine orderEngine,
     IExceptionHandlerLogic exceptionHandlerLogic,
     IVehicleLogic vehicleLogic
     )
 {
     _orderEngine           = orderEngine;
     _exceptionHandlerLogic = exceptionHandlerLogic;
     _vehicleLogic          = vehicleLogic;
 }
예제 #10
0
        public void TestStudentsOrderedByDistanceToSchool()
        {
            IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations();
            IStudentLogic studentOperations = DummyProvider.GetInstance.GetStudentOperations();

            Student studentOne = new Student();

            studentOne.Document          = "1234567-1";
            studentOne.Name              = "John";
            studentOne.Location          = new Location(2.00000, 2.000000);
            studentOne.HavePickUpService = true;
            studentOne.StudentNumber     = 1;

            Student studentTwo = new Student();

            studentTwo.Document          = "1234567-2";
            studentTwo.Name              = "George";
            studentTwo.Location          = new Location(1.00000, 1.000000);
            studentTwo.HavePickUpService = true;
            studentTwo.StudentNumber     = 2;

            Student studentThree = new Student();

            studentThree.Document          = "1234567-3";
            studentThree.Name              = "Paul";
            studentThree.Location          = new Location(3.00000, 3.000000);
            studentThree.HavePickUpService = true;
            studentThree.StudentNumber     = 3;

            Student studentFour = new Student();

            studentFour.Document          = "1234567-4";
            studentFour.Name              = "Ringo";
            studentFour.Location          = new Location(20.00000, 20.000000);
            studentFour.HavePickUpService = true;
            studentFour.StudentNumber     = 4;

            studentOperations.AddStudent(studentOne);
            studentOperations.AddStudent(studentTwo);
            studentOperations.AddStudent(studentThree);
            studentOperations.AddStudent(studentFour);


            Student studentToCompare1 = studentOperations.GetStudentByDocumentNumber(studentOne.Document);
            Student studentToCompare2 = studentOperations.GetStudentByDocumentNumber(studentTwo.Document);
            Student studentToCompare3 = studentOperations.GetStudentByDocumentNumber(studentThree.Document);
            Student studentToCompare4 = studentOperations.GetStudentByDocumentNumber(studentFour.Document);

            var studentsOrderedByDistanceToSchool = vehicleOperations.StudentsOrderedByDistanceToSchool();

            Assert.AreEqual(studentsOrderedByDistanceToSchool[0].Item1, studentToCompare2);
            Assert.AreEqual(studentsOrderedByDistanceToSchool[1].Item1, studentToCompare1);
            Assert.AreEqual(studentsOrderedByDistanceToSchool[2].Item1, studentToCompare3);
            Assert.AreEqual(studentsOrderedByDistanceToSchool[3].Item1, studentToCompare4);
        }
예제 #11
0
        private void CheckIfIsThereAnyVehicleInSystem()
        {
            IVehicleLogic vehicleOperations = Provider.GetInstance.GetVehicleOperations();
            var           vehicles          = vehicleOperations.GetVehicles();

            if (vehicles.Count() == 0)
            {
                this.labelError.Text    = "Currently there is not any subject in the system.";
                this.labelError.Visible = true;
            }
        }
예제 #12
0
        public void GetVehiclesOrderedByCapacityPerFuelConsumption()
        {
            IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations();

            Vehicle vehicle1 = new Vehicle("SBA0001", 10, 10);
            Vehicle vehicle2 = new Vehicle("SBA1015", 10, 100);

            vehicleOperations.AddVehicle(vehicle1);
            vehicleOperations.AddVehicle(vehicle2);

            var vehiclesOrdered = vehicleOperations.GetVehiclesOrderedByCapacityPerFuelConsumption();

            Assert.AreEqual(vehiclesOrdered[0], vehicle2);
            Assert.AreEqual(vehiclesOrdered[1], vehicle1);
        }
예제 #13
0
        public void ListVehicles()
        {
            IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations();

            Vehicle vehicleOne   = new Vehicle("SBA1234", 10);
            Vehicle vehicleTwo   = new Vehicle("SBA5678", 15);
            Vehicle vehicleThree = new Vehicle("SBA9012", 20);

            vehicleOperations.AddVehicle(vehicleOne);
            vehicleOperations.AddVehicle(vehicleTwo);
            vehicleOperations.AddVehicle(vehicleThree);

            var vehicles = vehicleOperations.GetVehicles();

            Assert.IsTrue(vehicles.Count == 3);
        }
예제 #14
0
 private void FillListBoxVehiclesOrderedByCapacity()
 {
     try
     {
         IVehicleLogic vehicleOperations = Provider.GetInstance.GetVehicleOperations();
         var           vehicles          = vehicleOperations.GetVehiclesOrderedByCapacityConsideringStudentsNumber();
         for (int index = 0; index < vehicles.Count; index++)
         {
             this.listBoxVehiclesOrderedByEfficiency.Items.Add(vehicles[index]);
         }
     }
     catch (CoreException ex)
     {
         this.labelError.Text    = ex.Message;
         this.labelError.Visible = true;
     }
 }
예제 #15
0
 private void FillVehiclesComboBox()
 {
     try
     {
         IVehicleLogic vehicleOperations = Provider.GetInstance.GetVehicleOperations();
         var           vehicles          = vehicleOperations.GetVehicles();
         for (int index = 0; index < vehicles.Count; index++)
         {
             this.comboBoxSelectVehicleToModify.Items.Add(vehicles[index]);
         }
         this.comboBoxSelectVehicleToModify.DropDownStyle = ComboBoxStyle.DropDownList;
     }
     catch (CoreException ex)
     {
         this.labelError.Text    = ex.Message;
         this.labelError.Visible = true;
     }
 }
예제 #16
0
        public void ModifyVehicleCapacityInSystem()
        {
            IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations();

            Vehicle newVehicle = new Vehicle("SBA1234", 10, 10);

            vehicleOperations.AddVehicle(newVehicle);

            ModifyVehicleInput input = new ModifyVehicleInput();

            input.Registration             = "SBA1234";
            input.NewCapacity              = 20;
            input.FuelConsumptionKmsPerLtr = 10;
            vehicleOperations.ModifyVehicle(input);

            Vehicle modifiedVehicle = vehicleOperations.GetVehicleByRegistration("SBA1234");

            Assert.AreEqual(modifiedVehicle.GetCapacity(), input.NewCapacity);
        }
예제 #17
0
        public void DeleteVehicle()
        {
            try
            {
                IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations();

                string  registration = "SBA1234";
                int     capacity     = 10;
                Vehicle vehicle      = new Vehicle(registration, capacity);

                vehicleOperations.AddVehicle(vehicle);
                vehicleOperations.DeleteVehicle(vehicle);

                Assert.IsNull(this.FindVehicleOnSystem(vehicle.Registration));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
예제 #18
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            this.labelSuccess.Visible = false;
            this.labelError.Visible   = false;
            var registration    = this.textBoxRegistration.Text;
            var capacity        = (int)this.numericUpDownCapacity.Value;
            var fuelConsumption = (int)this.numericUpDownFuelConsumption.Value;

            try
            {
                Vehicle       vehicle           = new Vehicle(registration, capacity, fuelConsumption);
                IVehicleLogic vehicleOperations = Provider.GetInstance.GetVehicleOperations();
                vehicleOperations.AddVehicle(vehicle);
                this.labelSuccess.Visible = true;
                this.labelSuccess.Text    = "Vehicle " + vehicle + " was successfully added.";
            }
            catch (CoreException ex)
            {
                this.labelError.Visible = true;
                this.labelError.Text    = ex.Message;
            }
        }
 private void FillListBoxAvailableVehicles()
 {
     try
     {
         IVehicleLogic vehicleOperations = Provider.GetInstance.GetVehicleOperations();
         var           availableVehicles = vehicleOperations.GetVehicles();
         for (int index = 0; index < availableVehicles.Count; index++)
         {
             this.listBoxAvailableVehicles.Items.Add(availableVehicles[index].GetFullToString());
         }
     }
     catch (CoreException ex)
     {
         this.labelError.Visible = true;
         this.labelError.Text    = ex.Message;
     }
     catch (Exception ex)
     {
         this.labelError.Visible = true;
         this.labelError.Text    = ex.Message;
     }
 }
 public VehiclesController(
     IVehicleLogic vehicleLogic
     )
 {
     _vehicleLogic = vehicleLogic;
 }
예제 #21
0
 public VehiclesController(IVehicleLogic logic) => _logic = logic;
예제 #22
0
        public void CalculateDistanceToCoverByVehicle()
        {
            IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations();
            IStudentLogic studentOperations = DummyProvider.GetInstance.GetStudentOperations();

            Vehicle vehicle = new Vehicle("SBA0001", 10, 10);

            vehicleOperations.AddVehicle(vehicle);

            Student studentOne = new Student();

            studentOne.Document          = "1234567-1";
            studentOne.Name              = "John";
            studentOne.Location          = new Location(2.00000, 2.000000);
            studentOne.HavePickUpService = true;
            studentOne.StudentNumber     = 1;

            Student studentTwo = new Student();

            studentTwo.Document          = "1234567-2";
            studentTwo.Name              = "George";
            studentTwo.Location          = new Location(1.00000, 1.000000);
            studentTwo.HavePickUpService = true;
            studentTwo.StudentNumber     = 2;

            Student studentThree = new Student();

            studentThree.Document          = "1234567-3";
            studentThree.Name              = "Paul";
            studentThree.Location          = new Location(3.00000, 3.000000);
            studentThree.HavePickUpService = true;
            studentThree.StudentNumber     = 3;

            Student studentFour = new Student();

            studentFour.Document          = "1234567-4";
            studentFour.Name              = "Ringo";
            studentFour.Location          = new Location(20.00000, 20.000000);
            studentFour.HavePickUpService = true;
            studentFour.StudentNumber     = 4;

            studentOperations.AddStudent(studentOne);
            studentOperations.AddStudent(studentTwo);
            studentOperations.AddStudent(studentThree);
            studentOperations.AddStudent(studentFour);

            List <Tuple <Vehicle, List <Student> > > vehiclesWithStudents = vehicleOperations.GetVehiclesOrderedByEfficiencyConsideringStudentsNumber();

            var expectedDistance = 0.0;

            expectedDistance += Utils.Distance(new Location(), studentTwo.Location);
            expectedDistance += Utils.Distance(studentTwo.Location, studentOne.Location);
            expectedDistance += Utils.Distance(studentOne.Location, studentThree.Location);
            expectedDistance += Utils.Distance(studentThree.Location, studentFour.Location);
            expectedDistance += Utils.Distance(studentFour.Location, new Location());


            var distance = vehicleOperations.CalculateDistanceToCoverByVehicle(vehiclesWithStudents[0]);

            Assert.IsTrue(distance == expectedDistance);
        }
 public VehicleController(IConfiguration config)
 {
     this._factory = new Factory.Factory(config);
     this._vehicle = this._factory.VehicleLogic();
 }
예제 #24
0
 public VehicleController(ConestogaCarpoolContext context, IVehicleLogic vehicleLogic)
 {
     _context      = context;
     _vehicleLogic = vehicleLogic;
 }