// GET: CPU/Details/5 public ActionResult Details(int id) { var cpu = _cpuService.GetCPU(id); if (cpu == null) { return(NotFound()); } var model = new CPUViewModel() { Id = cpu.Id, Name = cpu.Name, CoresName = cpu.CoresName, CoresNumber = cpu.CoresNumber, Description = cpu.Description, Frequency = cpu.Frequency, MaxFrequency = cpu.MaxFrequency, CPUSocketId = cpu.CPUSocketId, CPUSocket = cpu.CPUSocket.Name, ManufacturerId = cpu.ManufacturerId, Manufacturer = cpu.Manufacturer.Name, FrequencyDisplay = ((double)cpu.Frequency / 1000) + " GHz", MaxFrequencyDisplay = ((double)cpu.MaxFrequency / 1000) + " GHz", ThreadsNumber = cpu.ThreadsNumber, Price = cpu.Price, ImagePath = "/Images/CPU/" + cpu.Image }; return(View(model)); }
public IActionResult Create(SoftwareViewModel model) { if (model.SoftwareCPURequirements == null) { model.SoftwareCPURequirements = new List <SoftwareCPURequirement>(); } if (model.SoftwareVideoCardRequirements == null) { model.SoftwareVideoCardRequirements = new List <SoftwareVideoCardRequirement>(); } if (model.MinimiumRequiredRAM > model.RecommendedRequiredRAM) { ModelState.AddModelError("MinimiumRequiredRAM", "Мінімальні вимоги не можуть бути кращими за рекомендовані"); } var newMinCpus = model.SoftwareCPURequirements.Where(m => m.RequirementTypeId == 1).Select(m => _cpuService.GetCPU(m.CPUId)); var newReqCpus = model.SoftwareCPURequirements.Where(m => m.RequirementTypeId == 2).Select(m => _cpuService.GetCPU(m.CPUId)); var newMinVC = model.SoftwareVideoCardRequirements.Where(m => m.RequirementTypeId == 1).Select(m => _videoCardService.GetVideoCard(m.VideoCardId)); var newReqVC = model.SoftwareVideoCardRequirements.Where(m => m.RequirementTypeId == 2).Select(m => _videoCardService.GetVideoCard(m.VideoCardId)); if (newMinCpus.Any(m => newReqCpus.Any(z => m.Frequency > z.Frequency || m.ThreadsNumber > z.ThreadsNumber || m.CoresNumber > z.CoresNumber))) { ModelState.AddModelError("SoftwareCPURequirements", "Мінімальні вимоги не можуть бути кращими за рекомендовані"); } if (newMinVC.Any(m => newReqVC.Any(z => m.Frequency > z.Frequency || m.MemoryFrequency > z.MemoryFrequency || m.MemorySize > z.MemorySize))) { ModelState.AddModelError("SoftwareVideoCardRequirements", "Мінімальні вимоги не можуть бути кращими за рекомендовані"); } if (ModelState.IsValid) { var helper = new ImageHelper(_webHostEnvironment); var image = helper.GetUploadedFile(model.Image, "Software"); var powerSupply = new Software() { Name = model.Name, Description = model.Description, DiscVolume = model.DiscVolume, MinimiumRequiredRAM = model.MinimiumRequiredRAM, RecommendedRequiredRAM = model.RecommendedRequiredRAM, PublisherId = model.PublisherId, DeveloperId = model.DeveloperId, Image = image, Price = model.Price }; powerSupply.SoftwareCPURequirements = model.SoftwareCPURequirements.Select(m => new SoftwareCPURequirement() { CPUId = m.CPUId, RequirementTypeId = m.RequirementTypeId }).ToList(); powerSupply.SoftwareVideoCardRequirements = model.SoftwareVideoCardRequirements.Select(m => new SoftwareVideoCardRequirement() { VideoCardId = m.VideoCardId, RequirementTypeId = m.RequirementTypeId }).ToList(); var result = _softwareService.CreateSoftware(powerSupply); if (result.Succedeed) { return(View("../Catalog/Index", new { startView = "Software" })); } return(NotFound(result)); } var cpus = _cpuService.GetCPUs(); ViewBag.CPUs = new SelectList(cpus, "Id", "Name"); var videoCards = _videoCardService.GetVideoCards(); ViewBag.VideoCards = new SelectList(videoCards, "Id", "Name"); var publishers = _publisherService.GetPublishers(); ViewBag.Publishers = new SelectList(publishers, "Id", "Name"); var developers = _developerService.GetDevelopers(); ViewBag.Developers = new SelectList(developers, "Id", "Name"); return(View(model)); }