Exemplo n.º 1
0
        /// <summary>
        /// 保存树形组织结构(刷全表数据/BatchUpdate),先取出来所有的Branch,Staff的ParentId为0,然后在根据RootBranch的树形结构赋对应的值
        /// </summary>
        /// <param name="rootBranch"></param>
        public void SaveOrg(Branch rootBranch)
        {
            using (var dbContext = new OADbContext())
            {
                var branchs = dbContext.Branchs.ToList();
                branchs.ForEach(b => b.ParentId = 0);

                var staffs = dbContext.Staffs.ToList();
                staffs.ForEach(s => s.BranchId = 0);

                UpdateOrg(branchs, staffs, rootBranch);

                dbContext.SaveChanges();
            }
        }
Exemplo n.º 2
0
 public static void SeedHostDb(OADbContext db)
 {
     if (db.Database.EnsureCreated())
     {
         //create seed data
         var user = db.SysUsers.Where(m => m.UserName == "admin").FirstOrDefault();
         if (user == null)
         {
             var sysUser = new SysUser
             {
                 Password = Md5Helper.Encrypt("123456"),
                 UserName = "******",
                 NickName = "leo"
             };
             db.SysUsers.Add(sysUser);
             db.SaveChanges();
         }
     }
 }