public static void UpdateSpec(VendorDefn vendorDefn) { using (FilamentContext context = new FilamentContext()) { if (context != null) { // flag the 'new' objects for added state SetDataItemsState(context, vendorDefn.SpoolDefns.Where(sd => sd.VendorDefnId == default), EntityState.Added); //foreach (var item in vendorDefn.SpoolDefns.Where(sd=>sd.VendorDefnId==default)) //{ // context.Entry<SpoolDefn>(item).State = EntityState.Added; //} // flag the 'modified' objects for modified state SetDataItemsState(context, vendorDefn.SpoolDefns.Where(sd => sd.IsModified && sd.VendorDefnId != default), EntityState.Modified); foreach (var sd in vendorDefn.SpoolDefns) { SetDataItemsState <InventorySpool>(context, sd.Inventory.Where(inv => inv.SpoolDefnId == default), EntityState.Added); SetDataItemsState <InventorySpool>(context, sd.Inventory.Where(inv => inv.IsModified && inv.SpoolDefnId != default), EntityState.Modified); foreach (var inv in sd.Inventory) { SetDataItemsState <DepthMeasurement>(context, inv.DepthMeasurements.Where(dm => dm.InventorySpoolId == default), EntityState.Added); SetDataItemsState <DepthMeasurement>(context, inv.DepthMeasurements.Where(dm => dm.InventorySpoolId != default && dm.IsModified), EntityState.Modified); } } //foreach(var item in vendorDefn.SpoolDefns.Where()) // context.Entry<SpoolDefn>(item).State= EntityState.Modified; context.Update(vendorDefn); context.SaveChanges(); } } }
public static VendorDefn[] InitialVendorDefinitions() { var vendor1 = new VendorDefn() { Name = "3d Solutech", WebUrl = "https://www.3dsolutech.com/", FoundOnAmazon = true }; vendor1.SpoolDefns.Add(new SpoolDefn() { Description = "Black plastic", DrumDiameter = 80, SpoolDiameter = 200, SpoolWidth = 55, Vendor = vendor1, Weight = 1 }); var vendor2 = new VendorDefn() { Name = "HatchBox", WebUrl = "https://www.hatchbox3d.com/", FoundOnAmazon = true }; vendor2.SpoolDefns.Add(new SpoolDefn() { Description = "Black plastic", DrumDiameter = 77, SpoolDiameter = 200, SpoolWidth = 63, Weight = 1, Vendor = vendor2 }); var vendor3 = new VendorDefn() { Name = "Sunlu", WebUrl = "http://www.sunlugw.com/" , FoundOnAmazon = true }; vendor3.SpoolDefns.Add(new SpoolDefn() { Description = "Clear plastic", DrumDiameter = 68, SpoolWidth = 55, SpoolDiameter = 195, Vendor = vendor3, Weight = 1 }); var vendor4 = new VendorDefn() { Name = "Flashforge", WebUrl = "https://flashforge-usa.com/", FoundOnAmazon = true }; vendor4.SpoolDefns.Add(new SpoolDefn() { Description = "Black plastic", DrumDiameter = 69, SpoolWidth = 58, SpoolDiameter = 200, Vendor = vendor4, Weight = 1 }); return(new VendorDefn[] { vendor1, vendor2, vendor3, vendor4, new VendorDefn() { Name = "Overture", WebUrl = "https://overture3d.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "Amolen", WebUrl = "https://amolen.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "Geetech", WebUrl = "https://www.geeetech.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "eSun", WebUrl = "https://esun3dstore.com/collections/3d-printing-filament", FoundOnAmazon = true }, new VendorDefn() { Name = "iSanMate", WebUrl = "http://www.isanmate.net/index.php?lang=en", FoundOnAmazon = true }, new VendorDefn() { Name = "Ziro", WebUrl = "https://ziro3d.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "Gudteks", WebUrl = "http://gudteks.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "Eryone", WebUrl = "https://eryone3d.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "Reprapper", WebUrl = "https://www.reprapwarehouse.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "Polymaker", WebUrl = "https://polymaker.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "Aystkniet", FoundOnAmazon = true }, new VendorDefn() { Name = "Comgrow", WebUrl = "https://www.comgrow.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "Shengtian", FoundOnAmazon = true }, new VendorDefn() { Name = "Gizmo Dorks", WebUrl = "https://gizmodorks.com/pla-3d-printer-filament/", FoundOnAmazon = true }, new VendorDefn() { Name = "CCTree3d", WebUrl = "http://www.cctree3dstore.com/collections/pla-filament-371", FoundOnAmazon = true }, new VendorDefn() { Name = "Monoprice", WebUrl = "https://www.monoprice.com/pages/3d_printers", FoundOnAmazon = true }, new VendorDefn() { Name = "Makerbot", WebUrl = "https://www.makerbot.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "Ataraxia", WebUrl = "https://ataraxiaart.com/", FoundOnAmazon = true }, new VendorDefn() { Name = "Prusament", WebUrl = "https://prusament.com/", FoundOnAmazon = true } }); }