示例#1
0
        /// <summary>
        /// Hires a driver.
        /// </summary>
        /// <param name="parameters">A string containing the driver id which will be hired, and the car id wich driver will drive, separated by a pipe.</param>
        public void HireDriver(string parameters)
        {
            string[] p = parameters.Split('|');
            if (p.Length < 2)
            {
                throw new ArgumentException("Invalid function parameter. Driver id and vehicle Id expected.");
            }

            int driverId;
            if (!int.TryParse(p[0], out driverId))
            {
                throw new ArgumentException("Invalid function parameter. Driver Id expected.");
            }

            int vehicleId;
            if (!int.TryParse(p[1], out vehicleId))
            {
                throw new ArgumentException("Invalid function parameter. Vehicle Id expected.");
            }

            DriverServices driverSvc = new DriverServices();
            Driver theDriver = driverSvc.GetById(driverId);

            VehicleServices vehicleSvc = new VehicleServices();
            Vehicle theCar = vehicleSvc.GetById(vehicleId);

            driverSvc.HireDriver(theDriver, theCar);
        }
示例#2
0
        /// <summary>
        /// Fires a driver.
        /// </summary>
        /// <param name="parameters">A string containing the car id wich driver will be fired.</param>
        public void FireDriver(string parameters)
        {
            int vehicleId;
            if (!int.TryParse(parameters, out vehicleId))
            {
                throw new ArgumentException("Invalid function parameter. Vehicle Id expected.");
            }

            VehicleServices vehicleSvc = new VehicleServices();
            Vehicle theCar = vehicleSvc.GetById(vehicleId);

            DriverServices driverSvc = new DriverServices();
            driverSvc.FireDriver(theCar);
        }
示例#3
0
        /// <summary>
        /// Mounts a part in a car.
        /// </summary>
        /// <param name="parameters">A string containing the part id which mounting, plus the vehicle id, separated with a pipe.</param>
        public void MountPart(string parameters)
        {
            string[] p = parameters.Split('|');
            if (p.Length < 2)
            {
                throw new ArgumentException("Invalid function parameter. Part id and vehicle Id expected.");
            }

            int partId;
            if (!int.TryParse(p[0], out partId))
            {
                throw new ArgumentException("Invalid function parameter. Part Id expected.");
            }

            int vehicleId;
            if (!int.TryParse(p[1], out vehicleId))
            {
                throw new ArgumentException("Invalid function parameter. Vehicle Id expected.");
            }

            PartServices partSvc = new PartServices();
            Part thePart = partSvc.GetById(partId);

            VehicleServices vehicleSvc = new VehicleServices();
            Vehicle theCar = vehicleSvc.GetById(vehicleId);

            partSvc.Mount(thePart, theCar);
        }