public ActionResult PartialDetails(int id) { var pcCase = _pcCaseService.GetPCCase(id); if (pcCase == null) { return(NotFound()); } var model = new PCCaseViewModel() { Id = pcCase.Id, Name = pcCase.Name, WeightDisplay = CreateWeightDescription(pcCase.Weight), PCCaseMotherBoardFormFactors = pcCase.PCCaseMotherBoardFormFactors.Select(m => new MotherBoardFormFactorViewModel() { Id = m.MotherBoardFormFactor.Id, Name = m.MotherBoardFormFactor.Name }).ToList(), PCCaseOuterMemoryFormFactors = pcCase.PCCaseOuterMemoryFormFactors.Select(m => new OuterMemoryFormFactorViewModel() { Id = m.OuterMemoryFormFactors.Id, Name = m.OuterMemoryFormFactors.Name }).ToList(), Manufacturer = pcCase.Manufacturer.Name, Price = pcCase.Price, ImagePath = "/Images/PCCase/" + pcCase.Image, Description = pcCase.Description }; return(PartialView("PartialDetails", model)); }
//[ValidateAntiForgeryToken] public IActionResult Create(PCCaseViewModel model) { if (ModelState.IsValid) { if (model.PCCaseOuterMemoryFormFactors == null) { model.PCCaseOuterMemoryFormFactors = new List <OuterMemoryFormFactorViewModel>(); } if (model.PCCaseMotherBoardFormFactors == null) { model.PCCaseMotherBoardFormFactors = new List <MotherBoardFormFactorViewModel>(); } var helper = new ImageHelper(_webHostEnvironment); var image = helper.GetUploadedFile(model.Image, "PCCase"); var pcCase = new PCCase() { Name = model.Name, Description = model.Description, Weight = model.Weight, ManufacturerId = model.ManufacturerId, Image = image, Price = model.Price }; pcCase.PCCaseMotherBoardFormFactors = model.PCCaseMotherBoardFormFactors.Select(m => new PCCaseMotherBoardFormFactor() { MotherBoardFormFactorId = m.Id }).ToList(); pcCase.PCCaseOuterMemoryFormFactors = model.PCCaseOuterMemoryFormFactors.Select(m => new PCCaseOuterMemoryFormFactor() { OuterMemoryFormFactorId = m.Id }).ToList(); var result = _pcCaseService.CreatePCCase(pcCase); if (result.Succedeed) { return(View("../Catalog/Index", new { startView = "PCCase" })); } return(NotFound(result)); } var motherBoardFormFactorService = _motherBoardFormFactorService.GetMotherBoardFormFactors(); ViewBag.MotherBoardFormFactors = new SelectList(motherBoardFormFactorService, "Id", "Name"); var outerMemoryFormFactors = _outerMemoryFormFactorService.GetOuterMemoryFormFactors(); ViewBag.OuterMemoryFormFactors = new SelectList(outerMemoryFormFactors, "Id", "Name"); var manufacturers = _manufacturerService.GetManufacturers(); ViewBag.Manufacturers = new SelectList(manufacturers, "Id", "Name"); return(View(model)); }
public ActionResult Edit(int id) { var pcCase = _pcCaseService.GetPCCase(id); if (pcCase == null) { return(NotFound()); } var model = new PCCaseViewModel() { Name = pcCase.Name, Description = pcCase.Description, ManufacturerId = pcCase.ManufacturerId, Weight = pcCase.Weight, Price = pcCase.Price, PCCaseMotherBoardFormFactors = pcCase.PCCaseMotherBoardFormFactors.Select(m => new MotherBoardFormFactorViewModel() { Id = m.MotherBoardFormFactor.Id, Name = m.MotherBoardFormFactor.Name }).ToList(), PCCaseOuterMemoryFormFactors = pcCase.PCCaseOuterMemoryFormFactors.Select(m => new OuterMemoryFormFactorViewModel() { Id = m.OuterMemoryFormFactors.Id, Name = m.OuterMemoryFormFactors.Name }).ToList(), ImagePath = "/Images/PCCase/" + pcCase.Image }; var motherBoardFormFactorService = _motherBoardFormFactorService.GetMotherBoardFormFactors(); ViewBag.MotherBoardFormFactors = new SelectList(motherBoardFormFactorService, "Id", "Name"); var outerMemoryFormFactors = _outerMemoryFormFactorService.GetOuterMemoryFormFactors(); ViewBag.OuterMemoryFormFactors = new SelectList(outerMemoryFormFactors, "Id", "Name"); var manufacturers = _manufacturerService.GetManufacturers(); ViewBag.Manufacturers = new SelectList(manufacturers, "Id", "Name"); return(View("Edit", model)); }