Пример #1
0
        public ActionResult PartialDetails(int id)
        {
            var motherBoard = _motherBoardService.GetMotherBoard(id);

            if (motherBoard == null)
            {
                return(NotFound());
            }
            var model = new MotherBoardViewModel()
            {
                Id        = motherBoard.Id,
                Name      = motherBoard.Name,
                MaxMemory = motherBoard.MaxMemory,
                CPUSocket = motherBoard.CPUSocket.Name,
                MotherBoardNothernBridge = motherBoard.MotherBoardNothernBridge.Name,
                MotherBoardFormFactor    = motherBoard.MotherBoardFormFactor.Name,
                Manufacturer             = motherBoard.Manufacturer.Name,
                VideoCardInterfaces      = motherBoard.MotherBoardVideoCardSlots.Select(m => new VideoCardInterfaceViewModel {
                    Id = m.VideoCardInterface.Id, Name = m.VideoCardInterface.Name, Multiplier = m.VideoCardInterface.Multiplier, Version = m.VideoCardInterface.Version
                }).ToList(),
                MotherBoardRAMSlots = motherBoard.MotherBoardRAMSlots.Select(m => new RAMTypeViewModel {
                    Id = m.RAMType.Id, Name = m.RAMType.Name
                }).ToList(),
                PowerSupplyMotherBoardInterfaces = motherBoard.PowerSupplyMotherBoardSlots.Select(m => new PowerSupplyMotherBoardInterfaceViewModel {
                    Id = m.PowerSupplyMotherBoardInterface.Id, Name = m.PowerSupplyMotherBoardInterface.Name
                }).ToList(),
                OuterMemoryInterfaces = motherBoard.MotherBoardOuterMemorySlots.Select(m => new OuterMemoryInterfaceViewModel {
                    Id = m.OuterMemoryInterface.Id, Name = m.OuterMemoryInterface.Name
                }).ToList(),
                Price       = motherBoard.Price,
                ImagePath   = "/Images/MotherBoard/" + motherBoard.Image,
                Description = motherBoard.Description
            };

            return(PartialView("PartialDetails", model));
        }
Пример #2
0
        public ActionResult Edit(MotherBoardViewModel model)
        {
            var motherBoard = _motherBoardService.GetMotherBoard(model.Id);

            if (motherBoard == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (model.OuterMemoryInterfaces == null)
                {
                    model.OuterMemoryInterfaces = new List <OuterMemoryInterfaceViewModel>();
                }
                if (model.VideoCardInterfaces == null)
                {
                    model.VideoCardInterfaces = new List <VideoCardInterfaceViewModel>();
                }
                if (model.MotherBoardRAMSlots == null)
                {
                    model.MotherBoardRAMSlots = new List <RAMTypeViewModel>();
                }
                if (model.PowerSupplyMotherBoardInterfaces == null)
                {
                    model.PowerSupplyMotherBoardInterfaces = new List <PowerSupplyMotherBoardInterfaceViewModel>();
                }
                motherBoard.Name                       = model.Name;
                motherBoard.Description                = model.Description;
                motherBoard.MaxMemory                  = model.MaxMemory;
                motherBoard.CPUSocketId                = model.CPUSocketId;
                motherBoard.ManufacturerId             = model.ManufacturerId;
                motherBoard.MotherBoardNothernBridgeId = model.MotherBoardNothernBridgeId;
                motherBoard.MotherBoardFormFactorId    = model.MotherBoardFormFactorId;
                motherBoard.Price                      = model.Price;

                if (model.Image != null)
                {
                    var helper = new ImageHelper(_webHostEnvironment);
                    var image  = helper.GetUploadedFile(model.Image, "MotherBoard");
                    motherBoard.Image = image;
                }
                motherBoard.MotherBoardOuterMemorySlots = model.OuterMemoryInterfaces.Select(m => new MotherBoardOuterMemorySlot()
                {
                    OuterMemoryInterfaceId = m.Id
                }).ToList();
                motherBoard.MotherBoardVideoCardSlots = model.VideoCardInterfaces.Select(m => new MotherBoardVideoCardSlot()
                {
                    VideoCardInterfaceId = m.Id.Value
                }).ToList();
                motherBoard.MotherBoardRAMSlots = model.MotherBoardRAMSlots.Select(m => new MotherBoardRAMSlot()
                {
                    RAMTypeId = m.Id
                }).ToList();
                motherBoard.PowerSupplyMotherBoardSlots = model.PowerSupplyMotherBoardInterfaces.Select(m => new MotherBoardPowerSupplySlot()
                {
                    PowerSupplyMotherBoardInterfaceId = m.Id
                }).ToList();

                var result = _motherBoardService.UpdateMotherBoard(motherBoard);

                model.Id    = motherBoard.Id;
                model.Image = null;

                if (result.Succedeed)
                {
                    return(View("../Catalog/Index", new { startView = "MotherBoard" }));
                }

                return(NotFound(result));
            }
            var sockets = _cpuSocketService.GetCPUSockets();

            ViewBag.Sockets = new SelectList(sockets, "Id", "Name");
            var manufacturers = _manufacturerService.GetManufacturers();

            ViewBag.Manufacturers = new SelectList(manufacturers, "Id", "Name");
            var motherBoardFormFactors = _motherBoardFormFactorService.GetMotherBoardFormFactors();

            ViewBag.MotherBoardFormFactors = new SelectList(motherBoardFormFactors, "Id", "Name");
            var motherBoardNothernBridges = _northBridgeService.GetMotherBoardNorthBridges();

            ViewBag.MotherBoardNothernBridges = new SelectList(motherBoardNothernBridges, "Id", "Name");
            var outerMemoryInterfaces = _outerMemoryInterfaceService.GetOuterMemoryInterfaces();

            ViewBag.OuterMemoryInterfaces = new SelectList(outerMemoryInterfaces, "Id", "Name");
            var videoCardInterfaces = _videoCardInterfaceService.GetVideoCardInterfaces().Select(m => new VideoCardInterfaceViewModel()
            {
                Id = m.Id, Name = m.Name, Multiplier = m.Multiplier, Version = m.Version
            });

            ViewBag.VideoCardInterfaces = new SelectList(videoCardInterfaces, "Id", "FullName");
            var powerSupplyMotherBoardInterfaces = _powerSupplyMotherBoardInterfaceService.GetPowerSupplyMotherBoardInterfaces();

            ViewBag.PowerSupplyMotherBoardInterface = new SelectList(powerSupplyMotherBoardInterfaces, "Id", "Name");
            var ramTypes = _ramTypeService.GetRAMTypes();

            ViewBag.RamTypes = new SelectList(ramTypes, "Id", "Name");
            return(View("Edit", model));
        }
Пример #3
0
        public ActionResult Edit(int id)
        {
            var motherBoard = _motherBoardService.GetMotherBoard(id);

            if (motherBoard == null)
            {
                return(NotFound());
            }

            var model = new MotherBoardViewModel()
            {
                Id          = motherBoard.Id,
                Name        = motherBoard.Name,
                MaxMemory   = motherBoard.MaxMemory,
                CPUSocket   = motherBoard.CPUSocket.Name,
                CPUSocketId = motherBoard.CPUSocketId,
                MotherBoardNothernBridge = motherBoard.MotherBoardNothernBridge.Name,
                MotherBoardFormFactor    = motherBoard.MotherBoardFormFactor.Name,
                MotherBoardFormFactorId  = motherBoard.MotherBoardFormFactorId,
                Manufacturer             = motherBoard.Manufacturer.Name,
                VideoCardInterfaces      = motherBoard.MotherBoardVideoCardSlots.Select(m => new VideoCardInterfaceViewModel {
                    Id = m.VideoCardInterface.Id, Name = m.VideoCardInterface.Name, Multiplier = m.VideoCardInterface.Multiplier, Version = m.VideoCardInterface.Version
                }).ToList(),
                MotherBoardRAMSlots = motherBoard.MotherBoardRAMSlots.Select(m => new RAMTypeViewModel {
                    Id = m.RAMType.Id, Name = m.RAMType.Name
                }).ToList(),
                PowerSupplyMotherBoardInterfaces = motherBoard.PowerSupplyMotherBoardSlots.Select(m => new PowerSupplyMotherBoardInterfaceViewModel {
                    Id = m.PowerSupplyMotherBoardInterface.Id, Name = m.PowerSupplyMotherBoardInterface.Name
                }).ToList(),
                OuterMemoryInterfaces = motherBoard.MotherBoardOuterMemorySlots.Select(m => new OuterMemoryInterfaceViewModel {
                    Id = m.OuterMemoryInterface.Id, Name = m.OuterMemoryInterface.Name
                }).ToList(),
                Price       = motherBoard.Price,
                ImagePath   = "/Images/MotherBoard/" + motherBoard.Image,
                Description = motherBoard.Description
            };

            var sockets = _cpuSocketService.GetCPUSockets();

            ViewBag.Sockets = new SelectList(sockets, "Id", "Name");
            var manufacturers = _manufacturerService.GetManufacturers();

            ViewBag.Manufacturers = new SelectList(manufacturers, "Id", "Name");
            var motherBoardFormFactors = _motherBoardFormFactorService.GetMotherBoardFormFactors();

            ViewBag.MotherBoardFormFactors = new SelectList(motherBoardFormFactors, "Id", "Name");
            var motherBoardNothernBridges = _northBridgeService.GetMotherBoardNorthBridges();

            ViewBag.MotherBoardNothernBridges = new SelectList(motherBoardNothernBridges, "Id", "Name");
            var outerMemoryInterfaces = _outerMemoryInterfaceService.GetOuterMemoryInterfaces();

            ViewBag.OuterMemoryInterfaces = new SelectList(outerMemoryInterfaces, "Id", "Name");
            var videoCardInterfaces = _videoCardInterfaceService.GetVideoCardInterfaces().Select(m => new VideoCardInterfaceViewModel()
            {
                Id = m.Id, Name = m.Name, Multiplier = m.Multiplier, Version = m.Version
            });

            ViewBag.VideoCardInterfaces = new SelectList(videoCardInterfaces, "Id", "FullName");
            var powerSupplyMotherBoardInterfaces = _powerSupplyMotherBoardInterfaceService.GetPowerSupplyMotherBoardInterfaces();

            ViewBag.PowerSupplyMotherBoardInterfaces = new SelectList(powerSupplyMotherBoardInterfaces, "Id", "Name");
            var ramTypes = _ramTypeService.GetRAMTypes();

            ViewBag.RamTypes = new SelectList(ramTypes, "Id", "Name");
            return(View("Edit", model));
        }