public static bool AddCdu(Cdu.Info cdu) { try { using (var ctx = new LocalDB()) { Database.LocalDB.Model.CDU newcdu = new Database.LocalDB.Model.CDU() { No = cdu.cduNo, Name = cdu.cduName, Extendable = cdu.isExtended, IpAddress = cdu.ip, Enabled = cdu.isUsing, InstallAt = cdu.installDate, }; using (var trx = new TransactionScope()) { ctx.Cdu.Add(newcdu); ctx.SaveChanges(); trx.Complete(); } } return true; } catch (Exception e) { Console.WriteLine($"AddCdu : {e.ToString()}"); return false; } }
public static bool SetCdu(Cdu.Info cdu) { try { using (var ctx = new LocalDB()) { var existCdu = (from c in ctx.Cdu where c.Idx == cdu.cduIdx select c).DefaultIfEmpty(null).First(); if (existCdu == null) return false; //existCdu.GroupNo = cdu. existCdu.No = cdu.cduNo; existCdu.Name = cdu.cduName; existCdu.Extendable = cdu.isExtended; existCdu.IpAddress = cdu.ip; existCdu.Enabled = cdu.isUsing; existCdu.InstallAt = cdu.installDate; //existCdu.Description = cdu. using (var trx = new TransactionScope()) { ctx.SaveChanges(); trx.Complete(); } } return true; } catch (Exception e) { Console.WriteLine($"SetCdu : {e.ToString()}"); return false; } }