public ActionResult CreateComputer()
        {
            List <ComputerComponentDM> compMotherBoard = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.MotherBoard));
            var compMotherBoardItems = compMotherBoard.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compPowerSupply = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.PowerSupply));
            var compPowerSupplyItems = compPowerSupply.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compProcessor = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.Processor));
            var compProcessorItems = compProcessor.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compRAM = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.RAM));
            var compRAMItems = compRAM.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compROM = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.ROM));
            var compROMItems = compROM.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compSystemBlock = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.SystemBlock));
            var compSystemBlockItems = compSystemBlock.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compVideoCard = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.VideoCard));
            var compVideoCardItems = compVideoCard.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            CreateComputerVM comp = new CreateComputerVM();

            comp.MotherBoards  = compMotherBoardItems;
            comp.PowerSupplies = compPowerSupplyItems;
            comp.Processors    = compProcessorItems;
            comp.RAMs          = compRAMItems;
            comp.ROMs          = compROMItems;
            comp.SystemBlocks  = compSystemBlockItems;
            comp.VideoCards    = compVideoCardItems;
            return(View(comp));
        }
 public ActionResult CreateComputer(CreateComputerVM item)
 {
     if (ModelState.IsValid)
     {
         ProductDTO product = new ProductDTO()
         {
             Name = item.Name, Description = item.Description, Price = item.Price, Sale = item.Sale
         };
         ComputerDTO computer = new ComputerDTO();
         if (item.Images != null)
         {
             foreach (var i in item.Images)
             {
                 ImageDTO image = new ImageDTO();
                 image.Text = item.Alt;
                 using (var reader = new BinaryReader(i.InputStream))
                     image.Photo = reader.ReadBytes(i.ContentLength);
                 product.Images = new List <ImageDTO>();
                 product.Images.Add(image);
             }
         }
         else
         {
             product.Images = new List <ImageDTO>();
             foreach (var i in item.ImagesInDatebase)
             {
                 product.Images.Add(_mappers.ToImageDTO.Map <ImageDM, ImageDTO>(i));
             }
         }
         computer.MotherBoard = new ComputerComponentDTO()
         {
             Name = item.SelectedMotherBoard
         };
         computer.PowerSupply = new ComputerComponentDTO()
         {
             Name = item.SelectedPowerSupply
         };
         computer.Processor = new ComputerComponentDTO()
         {
             Name = item.SelectedProcessor
         };
         computer.SystemBlock = new ComputerComponentDTO()
         {
             Name = item.SelectedSystemBlock
         };
         computer.RAM = new List <ComputerComponentDTO>();
         foreach (var i in item.SelectedRAM)
         {
             computer.RAM.Add(new ComputerComponentDTO()
             {
                 Name = i
             });
         }
         computer.ROM = new List <ComputerComponentDTO>();
         foreach (var i in item.SelectedROM)
         {
             computer.ROM.Add(new ComputerComponentDTO()
             {
                 Name = i
             });
         }
         computer.VideoCard = new List <ComputerComponentDTO>();
         foreach (var i in item.SelectedVideoCard)
         {
             computer.VideoCard.Add(new ComputerComponentDTO()
             {
                 Name = i
             });
         }
         computer.Properties = _mappers.ToPropertyDTO.Map <ICollection <PropertyDM>, ICollection <PropertyDTO> >(item.Properties);
         OperationDetails result = _adminService.CreateComputer(product, computer, product.Name);
         ViewBag.Result = result.Message;
         ViewBag.Status = result.Succedeed;
         List <ComputerComponentDM> compMotherBoard = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.MotherBoard));
         var compMotherBoardItems = compMotherBoard.Select(x => new SelectListItem()
         {
             Text = x.Name, Value = x.Name
         }).ToList();
         List <ComputerComponentDM> compPowerSupply = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.PowerSupply));
         var compPowerSupplyItems = compPowerSupply.Select(x => new SelectListItem()
         {
             Text = x.Name, Value = x.Name
         }).ToList();
         List <ComputerComponentDM> compProcessor = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.Processor));
         var compProcessorItems = compProcessor.Select(x => new SelectListItem()
         {
             Text = x.Name, Value = x.Name
         }).ToList();
         List <ComputerComponentDM> compRAM = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.RAM));
         var compRAMItems = compRAM.Select(x => new SelectListItem()
         {
             Text = x.Name, Value = x.Name
         }).ToList();
         List <ComputerComponentDM> compROM = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.ROM));
         var compROMItems = compROM.Select(x => new SelectListItem()
         {
             Text = x.Name, Value = x.Name
         }).ToList();
         List <ComputerComponentDM> compSystemBlock = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.SystemBlock));
         var compSystemBlockItems = compSystemBlock.Select(x => new SelectListItem()
         {
             Text = x.Name, Value = x.Name
         }).ToList();
         List <ComputerComponentDM> compVideoCard = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.VideoCard));
         var compVideoCardItems = compVideoCard.Select(x => new SelectListItem()
         {
             Text = x.Name, Value = x.Name
         }).ToList();
         item.MotherBoards  = compMotherBoardItems;
         item.PowerSupplies = compPowerSupplyItems;
         item.Processors    = compProcessorItems;
         item.RAMs          = compRAMItems;
         item.ROMs          = compROMItems;
         item.SystemBlocks  = compSystemBlockItems;
         item.VideoCards    = compVideoCardItems;
         return(View(item));
     }
     return(View());
 }
        public ActionResult UpdateComputer(int id = 0)
        {
            ProductDM        product = _mappers.ToProductDM.Map <ProductDTO, ProductDM>(_adminService.GetProduct(id));
            ComputerDM       result  = _mappers.ToComputerDM.Map <ComputerDTO, ComputerDM>(_adminService.GetComputer(product.FromTableId));
            CreateComputerVM comp    = new CreateComputerVM()
            {
                Name                = product.Name,
                Description         = product.Description,
                Sale                = product.Sale,
                Price               = product.Price,
                SelectedMotherBoard = result.MotherBoard.Name,
                SelectedPowerSupply = result.PowerSupply.Name,
                SelectedProcessor   = result.Processor.Name,
                SelectedSystemBlock = result.SystemBlock.Name
            };

            comp.SelectedRAM = new List <string>();
            foreach (var i in result.RAM)
            {
                comp.SelectedRAM.Add(i.Name);
            }
            comp.SelectedROM = new List <string>();
            foreach (var i in result.ROM)
            {
                comp.SelectedROM.Add(i.Name);
            }
            comp.SelectedVideoCard = new List <string>();
            foreach (var i in result.VideoCard)
            {
                comp.SelectedVideoCard.Add(i.Name);
            }
            if (product.Images != null && product.Images.FirstOrDefault() != null)
            {
                comp.ImagesInDatebase = new List <ImageDM>();
                foreach (var i in product.Images)
                {
                    comp.ImagesInDatebase.Add(i);
                    comp.Alt = i.Text;
                }
            }
            List <ComputerComponentDM> compMotherBoard = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.MotherBoard));
            var compMotherBoardItems = compMotherBoard.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compPowerSupply = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.PowerSupply));
            var compPowerSupplyItems = compPowerSupply.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compProcessor = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.Processor));
            var compProcessorItems = compProcessor.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compRAM = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.RAM));
            var compRAMItems = compRAM.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compROM = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.ROM));
            var compROMItems = compROM.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compSystemBlock = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.SystemBlock));
            var compSystemBlockItems = compSystemBlock.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <ComputerComponentDM> compVideoCard = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.VideoCard));
            var compVideoCardItems = compVideoCard.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();

            comp.MotherBoards  = compMotherBoardItems;
            comp.PowerSupplies = compPowerSupplyItems;
            comp.Processors    = compProcessorItems;
            comp.RAMs          = compRAMItems;
            comp.ROMs          = compROMItems;
            comp.SystemBlocks  = compSystemBlockItems;
            comp.VideoCards    = compVideoCardItems;
            return(View("CreateComputer", comp));
        }