public AdminHardwareVM AddHardware(AdminHardwareVM hw) { Hardware model = new Hardware() { HardwareID = hw.HardwareID, Category = hw.Category, DateDeleted = null, HardwareName = hw.HardwareName, Notes = hw.Notes, Faq = hw.Faq.Select(f => new FAQ() { Answer = f.Answer, FaqID = f.FaqID, DateDeleted = null, HardwareID = hw.HardwareID, Question = f.Question, Topic = f.Topic }).ToList(), }; using (ApplicationDbContext db = new ApplicationDbContext()) { db.Hardware.Add(model); db.SaveChanges(); } return hw; }
public AdminHardwareVM NewHardware(AdminHardwareVM hardware) { if (hardware != null) { Hardware model = new Hardware() { HardwareName = hardware.HardwareName, Notes = hardware.Notes, Category = hardware.Category, }; using (ApplicationDbContext db = new ApplicationDbContext()) { db.Hardware.Add(model); db.SaveChanges(); } } return hardware; }