예제 #1
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            CheckIfComputerExist(computerId);

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

            IComponent component = null;

            switch (componentType)
            {
            case "CentralProcessingUnit": component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation); break;

            case "Motherboard": component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation); break;

            case "PowerSupply": component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation); break;

            case "RandomAccessMemory": component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation); break;

            case "SolidStateDrive": component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation); break;

            case "VideoCard": component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation); break;

            default: throw new ArgumentException(ExceptionMessages.InvalidComponentType);
            }
            IComputer computer = this.computers.FirstOrDefault(x => x.Id == computerId);

            computer.AddComponent(component);
            this.components.Add(component);

            return(string.Format(SuccessMessages.AddedComponent, component.GetType().Name, component.Id, computerId));
        }
예제 #2
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(
                          string.Format(ExceptionMessages.ExistingComponentId));
            }


            IComponent component = componentType switch
            {
                nameof(CentralProcessingUnit) => new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation),
                nameof(Motherboard) => new Motherboard(id, manufacturer, model, price, overallPerformance, generation),
                nameof(RandomAccessMemory) => new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation),
                nameof(SolidStateDrive) => new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation),
                nameof(VideoCard) => new VideoCard(id, manufacturer, model, price, overallPerformance, generation),
                _ => throw new ArgumentException(ExceptionMessages.InvalidComponentType)
            };

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

            computer.AddComponent(component);
            components.Add(component);

            return(string.Format(SuccessMessages.AddedComponent, componentType, id, computerId));
        }
예제 #3
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            IComputer currentComputer = this.computers.FirstOrDefault(x => x.Id == computerId);

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

            var currentComponent = currentComputer.Components.FirstOrDefault(x => x.Id == id);

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

            currentComponent = ComponentFactory(id, componentType, manufacturer, model, price, overallPerformance, generation);



            if (currentComponent is null)
            {
                throw new ArgumentException(ExceptionMessages.InvalidComponentType);
            }

            currentComputer.AddComponent(currentComponent);

            return($"Component {componentType} with id {id} added successfully in computer with id {computerId}.");
        }
예제 #4
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price,
                                   double overallPerformance, int generation)
        {
            IComputer computer = this.computers.FirstOrDefault(c => c.Id == computerId);

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


            IComponent component = this.components.FirstOrDefault(c => c.Id == id);

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

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

            this.components.Add(component);
            computer.AddComponent(component);

            return($"Component {componentType} with id {id} added successfully in computer with id {computerId}.");
        }
예제 #5
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            IComputer currComp = computers.FirstOrDefault(c => c.Id == computerId);

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

            var currComponent = components.FirstOrDefault(c => c.Id == id);

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

            IComponent component = null;

            if (componentType == nameof(CentralProcessingUnit))
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == nameof(Motherboard))
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == nameof(PowerSupply))
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == nameof(RandomAccessMemory))
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == nameof(SolidStateDrive))
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == nameof(VideoCard))
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else
            {
                throw new ArgumentException(string.Format(Common.Constants.ExceptionMessages.InvalidComponentType));
            }

            currComp.AddComponent(component);
            components.Add(component);
            return(string.Format(Common.Constants.SuccessMessages.AddedComponent, componentType, id, computerId));
        }
예제 #6
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            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 (components.Any(x => x.Id == id))
            {
                throw new ArgumentException("Component with this id already exists.");
            }

            IComponent component = null;

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

            computer.AddComponent(component);
            components.Add(component);

            return($"Component {componentType} with id {id} added successfully in computer with id {computerId}.");
        }
예제 #7
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            IComputer computer = computers.FirstOrDefault(c => c.Id == computerId);

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

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

            IComponent component = null;

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

            components.Add(component);
            computer.AddComponent(component);

            return(String.Format(SuccessMessages.AddedComponent, componentType, id, computerId));
        }
예제 #8
0
        public string AddComponent(int computerId, int id, string componentType,
                                   string manufacturer, string model, decimal price,
                                   double overallPerformance, int generation)
        {
            ComponentType cType     = new ComponentType();
            IComponent    component = null;

            if (DoesComputerExist(computerId))
            {
                throw new ArgumentException(COMPUTER_DOESNT_EXIST);
            }
            else if (computers.Where(x => x.Id == computerId).Any(x => x.Components.Any(x => x.Id == id)))
            {
                throw new ArgumentException("Component with this id already exists.");
            }
            else if (!Enum.TryParse <ComponentType>(componentType, out cType))
            {
                throw new ArgumentException("Component type is invalid.");
            }
            else if (cType == ComponentType.CentralProcessingUnit)
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (cType == ComponentType.Motherboard)
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (cType == ComponentType.PowerSupply)
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (cType == ComponentType.RandomAccessMemory)
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (cType == ComponentType.SolidStateDrive)
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (cType == ComponentType.VideoCard)
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
            }

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

            computer.AddComponent(component);
            return($"Component {component.GetType().Name} with id {component.Id} added successfully in computer with id {computer.Id}.");
        }
예제 #9
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            if (this.components.Any(c => c.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingComponentId);
            }
            IComputer  currentComp = ComputerWithIdExists(computerId);
            IComponent component   = CreateComponent(id, componentType, manufacturer, model, price, overallPerformance, generation);

            this.components.Add(component);
            currentComp.AddComponent(component);

            string outputMsg = string.Format(SuccessMessages.AddedComponent, componentType, id, computerId);

            return(outputMsg);
        }
예제 #10
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            IComputer comp = IsExist(computerId);

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

            if (!Enum.TryParse(componentType, out ComponentType))
            {
                throw new ArgumentException(ExceptionMessages.InvalidComponentType);
            }

            IComponent component = null;

            switch (ComponentType)
            {
            case ComponentType.CentralProcessingUnit:
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case ComponentType.Motherboard:
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case ComponentType.PowerSupply:
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case ComponentType.RandomAccessMemory:
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case ComponentType.SolidStateDrive:
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case ComponentType.VideoCard:
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
                break;
            }
            comp.AddComponent(component);
            components.Add(component);
            return(string.Format(SuccessMessages.AddedComponent, component.GetType().Name, id, comp.Id));
        }
예제 #11
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            this.ValidateComputerWithIdExists(computerId);

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

            IComponent component = CreateComponent(id, componentType, manufacturer, model, price, overallPerformance, generation);

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

            computer.AddComponent(component);
            this.components.Add(component);

            string result = string.Format(SuccessMessages.AddedComponent, componentType, id, computerId);

            return(result);
        }
예제 #12
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price,
                                   double overallPerformance, int generation)
        {
            CheckIfComputerIdExist(computerId);

            IComputer computer = _computers[computerId];

            if (_components.ContainsKey(id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingComponentId);
            }

            IComponent component = _factory.CreateComponent(id, componentType, manufacturer, model, price,
                                                            overallPerformance, generation);

            computer.AddComponent(component);
            _components.Add(id, component);

            return(string.Format(SuccessMessages.AddedComponent, componentType, id, computerId));
        }
예제 #13
0
        public string AddComponent(int computerId, int id,
                                   string componentType, string manufacturer,
                                   string model, decimal price, double overallPerformance,
                                   int generation)
        {
            CheckIfComponentAlreadyExist(id);
            IComponent component = CreateComponent(id, componentType,
                                                   manufacturer, model, price,
                                                   overallPerformance, generation);

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

            computer.AddComponent(component);

            components.Add(component);

            return(string.Format(SuccessMessages
                                 .AddedComponent, component.GetType().Name,
                                 component.Id, computerId));
        }