Exemple #1
0
 public long Add(string name)
 {
     using (ZSZContext context = new ZSZContext())
     {
         RoleEntity r = new RoleEntity()
         {
             Name = name
         };
         context.Roles.Add(r);
         context.SaveChanges();
         return(r.Id);
     }
 }
Exemple #2
0
        public bool MarkDeleted(long id)
        {
            var data = GetById(id);

            data.IsDeleted = true;
            int r = zsz.SaveChanges();

            if (r > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        public long AddAdminUser(string name, string phoneNum, string password)
        {
            AdminUserEntity adminEf = new AdminUserEntity();

            adminEf.Name     = name;
            adminEf.PhoneNum = phoneNum;
            string salt = CommonHelper.CreateVerifyCode(5);//盐

            adminEf.PasswordSalt = salt;
            //Md5(盐+用户密码)
            string pwdHash = CommonHelper.CalcMD5(password + salt);//处理后的密码

            adminEf.PasswordHash = pwdHash;
            using (ZSZContext context = new ZSZContext())
            {
                context.AdminUsers.Add(adminEf);
                context.SaveChanges();
                return(adminEf.Id);
            }
        }
Exemple #4
0
        public void UpdateAdminUser(long id, string name, string phoneNum, string password)
        {
            using (ZSZContext ct = new ZSZContext())
            {
                BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ct);
                //先查询出来,再做更新
                var admin = bs.GetById(id);
                if (admin == null)
                {
                    throw new Exception("不存在id为" + id + "的管理员");
                }
                admin.Name     = name;
                admin.PhoneNum = phoneNum;
                if (!string.IsNullOrEmpty(password))
                {
                    admin.PasswordHash = CommonHelper.CalcMD5(password + admin.PasswordSalt);
                }

                ct.SaveChanges();
            }
        }
Exemple #5
0
 public void AddRoleIds(long adminUserId, long[] roleIds)
 {
     //1:通过adminUSerID获取管理员信息
     using (ZSZContext context = new ZSZContext())
     {
         BaseService <AdminUserEntity> adminService = new BaseService <AdminUserEntity>(context);
         var adminModel = adminService.GetById(adminUserId);
         if (adminModel == null)
         {
             throw new Exception("该用户不存在!!");
         }
         //2:添加对应的角色信息
         BaseService <RoleEntity> roleService = new BaseService <RoleEntity>(context);
         var roles = roleService.GetAll().Where(m => roleIds.Contains(m.Id)).ToArray();//获取选中的角色信息
         for (int i = 0; i < roles.Length; i++)
         {
             adminModel.Roles.Add(roles[i]);
         }
         context.SaveChanges();
     }
 }