コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Weight,Tdp,Price")] Cooler cooler)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cooler);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cooler));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Ramtype ramtype)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ramtype);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ramtype));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Manufacturer,Power,Width,Height,Thickness,Price")] PowerSupply powerSupply)
        {
            if (ModelState.IsValid)
            {
                _context.Add(powerSupply);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(powerSupply));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Size,ReadSpeed,WriteSpeed,Interface,Width,Height,Thickness,Manufacturer,Price")] Drive drive)
        {
            if (ModelState.IsValid)
            {
                _context.Add(drive);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(drive));
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("Id,Name,CoreNumber,Clock,MemorySize,MemorySpeed,Price,InterfaceId")] Gpu gpu)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gpu);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["InterfaceId"] = new SelectList(_context.Gpuinterfaces, "Id", "Id", gpu.InterfaceId);
            return(View(gpu));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Size,TypeId,Manufacturer,Speed,Price")] Ram ram)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ram);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TypeId"] = new SelectList(_context.Ramtypes, "Id", "Name", ram.TypeId);
            return(View(ram));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("Id,Name,CoresNumber,ThreadsNumber,Clock,Manufacturer,Price,SocketId")] Cpu cpu)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cpu);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SocketId"] = new SelectList(_context.Sockets, "Id", "Name", cpu.SocketId);
            return(View(cpu));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("Id,Name,GpuinterfaceId,SocketId,Formfactor,RamtypeId,Ramcount,Usbcount,Price")] Motherboard motherboard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(motherboard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GpuinterfaceId"] = new SelectList(_context.Gpuinterfaces, "Id", "Id", motherboard.GpuinterfaceId);
            ViewData["RamtypeId"]      = new SelectList(_context.Ramtypes, "Id", "Name", motherboard.RamtypeId);
            ViewData["SocketId"]       = new SelectList(_context.Sockets, "Id", "Name", motherboard.SocketId);
            return(View(motherboard));
        }
コード例 #9
0
        public async Task <IActionResult> Import(IFormFile fileExcel)
        {
            if (ModelState.IsValid)
            {
                if (fileExcel != null)
                {
                    using (var stream = new FileStream(fileExcel.FileName, FileMode.Create))
                    {
                        await fileExcel.CopyToAsync(stream);

                        using (XLWorkbook workBook = new XLWorkbook(stream, XLEventTracking.Disabled))
                        {
                            var parser    = new ExcelParser(_context);
                            var computers = parser.getComputersFromExcel(workBook);

                            /*var coolers = parser.getCoolersFromExcel(workBook);
                            *  var cpus = parser.getCpusFromExcel(workBook);
                            *  var drives = parser.getDrivesFromExcel(workBook);
                            *  var gpuInterfaces = parser.getGpuInterfacesFromExcel(workBook);
                            *  var gpu = parser.getGpusFromExcel(workBook);
                            *  var motherboards = parser.getMotherboardsFromExcel(workBook);
                            *  var powerSupplies = parser.getPowerSuppliesFromExcel(workBook);
                            *  var rams = parser.getRamsFromExcel(workBook);
                            *  var ramTypes = parser.getRamTypesFromExcel(workBook);
                            *  var sockets = parser.getSocketsFromExcel(workBook);*/

                            /*List<SocketsToCooler> socketsToCoolers = new List<SocketsToCooler>();
                             * for (int i = 0; i < coolers.Count(); i++)
                             * {
                             *  for (int k = 0; k < coolers.ElementAt(i).SocketsToCoolers.Count(); k++)
                             *  {
                             *      var temp = new SocketsToCooler
                             *      {
                             *          CoolerId = coolers.ElementAt(i).Id,
                             *          SocketId = coolers.ElementAt(i).SocketsToCoolers.ElementAt(k).SocketId
                             *      };
                             *      coolers.ElementAt(i).SocketsToCoolers.Add(temp);
                             *      socketsToCoolers.Add(temp);
                             *  }
                             * }*/
                            //replaceListInDB(socketsToCoolers, _context.SocketsToCoolers.ToList(),new SocketsToCoolerComparer());
                            insertComputers(computers.ToList());
                            //replaceListInDB(coolers, _context.Coolers.ToList());
                            //replaceListInDB(cpus,  _context.Cpus.ToList());
                            //replaceListInDB(drives, _context.Drives.ToList());
                            //replaceListInDB(gpuInterfaces,  _context.Gpuinterfaces.ToList());
                            //replaceListInDB(gpu,  _context.Gpus.ToList());
                            //replaceListInDB(motherboards, _context.Motherboards.ToList());
                            //replaceListInDB(powerSupplies,  _context.PowerSupplies.ToList());
                            //replaceListInDB(rams,  _context.Rams.ToList());
                            //replaceListInDB(ramTypes, _context.Ramtypes.ToList());
                            //replaceListInDB(sockets,  _context.Sockets.ToList());
                            //setIdentityInsert();
                            await _context.SaveChangesAsync();

                            List <RamsToComputer> ramToComputers = new List <RamsToComputer>();
                            for (int i = 0; i < computers.Count(); i++)
                            {
                                for (int k = 0; k < computers.ElementAt(i).SelectedRam.Count(); k++)
                                {
                                    var temp = new RamsToComputer
                                    {
                                        ComputerId = computers.ElementAt(i).Id,
                                        Ramid      = computers.ElementAt(i).SelectedRam[k]
                                    };
                                    computers.ElementAt(i).RamsToComputers.Add(temp);
                                    _context.Add(temp);
                                }
                            }
                            List <ComputersToDrive> drivesToComputers = new List <ComputersToDrive>();
                            for (int i = 0; i < computers.Count(); i++)
                            {
                                for (int k = 0; k < computers.ElementAt(i).SelectedDrive.Count(); k++)
                                {
                                    var temp = new ComputersToDrive
                                    {
                                        ComputerId = computers.ElementAt(i).Id,
                                        DriveId    = computers.ElementAt(i).SelectedDrive[k]
                                    };
                                    computers.ElementAt(i).ComputersToDrives.Add(temp);
                                    _context.Add(temp);
                                }
                            }

                            //replaceListInDB(ramToComputers, _context.RamsToComputers.ToList(),new RamsToComputerComparer());
                            //replaceListInDB(drivesToComputers, _context.ComputersToDrives.ToList(),new ComputersToDriveComparer());
                            await _context.SaveChangesAsync();

                            //setIdentityNotInsert();
                        }
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }