Пример #1
0
        /// <summary>
        /// 角色赋权
        /// </summary>
        /// <param name="Parameter"></param>
        /// <returns></returns>
        public BaseResponse <bool> RoleAuthorization(RoleAuthorizationParameter Parameter)
        {
            BaseResponse <bool> result = new BaseResponse <bool>();

            try
            {
                if (Parameter.Module == null)
                {
                    Parameter.Module = new List <string>();
                }

                Validate validate = new Validate(userRepository, roleRepository);

                result = validate.ValidateRoleAuthorizationParameter(Parameter.RoleCode);
                if (!result.IsSuccessful)
                {
                    return(result);
                }

                using (var dataContext = new iCMSDbContext())
                {
                    dataContext.Configuration.AutoDetectChangesEnabled = false;
                    var roleModuleList =
                        (from p in dataContext.RoleModule
                         where p.RoleCode == Parameter.RoleCode
                         select p);
                    foreach (var item in roleModuleList)
                    {
                        dataContext.Entry(item).State = EntityState.Deleted;
                    }
                    var addRoleModuleList =
                        (from p in Parameter.Module
                         select new RoleModule
                    {
                        RoleCode = Parameter.RoleCode,
                        ModuleCode = p,
                    });
                    foreach (var item in addRoleModuleList)
                    {
                        dataContext.Entry(item).State = EntityState.Added;
                    }
                    dataContext.SaveChanges();
                }

                result.IsSuccessful = true;
                return(result);
            }
            catch (Exception e)
            {
                LogHelper.WriteLog(e);
                result.IsSuccessful = false;
                result.Code         = "004021";
                return(result);
            }
        }
Пример #2
0
 /// <summary>
 /// 角色赋权
 /// </summary>
 /// <param name="Parameter"></param>
 /// <returns></returns>
 public BaseResponse <bool> GetModuleForRole(RoleAuthorizationParameter Parameter)
 {
     if (ValidateData <RoleAuthorizationParameter>(Parameter))
     {
         return(roleManager.RoleAuthorization(Parameter));
     }
     else
     {
         BaseResponse <bool> result = new BaseResponse <bool>();
         result.IsSuccessful = false;
         result.Code         = "001291";
         LogHelper.WriteLog(string.Format("未通过安全验证:({0}:{1}", result.Code, result.Reason));
         return(result);
     }
 }