public static bool SaveTelType(C_TelType entity) { //using (TransactionScope scope = new TransactionScope()) //{ using (MainDataContext dbContext = new MainDataContext(AppConfig.ConnectionStringDispatch)) { if (entity.编码 == 0) //添加 { var list = dbContext.TZTelType.Select(t => t.编码); long total = list.LongCount(); if (total == 0) { entity.编码 = 1; //entity.顺序号 = 1; } else { entity.编码 = dbContext.TZTelType.Max(t => t.编码) + 1; //entity.顺序号 = dbContext.TZTelType.Max(t => t.顺序号) + 1; } TZTelType type = new TZTelType(); type.编码 = entity.编码; type.称 = entity.称; type.级编码 = entity.级编码; type.是否有效 = entity.是否有效; type.顺序号 = entity.顺序号; dbContext.TZTelType.InsertOnSubmit(type); using (MainDataContext Context = new MainDataContext()) { //自定义通讯录类别 if (entity.归属人ID != 0) { B_TELTYPE_CUSTOM custom = new B_TELTYPE_CUSTOM(); custom.编码 = entity.编码; custom.归属人ID = entity.归属人ID; Context.B_TELTYPE_CUSTOM.InsertOnSubmit(custom); Context.SubmitChanges(); } } dbContext.SubmitChanges(); //scope.Complete(); return(true); } else //修改 { var model = dbContext.TZTelType.FirstOrDefault(t => t.编码 == entity.编码); model.编码 = entity.编码; model.称 = entity.称; model.级编码 = entity.级编码; model.是否有效 = entity.是否有效; model.顺序号 = entity.顺序号; dbContext.SubmitChanges(); //scope.Complete(); return(true); } } //} }
public bool SaveTelType(C_TelType entity) { return DAL.BasicInfo.TelBook.SaveTelType(entity); }