Пример #1
0
        public IActionResult Add(Drive drive)
        {
            if (ModelState.IsValid)
            {
                Drive newDrive = new Drive
                {
                    DriveCapacity     = drive.DriveCapacity,
                    DriveConnectivity = drive.DriveConnectivity,
                    DriveRead         = drive.DriveRead,
                    DriveSize         = drive.DriveSize,
                    DriveWrite        = drive.DriveWrite,
                    DriveSpec         = drive.DriveSpec,
                    PCComponentId     = drive.PCComponentId
                };

                dataContext.Drives.Add(newDrive);
                dataContext.SaveChanges();
                return(RedirectToAction("Index", "Drive"));
            }
            else
            {
                var product = dataContext.PCComponents.Where(p => p.ComponentCategoryId == 3).ToList();
                var cpuList = dataContext.Drives.ToList();
                List <PCComponent> itemSelected = product;
                foreach (var item in cpuList)
                {
                    PCComponent query = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == item.PCComponentId);
                    itemSelected.Remove(query);
                }
                ViewBag.Selected = new SelectList(itemSelected, "PCComponentId", "PCComponentName");
                return(View(drive));
            }
        }
Пример #2
0
        public IActionResult Add(Case casePC)
        {
            if (ModelState.IsValid)
            {
                Case newCase = new Case
                {
                    CaseColor     = casePC.CaseColor,
                    CaseDimension = casePC.CaseDimension,
                    CaseDrive     = casePC.CaseDrive,
                    CaseMaterial  = casePC.CaseMaterial,
                    CasePort      = casePC.CasePort,
                    CaseSpec      = casePC.CaseSpec,
                    CaseSupport   = casePC.CaseSupport,
                    PCComponentId = casePC.PCComponentId
                };

                dataContext.Cases.Add(newCase);
                dataContext.SaveChanges();
                return(RedirectToAction("Index", "Case"));
            }
            else
            {
                var product  = dataContext.PCComponents.Where(p => p.ComponentCategoryId == 8).ToList();
                var caseList = dataContext.Cases.ToList();
                List <PCComponent> itemSelected = product;
                foreach (var item in caseList)
                {
                    PCComponent query = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == item.PCComponentId);
                    itemSelected.Remove(query);
                }
                ViewBag.Selected = new SelectList(itemSelected, "PCComponentId", "PCComponentName");
                return(View(casePC));
            }
        }
Пример #3
0
        public IActionResult DeleteConfirmed(int id)
        {
            PCComponent component = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == id);

            dataContext.PCComponents.Remove(component);
            dataContext.SaveChanges();
            return(RedirectToAction("Index", "Component"));
        }
Пример #4
0
        public void Constructor_Called_CanCreatePCComponent()
        {
            //Arrange
            var componentName = NamesGenerator.ComponentName();
            var component     = new PCComponent(componentName, ValidComponentType);

            Assert.That(component.Name, Is.EqualTo(componentName));
        }
        private IEnumerable <ComponentType> GetContainedComponentTypes(PCComponent component)
        {
            yield return(component.Type);

            foreach (var type in component.ContainedComponents.SelectMany(GetContainedComponentTypes))
            {
                yield return(type);
            }
        }
        public void Delete(IPCComponent component)
        {
            using (PCConfigurationContext context = new PCConfigurationContext())
            {
                PCComponent pCComponentToDelete = context.PCComponents.FirstOrDefault(c => c.ID == (component as PCComponent).ID);
                pCComponentToDelete.Status = Core.Common.EntityStatus.Deleted;

                context.SaveChanges();
            }
        }
        public byte[] GetImageByComponent(IPCComponent component)
        {
            using (PCConfigurationContext context = new PCConfigurationContext())
            {
                PCComponent pCComponent     = component as PCComponent;
                PCComponent resultComponent = context.PCComponents.FirstOrDefault(c => c.ID == pCComponent.ID);

                return(resultComponent?.Image);
            }
        }
Пример #8
0
 private void AssertComponentsEqual(PCComponent savedComp, PCComponent loadedComp)
 {
     Assert.That(loadedComp, Is.Not.Null);
     Assert.That(loadedComp.AveragePrice, Is.EqualTo(savedComp.AveragePrice));
     Assert.That(loadedComp.Name, Is.EqualTo(savedComp.Name));
     Assert.That(UtilsAssert.CollectionsEqual(savedComp.ContainedSlots, loadedComp.ContainedSlots));
     Assert.That(UtilsAssert.CollectionsEqual(savedComp.PlugSlots, loadedComp.PlugSlots));
     Assert.That(UtilsAssert.CollectionsEqual(savedComp.ContainedComponents, loadedComp.ContainedComponents));
     Assert.That(UtilsAssert.CollectionsEqual(savedComp.CharacteristicValues, loadedComp.CharacteristicValues,
                                              CompareCharacteristicValues));
 }
Пример #9
0
        public IActionResult Index()
        {
            var item = dataContext.Coolings.ToList();
            List <PCComponent> pcComponents = new List <PCComponent>();

            foreach (var item2 in item)
            {
                PCComponent pcComponent = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == item2.PCComponentId);
                pcComponents.Add(pcComponent);
            }
            return(View(item));
        }
Пример #10
0
        public IActionResult Add()
        {
            Cooling            cooling      = new Cooling();
            var                product      = dataContext.PCComponents.Where(p => p.ComponentCategoryId == 5).ToList();
            var                coolingList  = dataContext.Coolings.ToList();
            List <PCComponent> itemSelected = product;

            foreach (var item in coolingList)
            {
                PCComponent query = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == item.PCComponentId);
                itemSelected.Remove(query);
            }
            ViewBag.Selected = new SelectList(itemSelected, "PCComponentId", "PCComponentName");
            return(View(cooling));
        }
Пример #11
0
        public IActionResult Add()
        {
            Drive drive     = new Drive();
            var   product   = dataContext.PCComponents.Where(p => p.ComponentCategoryId == 3).ToList();
            var   driveList = dataContext.Drives.ToList();
            List <PCComponent> itemSelected = product;

            foreach (var item in driveList)
            {
                PCComponent query = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == item.PCComponentId);
                itemSelected.Remove(query);
            }
            ViewBag.Selected = new SelectList(itemSelected, "PCComponentId", "PCComponentName");
            return(View(drive));
        }
Пример #12
0
        public IActionResult Add()
        {
            Graphic            graphic      = new Graphic();
            var                product      = dataContext.PCComponents.Where(p => p.ComponentCategoryId == 2).ToList();
            var                gpuList      = dataContext.Graphics.ToList();
            List <PCComponent> itemSelected = product;

            foreach (var item in gpuList)
            {
                PCComponent query = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == item.PCComponentId);
                itemSelected.Remove(query);
            }
            ViewBag.Selected = new SelectList(itemSelected, "PCComponentId", "PCComponentName");
            return(View(graphic));
        }
Пример #13
0
        public IActionResult Add()
        {
            //Buu dep trai
            CPU cpu     = new CPU();
            var product = dataContext.PCComponents.Where(p => p.ComponentCategoryId == 1).ToList();
            var cpuList = dataContext.CPUs.ToList();
            List <PCComponent> itemSelected = product;

            foreach (var item in cpuList)
            {
                PCComponent query = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == item.PCComponentId);
                itemSelected.Remove(query);
            }
            ViewBag.Selected = new SelectList(itemSelected, "PCComponentId", "PCComponentName");
            return(View(cpu));
        }
Пример #14
0
        public IActionResult Add()
        {
            PCComponent    pcComponent  = new PCComponent();
            var            product      = dataContext.Products.Where(p => p.CategoryId == 3).ToList();
            var            name         = dataContext.PCComponents.ToList();
            List <Product> itemSelected = product;

            foreach (var item in name)
            {
                Product query = dataContext.Products.FirstOrDefault(p => p.ProductId == item.ProductId);
                itemSelected.Remove(query);
            }
            ViewBag.Selected = new SelectList(itemSelected, "ProductId", "ProductName");
            var category = dataContext.ComponentCategories.Select(p => p).ToList();

            ViewBag.Category = new SelectList(category, "ComponentCategoryId", "ComponentCategoryName");
            return(View(pcComponent));
        }
Пример #15
0
        private List <PCComponent> CreateComponents(List <ComponentInterface> slotsToInsert,
                                                    List <ComponentCharacteristic> characteristics)
        {
            var componentsToInsert = new List <PCComponent>();

            for (var i = 0; i < 5; i++)
            {
                var newComponent = new PCComponent(NamesGenerator.ComponentName(i), ComponentType.PowerSupply);
                newComponent
                .WithAveragePrice(100 * (i + 1))
                .WithPlugSlot(slotsToInsert.RandomElement())
                .WithContainedSlot(slotsToInsert.RandomElement())
                .WithContainedSlot(slotsToInsert.RandomElementExcept(newComponent.ContainedSlots.ToList()));
                componentsToInsert.Add(newComponent);
                AddCharacteristicsToComponent(characteristics, newComponent);
            }
            CreateRandomLinks(componentsToInsert);
            return(componentsToInsert);
        }
Пример #16
0
 public IActionResult Add(Graphic graphic)
 {
     if (ModelState.IsValid)
     {
         Graphic newGPU = new Graphic
         {
             GraphicBus          = graphic.GraphicBus,
             GraphicConnector    = graphic.GraphicConnector,
             GraphicCooling      = graphic.GraphicCooling,
             GraphicCore         = graphic.GraphicCore,
             GraphicDimension    = graphic.GraphicDimension,
             GraphicGPU          = graphic.GraphicGPU,
             GraphicGPUBoost     = graphic.GraphicGPUBoost,
             GraphicLED          = graphic.GraphicLED,
             GraphicMaxMonitor   = graphic.GraphicMaxMonitor,
             GraphicMemFrequency = graphic.GraphicMemFrequency,
             GraphicMemory       = graphic.GraphicMemory,
             GraphicMinPower     = graphic.GraphicMinPower,
             GraphicPCI          = graphic.GraphicPCI,
             GraphicPort         = graphic.GraphicPort,
             GraphicPower        = graphic.GraphicPower,
             GraphicResolution   = graphic.GraphicResolution,
             GraphicSeries       = graphic.GraphicSeries,
             PCComponentId       = graphic.PCComponentId
         };
         dataContext.Graphics.Add(newGPU);
         dataContext.SaveChanges();
         return(RedirectToAction("Index", "GPU"));
     }
     else
     {
         var product = dataContext.PCComponents.Where(p => p.ComponentCategoryId == 2).ToList();
         var gpuList = dataContext.Graphics.ToList();
         List <PCComponent> itemSelected = product;
         foreach (var item in gpuList)
         {
             PCComponent query = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == item.PCComponentId);
             itemSelected.Remove(query);
         }
         ViewBag.Selected = new SelectList(itemSelected, "PCComponentId", "PCComponentName");
         return(View(graphic));
     }
 }
Пример #17
0
        public IActionResult Add(CPU cpu)
        {
            if (ModelState.IsValid)
            {
                CPU newCPU = new CPU
                {
                    CPUCache      = cpu.CPUCache,
                    CPUCore       = cpu.CPUCore,
                    CPUCode       = cpu.CPUCode,
                    CPUModel      = cpu.CPUModel,
                    CPUPower      = cpu.CPUPower,
                    CPUProcess    = cpu.CPUProcess,
                    CPUSocket     = cpu.CPUSocket,
                    CPUSpeed      = cpu.CPUSpeed,
                    CPUThread     = cpu.CPUThread,
                    CPUTurbo      = cpu.CPUTurbo,
                    PCComponentId = cpu.PCComponentId,
                };

                dataContext.CPUs.Add(newCPU);
                dataContext.SaveChanges();
                return(RedirectToAction("Index", "CPU"));
            }
            else
            {
                var product = dataContext.PCComponents.Where(p => p.ComponentCategoryId == 1).ToList();
                var cpuList = dataContext.CPUs.ToList();
                List <PCComponent> itemSelected = product;
                foreach (var item in cpuList)
                {
                    PCComponent query = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == item.PCComponentId);
                    itemSelected.Remove(query);
                }
                ViewBag.Selected = new SelectList(itemSelected, "PCComponentId", "PCComponentName");
                return(View(cpu));
            }
        }
        public static void Main(string[] args)
        {
            PCComponent vga = new PCComponent("VGA", "Intel HD Graphics 4400", 256.6M);
            PCComponent vga2 = new PCComponent("VGA", "Intel HD Graphics 5000", 306.6M);
            PCComponent ssd = new PCComponent("SSD 250GB", "Samsung 850 EVO", 207.9M);
            PCComponent ssd2 = new PCComponent("SSD 120GB", "A-Data Pro SP920", 114.64M);
            PCComponent ram = new PCComponent("RAM", "Мноо бърза!", 199.89M);
            PCComponent cpu = new PCComponent("Processor", "Intel Core i5", 399.52M);
            PCComponent cpu2 = new PCComponent("Processor", "Intel Core i7", 499.02M);
            PCComponent kb = new PCComponent("Keyboard", "Подарък!", 0M);

            List<Computer> computers = new List<Computer>()
            {
                new Computer("Dell", cpu, ssd, kb),
                new Computer("Alienware", cpu2, ssd2, vga),
                new Computer("HP", ram, vga2, kb),
                new Computer("Apple", cpu, kb),
            };

               computers
                .OrderBy(computer => computer.Price)
                .ToList()
                .ForEach(Console.WriteLine);
        }
Пример #19
0
 public IActionResult Add(PCComponent pcComponent)
 {
     if (ModelState.IsValid)
     {
         var         query     = dataContext.Products.Find(pcComponent.ProductId);
         PCComponent component = new PCComponent
         {
             ProductId           = pcComponent.ProductId,
             ComponentCategoryId = pcComponent.ComponentCategoryId,
             PCComponentName     = query.ProductName
         };
         dataContext.PCComponents.Add(component);
         dataContext.SaveChanges();
         return(RedirectToAction("Index", "Component"));
     }
     else
     {
         var item = dataContext.Products.Where(p => p.CategoryId == 3).ToList();
         ViewBag.Selected = new SelectList(item, "ProductId", "ProductName");
         var component = dataContext.ComponentCategories.ToList();
         ViewBag.Category = new SelectList(component, "ComponentCategoryId", "ComponentCategoryName");
         return(View(pcComponent));
     }
 }
Пример #20
0
        public IActionResult Add(Cooling cooling)
        {
            if (ModelState.IsValid)
            {
                Cooling newCooling = new Cooling
                {
                    CoolingColor     = cooling.CoolingColor,
                    CoolingDimension = cooling.CoolingDimension,
                    CoolingLED       = cooling.CoolingLED,
                    CoolingMaterial  = cooling.CoolingMaterial,
                    CoolingNoise     = cooling.CoolingNoise,
                    CoolingRPM       = cooling.CoolingRPM,
                    CoolingSocket    = cooling.CoolingSocket,
                    CoolingSpec      = cooling.CoolingSpec,
                    CoolingWeight    = cooling.CoolingWeight,
                    PCComponentId    = cooling.PCComponentId
                };

                dataContext.Coolings.Add(newCooling);
                dataContext.SaveChanges();
                return(RedirectToAction("Index", "Cooling"));
            }
            else
            {
                var product     = dataContext.PCComponents.Where(p => p.ComponentCategoryId == 5).ToList();
                var coolingList = dataContext.Coolings.ToList();
                List <PCComponent> itemSelected = product;
                foreach (var item in coolingList)
                {
                    PCComponent query = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == item.PCComponentId);
                    itemSelected.Remove(query);
                }
                ViewBag.Selected = new SelectList(itemSelected, "PCComponentId", "PCComponentName");
                return(View(cooling));
            }
        }
 private void SaveComponent(PCComponent addedComponent)
 {
     _provider.PCExpertContext.PCComponents.Add(addedComponent);
 }
Пример #22
0
        public IActionResult Delete(int id)
        {
            PCComponent component = dataContext.PCComponents.FirstOrDefault(p => p.PCComponentId == id);

            return(View(component));
        }
Пример #23
0
 private void AddCharacteristicsToComponent(List <ComponentCharacteristic> characteristics, PCComponent newComponent)
 {
     for (var j = 0; j < 3; j++)
     {
         var characteristic = characteristics.RandomElementExcept(newComponent.Characteristics.Keys.ToList());
         var value          = _characteristicHandlers.First(x => x.CharacteristicType.IsInstanceOfType(characteristic))
                              .CreateRandomValue(characteristic);
         newComponent.WithCharacteristicValue(value);
     }
 }
Пример #24
0
 public void Save(PCComponent component)
 {
     _workplace.Save(component);
 }
Пример #25
0
 public void EstablishContext()
 {
     DefaultComponent = CreateComponent(1);
 }
Пример #26
0
        public void NameLengthValidationTests(int nameLength, int expectedErrorsCount)
        {
            var component = new PCComponent("".PadLeft(nameLength, '*'), ComponentType.PowerSupply);

            AssertErrorsCount(component, expectedErrorsCount);
        }