Ejemplo n.º 1
0
 public bool CreateRole(string name,string displayName)
 {
     var rm = new RoleManager<ApplicationRole>(new RoleStore<ApplicationRole>(new EntityDbContext()));
     var role = new ApplicationRole() { Name = name, DisplayName = displayName };
     var idResult = rm.Create(role);
     return idResult.Succeeded;
 }
Ejemplo n.º 2
0
 public ApplicationRoleVM(ApplicationRole bo)
 {
     this.ID = Guid.Parse(bo.Id);
     this.Name = bo.Name;
     this.DisplayName = bo.DisplayName;
     this.Description = bo.Description;
     this.SortCode = bo.SortCode;
 }
Ejemplo n.º 3
0
 public ActionResult CreateOrEdit(string id)
 {
     bool isNew = false;
     var bo = _RoleManager.FindById(id);
     if (bo == null)
     {
         bo = new ApplicationRole();
         bo.Id = id;
         isNew = true;
     }
     var boVM = new ApplicationRoleVM(bo);
     var editor = PageComponentRepository<ApplicationRoleVM>.CreateOrEditDialog(boVM, isNew);
     return Json(editor);
 }
Ejemplo n.º 4
0
        public static bool AddUserAndRoles()
        {
            bool success = false;

            var idManager = new IdentityManager();
            var role1 = new ApplicationRole() { Name = "Admin", DisplayName = "系统管理员组", Description = "具备全部权限的用户组", SortCode = "001" };
            success = idManager.CreateRole(role1);
            if (!success == true) return success;

            var role2 = new ApplicationRole() { Name = "CanEdit", DisplayName = "业务数据编辑管理组", Description = "具备编辑一般业务数据权限的用户组", SortCode = "002" };
            success = idManager.CreateRole(role2);
            if (!success == true) return success;

            var role3 = new ApplicationRole() { Name = "User", DisplayName = "内部用户", Description = "内部操作用户组", SortCode = "003" };
            success = idManager.CreateRole(role3);
            if (!success) return success;

            var role4 = new ApplicationRole() { Name = "CustomerUser", DisplayName = "外部用户", Description = "外部操作用户组", SortCode = "004" };
            success = idManager.CreateRole(role4);
            if (!success) return success;

            var newUser = new ApplicationUser()
            {
                UserName = "******",
                FirstName = "李",
                LastName = "东生",
                ChineseFullName = "李东生",
                MobileNumber = "13899998888",
                Email = "*****@*****.**"
            };

            // 这里注意:创建的密码要满足响应的密码规则,否则将无法创建用户。
            success = idManager.CreateUser(newUser, "123@Abc");
            if (!success) return success;

            success = idManager.AddUserToRole(newUser.Id, "Admin");
            if (!success) return success;

            success = idManager.AddUserToRole(newUser.Id, "CanEdit");
            if (!success) return success;

            success = idManager.AddUserToRole(newUser.Id, "User");
            if (!success) return success;

            success = idManager.AddUserToRole(newUser.Id, "CustomerUser");
            if (!success) return success;

            return success;
        }
Ejemplo n.º 5
0
 public void MapToBo(ApplicationRole bo)
 {
     bo.Name = this.Name;
     bo.DisplayName = this.DisplayName;
     bo.Description = this.Description;
     bo.SortCode = this.SortCode;
 }
Ejemplo n.º 6
0
        public ActionResult Save(ApplicationRoleVM boVM)
        {
            if (ModelState.IsValid)
            {
                var bo = _RoleManager.FindById(boVM.ID.ToString());
                var isNew = false;
                if (bo == null)
                {
                    bo = new ApplicationRole();
                    bo.Id = boVM.ID.ToString();
                    isNew = true;
                }

                boVM.MapToBo(bo);

                if (isNew)
                    _RoleManager.Create(bo);
                else
                    _RoleManager.Update(bo);

                return Json(PageComponentRepository<ApplicationRoleVM>.SaveOK(true, "1", ""));
            }
            else
            {
                var vItems = new List<ValidatorResult>();
                foreach (var item in ModelState)
                {
                    if (item.Value.Errors != null)
                    {
                        foreach (var vItem in item.Value.Errors)
                        {
                            var errItem = new ValidatorResult();
                            errItem.Name = item.Key;
                            errItem.ErrorMessage = vItem.ErrorMessage;
                            vItems.Add(errItem);
                        }
                    }
                }

                var editor = PageComponentRepository<ApplicationRoleVM>.UpdateCreateOrEditDialog(boVM, false, vItems).InnerHtmlContent;
                return Json(editor);
            }
        }
Ejemplo n.º 7
0
 public bool CreateRole(ApplicationRole role)
 {
     var rm = new RoleManager<ApplicationRole>(new RoleStore<ApplicationRole>(new EntityDbContext()));
     var idResult = rm.Create(role);
     return idResult.Succeeded;
 }