Esempio n. 1
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);
        }