示例#1
0
 public IActionResult CreateCPU([Bind("Id,Name,Model,Rating,Price,Manufacturer,Color,Cores,Frequency,Series,Consumption")] CPU cpu)
 {
     if (ModelState.IsValid)
     {
         _context.Add(cpu);
         _context.SaveChanges();
         return(RedirectToAction(nameof(PartListPage)));
     }
     return(View("CreateCpu", cpu));
 }
示例#2
0
        public async Task <IActionResult> Create([Bind("FirstPartId", "SecondPartId")] TwoPartCompatibilities twoPartCompatibilities)
        {
            if (ModelState.IsValid)
            {
                var compatibility = new Compatibility();
                _context.Add(compatibility);
                var firstCompatibility = new PartCompatibility();
                firstCompatibility.Compatibility = compatibility;
                AddPartIdToCompatibility(firstCompatibility, twoPartCompatibilities.FirstPartId);
                _context.Add(firstCompatibility);
                var secondCompatibility = new PartCompatibility();
                secondCompatibility.Compatibility = compatibility;
                AddPartIdToCompatibility(secondCompatibility, twoPartCompatibilities.SecondPartId);
                _context.Add(secondCompatibility);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(twoPartCompatibilities));
        }
        public Build GetUnfinishedBuild()
        {
            var build = _context.Build
                        .Include(i => i.Cpu)
                        .Include(i => i.Cooler)
                        .Include(i => i.Motherboard)
                        .Include(i => i.Ram)
                        .Include(i => i.Storage)
                        .Include(i => i.Gpu)
                        .Include(i => i.Psu)
                        .Include(i => i.Case)
                        .Where(s => s.Status == "unfinished")
                        .FirstOrDefault();

            if (build == null)
            {
                build        = new Build();
                build.Status = "unfinished";

                _context.Add(build);
                _context.SaveChanges();
            }
            return(build);
        }