Пример #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)
        {
            var computer = this.computers.FirstOrDefault(x => x.Id == computerId);

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

            Models.Products.Components.IComponent component = null;

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

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

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

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

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

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

            if (component == null)
            {
                throw new ArgumentException("Component type is invalid.");
            }

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

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

            return($"Component {component.GetType().Name} with id {component.Id} added successfully in computer with id {computer.Id}.");
        }
Пример #3
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));
        }