/// <summary> /// 根据JSON写入数据 /// </summary> /// <param name="isClear">是否清理表,默认清理</param> /// <returns></returns> public int AddForJson(bool isClear = true) { var json = Core.FileTo.ReadText(JsonPath, JsonName); var objs = json.ToJObject()["data"]; var jsb = objs["SysButton"].ToString().ToEntitys <SysButton>(); var jsd = objs["SysDictionary"].ToString().ToEntitys <SysDictionary>(); var jsm = objs["SysMenu"].ToString().ToEntitys <SysMenu>(); var jsr = objs["SysRole"].ToString().ToEntitys <SysRole>(); var jstc = objs["SysTableConfig"].ToString().ToEntitys <SysTableConfig>(); var jsu = objs["SysUser"].ToString().ToEntitys <SysUser>(); var jte = objs["TempExample"].ToString().ToEntitys <TempExample>(); var jtid = objs["TempInvoiceDetail"].ToString().ToEntitys <TempInvoiceDetail>(); var jtim = objs["TempInvoiceMain"].ToString().ToEntitys <TempInvoiceMain>(); Tsb = Cdb.SysButton; Tsd = Cdb.SysDictionary; Tsm = Cdb.SysMenu; Tsr = Cdb.SysRole; Tstc = Cdb.SysTableConfig; Tsu = Cdb.SysUser; Tte = Cdb.TempExample; Ttid = Cdb.TempInvoiceDetail; Ttim = Cdb.TempInvoiceMain; var num = 0; if (isClear) { Tsb.RemoveRange(Tsb.ToList()); Tsd.RemoveRange(Tsd.ToList()); Tsm.RemoveRange(Tsm.ToList()); Tsr.RemoveRange(Tsr.ToList()); Tstc.RemoveRange(Tstc.ToList()); Tsu.RemoveRange(Tsu.ToList()); Tte.RemoveRange(Tte.ToList()); Ttid.RemoveRange(Ttid.ToList()); Ttim.RemoveRange(Ttim.ToList()); num = Cdb.SaveChanges(); } Tsb.AddRange(jsb); Tsd.AddRange(jsd); Tsm.AddRange(jsm); Tsr.AddRange(jsr); Tstc.AddRange(jstc); Tsu.AddRange(jsu); Tte.AddRange(jte); Ttid.AddRange(jtid); Ttim.AddRange(jtim); Cdb.AddRange(jsb); num += Cdb.SaveChanges(); return(num); }
/// <summary> /// 根据JSON写入数据 /// </summary> /// <param name="isClear">是否清理表,默认清理</param> /// <returns></returns> public ActionResultVM AddForJson(bool isClear = true) { var vm = new ActionResultVM(); try { var json = Core.FileTo.ReadText(fullJsonData); var objs = json.ToJObject()["data"]; var jsb = objs["SysButton"].ToString().ToEntitys <SysButton>(); var jsd = objs["SysDictionary"].ToString().ToEntitys <SysDictionary>(); var jsm = objs["SysMenu"].ToString().ToEntitys <SysMenu>(); var jsr = objs["SysRole"].ToString().ToEntitys <SysRole>(); var jstc = objs["SysTableConfig"].ToString().ToEntitys <SysTableConfig>(); var jsu = objs["SysUser"].ToString().ToEntitys <SysUser>(); var jte = objs["TempExample"].ToString().ToEntitys <TempExample>(); var jtid = objs["TempInvoiceDetail"].ToString().ToEntitys <TempInvoiceDetail>(); var jtim = objs["TempInvoiceMain"].ToString().ToEntitys <TempInvoiceMain>(); using var db = ContextBaseFactory.CreateDbContext(); Tsb = db.SysButton; Tsd = db.SysDictionary; Tsm = db.SysMenu; Tsr = db.SysRole; Tstc = db.SysTableConfig; Tsu = db.SysUser; Tte = db.TempExample; Ttid = db.TempInvoiceDetail; Ttim = db.TempInvoiceMain; var num = 0; if (isClear) { Tsb.RemoveRange(Tsb.ToList()); Tsd.RemoveRange(Tsd.ToList()); Tsm.RemoveRange(Tsm.ToList()); Tsr.RemoveRange(Tsr.ToList()); Tstc.RemoveRange(Tstc.ToList()); Tsu.RemoveRange(Tsu.ToList()); Tte.RemoveRange(Tte.ToList()); Ttid.RemoveRange(Ttid.ToList()); Ttim.RemoveRange(Ttim.ToList()); num = db.SaveChanges(); } Tsb.AddRange(jsb); Tsd.AddRange(jsd); Tsm.AddRange(jsm); Tsr.AddRange(jsr); Tstc.AddRange(jstc); Tsu.AddRange(jsu); Tte.AddRange(jte); Ttid.AddRange(jtid); Ttim.AddRange(jtim); db.AddRange(jsb); num += db.SaveChanges(); vm.Set(num > 0); } catch (Exception ex) { vm.Set(ex); } return(vm); }