Example #1
0
 /// <summary>
 /// 保存模块
 /// </summary>
 /// <param name="module">模块实体</param>
 public void SaveModule(Module module)
 {
     using (AuthentContext db = new AuthentContext())
     {
         if (module.Id == 0)
         {
             db.Module.Add(module);
         }
         else
         {
             Module mod;
             mod = db.Module.Where(m => m.Id == module.Id).FirstOrDefault();
             if (mod != null)
             {
                 mod.ChineseName     = module.ChineseName;
                 mod.Description     = module.Description;
                 mod.EnglishName     = module.EnglishName;
                 mod.LastChangeTime  = module.LastChangeTime;
                 mod.LastChangeUser  = module.LastChangeUser;
                 mod.NavigatePicture = module.NavigatePicture;
                 mod.IsDisplay       = module.IsDisplay;
                 mod.Status          = module.Status;
                 mod.Icon            = module.Icon;
                 mod.Order           = module.Order;
                 mod.Url             = module.Url;
                 mod.ParentId        = module.ParentId;
             }
         }
         db.SaveChanges();
     }
 }
Example #2
0
        /// <summary>
        /// 保存用户
        /// </summary>
        /// <param name="userIn">用户实体</param>
        public void SaveUser(User userIn)
        {
            userIn.PassWord = Base64(userIn.PassWord);

            using (AuthentContext db = new AuthentContext())
            {
                if (userIn.Id == 0)
                {
                    db.User.Add(userIn);
                }
                else
                {
                    User user = new User();
                    user                = db.User.Where(u => u.Id == userIn.Id).FirstOrDefault();
                    user.UserName       = userIn.UserName;
                    user.Id             = userIn.Id;
                    user.PassWord       = userIn.PassWord;
                    user.Phone          = userIn.Phone;
                    user.Age            = userIn.Age;
                    user.Email          = userIn.Email;
                    user.MobilePhone    = userIn.MobilePhone;
                    user.RealName       = userIn.RealName;
                    user.Sex            = userIn.Sex;
                    user.LastChangeTime = userIn.LastChangeTime;
                    user.LastChangeUser = userIn.LastChangeUser;
                    user.Status         = userIn.Status;
                    user.UserName       = userIn.UserName;
                    user.UserName       = userIn.UserName;
                }
                db.SaveChanges();
            }
        }
Example #3
0
 /// <summary>
 /// 登录验证
 /// </summary>
 /// <param name="userLogin">登陆的用户</param>
 /// <returns></returns>
 public User IsValid(User userLogin)
 {
     if (string.IsNullOrEmpty(userLogin.UserName) || string.IsNullOrEmpty(userLogin.PassWord))
     {
         return(null);
     }
     else
     {
         using (AuthentContext db = new AuthentContext())
         {
             int userCount = db.User.Count();
             //如果用户表没有用户,则新增一名用户
             if (userCount == 0)
             {
                 db.User.Add(new User
                 {
                     UserName       = "******",
                     PassWord       = Base64("admin"),
                     RealName       = "admin",
                     MobilePhone    = "13243211111",
                     Email          = "*****@*****.**",
                     LastChangeUser = 0,
                     LastChangeTime = DateTime.Now,
                 });
                 db.SaveChanges();
             }
             string base64Pass = Base64(userLogin.PassWord);
             User   user       = db.User.Where(u => u.UserName == userLogin.UserName && u.PassWord == base64Pass)
                                 .FirstOrDefault();
             return(user);
         }
     }
 }
Example #4
0
 /// <summary>
 /// 删除一个模块信息
 /// </summary>
 /// <param name="id">模块ID</param>
 public void DeleteMain(int id)
 {
     using (AuthentContext db = new AuthentContext())
     {
         Module mainDic = db.Module.Where(m => m.Id == id).FirstOrDefault();
         db.Module.Remove(mainDic);
         db.SaveChanges();
     }
 }
Example #5
0
 /// <summary>
 /// 删除一个数据字典项
 /// </summary>
 /// <param name="id">数据字典主表ID</param>
 public void DeleteDic(int id)
 {
     using (AuthentContext db = new AuthentContext())
     {
         Dictionary dic = db.Dictionary.Where(m => m.Id == id).FirstOrDefault();
         db.Dictionary.Remove(dic);
         db.SaveChanges();
     }
 }
Example #6
0
 /// <summary>
 /// 删除用户
 /// </summary>
 /// <param name="id">用户ID</param>
 /// <returns></returns>
 public void Delete(int id)
 {
     using (AuthentContext db = new AuthentContext())
     {
         User user = db.User.Where(u => u.Id == id).FirstOrDefault();
         if (user != null)
         {
             db.User.Remove(user);
             db.SaveChanges();
         }
     }
 }
Example #7
0
 /// <summary>
 /// 删除角色
 /// </summary>
 /// <param name="id">角色ID</param>
 /// <returns></returns>
 public void Delete(int id)
 {
     using (AuthentContext db = new AuthentContext())
     {
         Role role = db.Role.Where(u => u.Id == id).FirstOrDefault();
         if (role != null)
         {
             db.Role.Remove(role);
             db.SaveChanges();
         }
     }
 }
Example #8
0
 /// <summary>
 /// 保存数据字典主表
 /// </summary>
 /// <param name="mainDic">数据字典主表实体</param>
 public void SaveMainDiction(MainDictionary mainDic)
 {
     using (AuthentContext db = new AuthentContext())
     {
         if (mainDic.Id == 0)
         {
             db.MainDictionary.Add(mainDic);
         }
         else
         {
             MainDictionary mainDiction = new MainDictionary();
             mainDiction                = db.MainDictionary.Where(m => m.Id == mainDic.Id).FirstOrDefault();
             mainDiction.ChineseName    = mainDic.ChineseName;
             mainDiction.Description    = mainDic.Description;
             mainDiction.EnglishName    = mainDic.EnglishName;
             mainDiction.LastChangeTime = mainDic.LastChangeTime;
             mainDiction.LastChangeUser = mainDic.LastChangeUser;
             mainDiction.ReadOnly       = mainDic.ReadOnly;
         }
         db.SaveChanges();
     }
 }
Example #9
0
 /// <summary>
 /// 保存数据字典项
 /// </summary>
 /// <param name="diction">数据字典主表实体</param>
 public void SaveDiction(Dictionary diction)
 {
     using (AuthentContext db = new AuthentContext())
     {
         if (diction.Id == 0)
         {
             db.Dictionary.Add(diction);
         }
         else
         {
             Dictionary dictionary = db.Dictionary.Where(d => d.Id == diction.Id).FirstOrDefault();
             dictionary.ChineseName      = diction.ChineseName;
             dictionary.Description      = diction.Description;
             dictionary.EnglishName      = diction.EnglishName;
             dictionary.LastChangeTime   = diction.LastChangeTime;
             dictionary.LastChangeUser   = diction.LastChangeUser;
             dictionary.Order            = diction.Order;
             dictionary.Status           = diction.Status;
             dictionary.MainDictionaryId = diction.MainDictionaryId;
         }
         db.SaveChanges();
     }
 }
Example #10
0
        /// <summary>
        /// 保存选择的角色
        /// </summary>
        /// <param name="roleIds">角色数组</param>
        /// <param name="moduleId">当前模块ID</param>
        /// <param name="changeUser">修改人ID</param>
        public void SaveModuleRoles(List <int> roleIds, int moduleId, int changeUser)
        {
            using (AuthentContext db = new AuthentContext())
            {
                //先要删除这个模块的角色
                var roles = db.RoleModule.Where(rm => rm.ModuleId == moduleId);
                db.RoleModule.RemoveRange(roles);

                //再重新保存
                List <RoleModule> roleModels = new List <RoleModule>();
                foreach (var roleId in roleIds)
                {
                    RoleModule roleModel = new RoleModule();
                    roleModel.ModuleId       = moduleId;
                    roleModel.RoleId         = roleId;
                    roleModel.LastChangeTime = DateTime.Now;
                    roleModel.LastChangeUser = changeUser;
                    roleModels.Add(roleModel);
                }
                db.RoleModule.AddRange(roleModels);

                db.SaveChanges();
            }
        }
Example #11
0
        /// <summary>
        /// 保存选择的角色
        /// </summary>
        /// <param name="roleIds">角色数组</param>
        /// <param name="userId">用户ID</param>
        /// <param name="changeUser">修改人ID</param>
        public void SaveUserRoles(List <int> roleIds, int userId, int changeUser)
        {
            using (AuthentContext db = new AuthentContext())
            {
                //先要删除这个用户的角色
                var roles = db.UserRole.Where(ur => ur.UserId == userId);
                db.UserRole.RemoveRange(roles);

                //再重新保存
                List <UserRole> userRoles = new List <UserRole>();
                foreach (var roleId in roleIds)
                {
                    UserRole userRole = new UserRole();
                    userRole.UserId         = userId;
                    userRole.RoleId         = roleId;
                    userRole.LastChangeTime = DateTime.Now;
                    userRole.LastChangeUser = changeUser;
                    userRoles.Add(userRole);
                }
                db.UserRole.AddRange(userRoles);

                db.SaveChanges();
            }
        }
Example #12
0
 /// <summary>
 /// 保存角色
 /// </summary>
 /// <param name="roleIn">角色实体</param>
 public void SaveRole(Role roleIn)
 {
     using (AuthentContext db = new AuthentContext())
     {
         if (roleIn.Id == 0)
         {
             db.Role.Add(roleIn);
         }
         else
         {
             Role role = new Role();
             role = db.Role.Where(u => u.Id == roleIn.Id).FirstOrDefault();
             if (role != null)
             {
                 role.RoleName       = roleIn.RoleName;
                 role.Description    = roleIn.Description;
                 role.Code           = roleIn.Code;
                 role.LastChangeTime = roleIn.LastChangeTime;
                 role.LastChangeUser = roleIn.LastChangeUser;
             }
         }
         db.SaveChanges();
     }
 }
Example #13
0
        /// <summary>
        /// 保存选择的模块
        /// </summary>
        /// <param name="moduleIds">模块Id数组</param>
        /// <param name="roleId">角色ID</param>
        /// <param name="changeUser">修改人ID</param>
        public void SaveRoleModules(List <int> moduleIds, int roleId, int changeUser)
        {
            using (AuthentContext db = new AuthentContext())
            {
                //先要删除这个角色的模块
                var modules = db.RoleModule.Where(rm => rm.RoleId == roleId);
                db.RoleModule.RemoveRange(modules);

                //再重新保存
                List <RoleModule> roleModules = new List <RoleModule>();
                foreach (var moduleId in moduleIds)
                {
                    RoleModule roleModule = new RoleModule();
                    roleModule.ModuleId       = moduleId;
                    roleModule.RoleId         = roleId;
                    roleModule.LastChangeTime = DateTime.Now;
                    roleModule.LastChangeUser = changeUser;
                    roleModules.Add(roleModule);
                }
                db.RoleModule.AddRange(roleModules);

                db.SaveChanges();
            }
        }