Пример #1
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            var computer = this.computers.FirstOrDefault(x => x.Id == computerId);

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

            IComponent component = null;

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

            if (componentType == "CentralProcessingUnit")
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else if (componentType == "Motherboard")
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else if (componentType == "PowerSupply")
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else if (componentType == "RandomAccessMemory")
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else if (componentType == "SolidStateDrive")
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else if (componentType == "VideoCard")
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else
            {
                throw new ArgumentException(ExceptionMessages.InvalidComponentType);
            }

            return(string.Format(SuccessMessages.AddedComponent, componentType, component.Id, computer.Id));
        }
Пример #2
0
        public string RemoveComponent(string componentType, int computerId)
        {
            CheckIfComputerExists(computerId);

            IComponent component = components.FirstOrDefault(x => x.GetType().Name == componentType);
            IComputer  computer  = computers.FirstOrDefault(x => x.Id == computerId);

            computer.RemoveComponent(componentType);
            components.Remove(component);

            return($"Successfully removed {componentType} with id {component.Id}.");
        }
Пример #3
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            CheckIfComputerExists(computerId);

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

            IComponent component = null;

            if (componentType == "VideoCard")
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == "SolidStateDrive")
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == "CentralProcessingUnit")
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == "RandomAccessMemory")
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == "PowerSupply")
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == "MotherBoard")
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else
            {
                throw new ArgumentException("Component type is invalid.");
            }

            components.Add(component);
            var computer = computers.FirstOrDefault(x => x.Id == computerId);

            computer.AddComponent(component);
            return($"Component {component.GetType().Name} with id {component.Id} added successfully in computer with id {computer.Id}.");
        }
Пример #4
0
        public string RemoveComponent(string componentType, int computerId)
        {
            var computer = this.computers.FirstOrDefault(x => x.Id == computerId);

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

            computer.RemoveComponent(componentType);
            IComponent component = this.components.FirstOrDefault(x => x.GetType().Name == componentType);

            if (component != null)
            {
                this.components.Remove(component);
            }

            return(String.Format(SuccessMessages.RemovedComponent, componentType, component.Id));
        }