Beispiel #1
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            CheckIfComputerExist(computerId);

            if (this.peripherals.Any(x => x.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingPeripheralId);
            }

            IPeripheral peripheral = null;

            switch (peripheralType)
            {
            case "Headset": peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); break;

            case "Keyboard": peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); break;

            case "Monitor": peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); break;

            case "Mouse": peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); break;

            default: throw new ArgumentException(string.Format(ExceptionMessages.InvalidPeripheralType));
            }

            IComputer computer = this.computers.FirstOrDefault(x => x.Id == computerId);

            computer.AddPeripheral(peripheral);
            this.peripherals.Add(peripheral);

            return(string.Format(SuccessMessages.AddedPeripheral, peripheral.GetType().Name, peripheral.Id, computer.Id));
        }
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            var currentPeripheral = this.peripherals.FirstOrDefault(x => x.Id == id);

            if (!(currentPeripheral is null))
            {
                throw new ArgumentException($"Peripheral with this id already exists.");
            }

            IComputer currentComputer = this.computers.FirstOrDefault(x => x.Id == computerId);

            if (currentComputer is null)
            {
                throw new ArgumentException("Computer with this id does not exist.");
            }

            currentPeripheral = PeripheralFactory(id, peripheralType, manufacturer, model, price, overallPerformance, connectionType);


            if (currentPeripheral is null)
            {
                throw new ArgumentException(ExceptionMessages.InvalidPeripheralType);
            }

            currentComputer.AddPeripheral(currentPeripheral);

            this.peripherals.Add(currentPeripheral);

            return($"Peripheral {peripheralType} with id {id} added successfully in computer with id {computerId}.");
        }
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            if (this.peripherals.Any(c => c.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingPeripheralId);
            }
            IComputer   currentComp = ComputerWithIdExists(computerId);
            IPeripheral peripheral  = CreatePeripherpal(id, peripheralType, manufacturer, model, price, overallPerformance, connectionType);

            this.peripherals.Add(peripheral);
            currentComp.AddPeripheral(peripheral);

            string outputMsg = String.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId);

            return(outputMsg);
        }
Beispiel #4
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price,
                                    double overallPerformance, string connectionType)
        {
            IComputer computer = this.computers.FirstOrDefault(c => c.Id == computerId);

            if (computer == null)
            {
                throw new ArgumentException("Computer with this id does not exist.");
            }


            IPeripheral peripheral = this.peripherals.FirstOrDefault(c => c.Id == id);

            if (peripheral != null)
            {
                throw new ArgumentException("Peripheral with this id already exists.");
            }

            if (peripheralType == Common.Enums.PeripheralType.Headset.ToString())
            {
                peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == Common.Enums.PeripheralType.Keyboard.ToString())
            {
                peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == Common.Enums.PeripheralType.Monitor.ToString())
            {
                peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == Common.Enums.PeripheralType.Mouse.ToString())
            {
                peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else
            {
                throw new ArgumentException("Peripheral type is invalid.");
            }

            computer.AddPeripheral(peripheral);
            this.peripherals.Add(peripheral);

            return($"Peripheral {peripheralType} with id {id} added successfully in computer with id {computerId}.");
        }
Beispiel #5
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            IComputer currComp = computers.FirstOrDefault(c => c.Id == computerId);

            if (!computers.Contains(currComp))
            {
                throw new ArgumentException(string.Format(Common.Constants.ExceptionMessages.NotExistingComputerId));
            }

            var currPeripherial = peripherals.FirstOrDefault(p => p.Id == id);

            if (currPeripherial != null)
            {
                throw new ArgumentException(string.Format(Common.Constants.ExceptionMessages.ExistingPeripheralId));
            }

            IPeripheral peripheral = null;

            if (peripheralType == nameof(Headset))
            {
                peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == nameof(Keyboard))
            {
                peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == nameof(Monitor))
            {
                peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == nameof(Mouse))
            {
                peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else
            {
                throw new ArgumentException(string.Format(Common.Constants.ExceptionMessages.InvalidPeripheralType));
            }

            currComp.AddPeripheral(peripheral);
            peripherals.Add(peripheral);
            return(string.Format(Common.Constants.SuccessMessages.AddedPeripheral, peripheralType, id, computerId));
        }
Beispiel #6
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price,
                                    double overallPerformance, string connectionType)
        {
            CheckIfComputerIdExist(computerId);
            IComputer computer = _computers[computerId];

            if (_peripherals.ContainsKey(id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingPeripheralId);
            }

            IPeripheral peripheral = _factory.CreatePeripheral(id, peripheralType, manufacturer, model, price,
                                                               overallPerformance, connectionType);

            computer.AddPeripheral(peripheral);
            _peripherals.Add(id, peripheral);

            return(string.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId));
        }
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            if (!computers.Any(x => x.Id == computerId))
            {
                throw new ArgumentException("Computer with this id does not exist.");
            }

            IComputer computer = computers.FirstOrDefault(x => x.Id == computerId);

            if (peripherals.Any(x => x.Id == id))
            {
                throw new ArgumentException("Peripheral with this id already exists.");
            }

            IPeripheral peripheral = null;

            if (peripheralType == "Headset")
            {
                peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == "Keyboard")
            {
                peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == "Monitor")
            {
                peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == "Mouse")
            {
                peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else
            {
                throw new ArgumentException("Peripheral type is invalid.");
            }

            computer.AddPeripheral(peripheral);
            peripherals.Add(peripheral);

            return($"Peripheral {peripheralType} with id {id} added successfully in computer with id {computerId}.");
        }
Beispiel #8
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            IComputer computer = computers.FirstOrDefault(c => c.Id == computerId);

            if (computer == null)
            {
                throw new ArgumentException(String.Format(ExceptionMessages.NotExistingComputerId));
            }

            if (peripherals.Any(p => p.Id == id))
            {
                throw new ArgumentException(String.Format(ExceptionMessages.ExistingPeripheralId));
            }

            IPeripheral peripheral = null;

            if (peripheralType == "Headset")
            {
                peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == "Keyboard")
            {
                peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == "Monitor")
            {
                peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == "Mouse")
            {
                peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else
            {
                throw new ArgumentException(String.Format(ExceptionMessages.InvalidPeripheralType));
            }

            computer.AddPeripheral(peripheral);
            peripherals.Add(peripheral);

            return(String.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId));
        }
Beispiel #9
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            this.ValidateComputerWithIdExists(computerId);

            if (this.peripherals.Any(x => x.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingPeripheralId);
            }

            IPeripheral peripheral = CreateValidPeripheral(id, peripheralType, manufacturer, model, price, overallPerformance, connectionType);

            IComputer computer = this.computers.First(x => x.Id == computerId);

            computer.AddPeripheral(peripheral);
            this.peripherals.Add(peripheral);

            string result = string.Format(SuccessMessages.AddedPeripheral, peripheralType, peripheral.Id, computer.Id);

            return(result);
        }
Beispiel #10
0
        public string AddPeripheral(int computerId, int id,
                                    string peripheralType, string manufacturer,
                                    string model, decimal price, double overallPerformance,
                                    string connectionType)
        {
            CheckIfPeripheralAlreadyExist(id);
            IPeripheral peripheral = CreatePeripheral(id, peripheralType,
                                                      manufacturer, model, price,
                                                      overallPerformance, connectionType);

            CheckIfComputerExist(computerId);
            IComputer computer = GetComputerById(computerId);

            computer.AddPeripheral(peripheral);
            peripherals.Add(peripheral);

            return(string.Format(SuccessMessages
                                 .AddedPeripheral, peripheral.GetType().Name,
                                 peripheral.Id, computerId));
        }
Beispiel #11
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            if (!computers.Any(x => x.Id == computerId))
            {
                throw new ArgumentException(ExceptionMessages.NotExistingComputerId);
            }

            IPeripheral peripheralToAdd;

            switch (peripheralType)
            {
            case "Headset":
                peripheralToAdd = new Headset(id, manufacturer, model, price, overallPerformance, connectionType);
                break;

            case "Keyboard":
                peripheralToAdd = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType);
                break;

            case "Monitor":
                peripheralToAdd = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType);
                break;

            case "Mouse":
                peripheralToAdd = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType);
                break;

            default:
                throw new ArgumentException(ExceptionMessages.InvalidPeripheralType);
            }

            IComputer computer = computers.First(x => x.Id == computerId);

            if (computer.Peripherals.Any(x => x.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingPeripheralId);
            }
            computer.AddPeripheral(peripheralToAdd);
            peripherals.Add(peripheralToAdd);
            return(string.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId));
        }
Beispiel #12
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            CheckIfComputerExists(computerId);
            if (periherals.Any(x => x.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingPeripheralId);
            }

            IPeripheral peripheral = peripheralType switch
            {
                nameof(Headset) => new Headset(id, manufacturer, model, price, overallPerformance, connectionType),
                nameof(Keyboard) => new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType),
                nameof(Monitor) => new Monitor(id, manufacturer, model, price, overallPerformance, connectionType),
                nameof(Mouse) => new Mouse(id, manufacturer, model, price, overallPerformance, connectionType),
                _ => throw new ArgumentException(ExceptionMessages.InvalidPeripheralType)
            };
            IComputer computer = computers.FirstOrDefault(x => x.Id == computerId);

            computer.AddPeripheral(peripheral);
            periherals.Add(peripheral);
            return(string.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId));
        }
Beispiel #13
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            IComputer currentComputer = computers.Where(x => x.Id == computerId).FirstOrDefault();

            if (currentComputer == null)
            {
                throw new ArgumentException(ExceptionMessages.NotExistingComputerId);
            }
            IPeripheral currentPeripheral = null;

            if (peripherals.Any(x => x.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingPeripheralId);
            }
            if (peripheralType == "Headset")
            {
                currentPeripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == "Keyboard")
            {
                currentPeripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == "Monitor")
            {
                currentPeripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else if (peripheralType == "Mouse")
            {
                currentPeripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType);
            }
            else
            {
                throw new ArgumentException(ExceptionMessages.InvalidPeripheralType);
            }
            currentComputer.AddPeripheral(currentPeripheral);
            peripherals.Add(currentPeripheral);
            //public const string AddedComponent = "Component {0} with id {1} added successfully in computer with id {2}.";
            return(string.Format(SuccessMessages.AddedPeripheral, currentPeripheral.GetType().Name, currentPeripheral.Id, currentComputer.Id));
        }
Beispiel #14
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            IComputer comp = IsExist(computerId);

            if (comp.Peripherals.Any(x => x.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingPeripheralId);
            }

            if (!Enum.TryParse(peripheralType, out PeripheralType))
            {
                throw new ArgumentException(ExceptionMessages.InvalidPeripheralType);
            }

            IPeripheral peripheral = null;

            switch (PeripheralType)
            {
            case PeripheralType.Headset:
                peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType);
                break;

            case PeripheralType.Keyboard:
                peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType);
                break;

            case PeripheralType.Monitor:
                peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType);
                break;

            case PeripheralType.Mouse:
                peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType);
                break;
            }
            comp.AddPeripheral(peripheral);
            peripherals.Add(peripheral);
            return(string.Format(SuccessMessages.AddedPeripheral, peripheral.GetType().Name, id, computerId));
        }
Beispiel #15
0
        public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType)
        {
            ValidateExistingComputerId(computerId);

            IPeripheral peripheral = null;

            switch (peripheralType)
            {
            case "Headset":
                peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType);
                break;

            case "Keyboard":
                peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType);
                break;

            case "Monitor":
                peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType);
                break;

            case "Mouse":
                peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType);
                break;
            }
            if (peripherals.Any(p => p.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingPeripheralId);
            }

            IComputer computer = computers.FirstOrDefault(c => c.Id == computerId);

            computer.AddPeripheral(peripheral);

            peripherals.Add(peripheral);


            return(string.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId));
        }