public int PopulateDatabase() { try { CustomComputersAspEntities db = new CustomComputersAspEntities(); int materialsid = this.InsertMaterials(); string producerMonitor = this.monitor.GetMonitorProducer(); string ledMonitor = this.monitor.GetLed(); string aspectRatioMonitor = this.monitor.GetAspecRatio().Item1.ToString() + "x" + this.monitor.GetAspecRatio().Item2.ToString(); string matrixMonitor = this.monitor.GetMatrixAndMatrixProducer().Item1; Monitor match = db.Monitors.FirstOrDefault(m => m.led == ledMonitor && m.aspectRatio == aspectRatioMonitor && m.producer == producerMonitor && m.matrix == matrixMonitor && m.materialsId == materialsid); if (match == null) { db.AddToMonitors(new Monitor() { led = ledMonitor, aspectRatio = aspectRatioMonitor, producer = producerMonitor, materialsId = materialsid, matrix = matrixMonitor }); db.SaveChanges(); match = db.Monitors.FirstOrDefault(m => m.led == ledMonitor && m.aspectRatio == aspectRatioMonitor && m.producer == producerMonitor && m.matrix == matrixMonitor && m.materialsId == materialsid); } return(match.id); } catch (Exception ex) { Console.WriteLine("Could not successfully populate DB with monitor information. Reason: {0}", ex.Message); return(0); } }
public int PopulateDatabase() { try { CustomComputersAspEntities db = new CustomComputersAspEntities(); int materialsid = this.InsertMaterials(); string producerMonitor = this.monitor.GetMonitorProducer(); string ledMonitor = this.monitor.GetLed(); string aspectRatioMonitor = this.monitor.GetAspecRatio().Item1.ToString() + "x" + this.monitor.GetAspecRatio().Item2.ToString(); string matrixMonitor = this.monitor.GetMatrixAndMatrixProducer().Item1; Monitor match = db.Monitors.FirstOrDefault(m => m.led == ledMonitor && m.aspectRatio == aspectRatioMonitor && m.producer == producerMonitor && m.matrix == matrixMonitor && m.materialsId == materialsid); if (match == null) { db.AddToMonitors(new Monitor() { led = ledMonitor, aspectRatio = aspectRatioMonitor, producer = producerMonitor, materialsId = materialsid, matrix = matrixMonitor }); db.SaveChanges(); match = db.Monitors.FirstOrDefault(m => m.led == ledMonitor && m.aspectRatio == aspectRatioMonitor && m.producer == producerMonitor && m.matrix == matrixMonitor && m.materialsId == materialsid); } return match.id; } catch (Exception ex) { Console.WriteLine("Could not successfully populate DB with monitor information. Reason: {0}", ex.Message); return 0; } }