public async Task Create(CreateRoleInput input) { var exsitRole = await _roleRepository.FirstOrDefaultAsync(p => p.Name == input.Name); if (exsitRole != null) { throw new BusinessException($"系统中已经存在{input.Name}的角色"); } var role = input.MapTo <Role>(); await UnitOfWorkAsync(async (conn, trans) => { var roleId = await _roleRepository.InsertAndGetIdAsync(role, conn, trans); var queryOperationSql = "SELECT o.* FROM `Operation` as o LEFT JOIN Permission as p ON o.PermissionId = p.Id AND p.IsDeleted = 0 AND o.IsDeleted = 0 WHERE o.PermissionId IN @PermissionIds"; var operations = await conn.QueryAsync <Operation>(queryOperationSql, new { PermissionIds = input.PermissionIds }, transaction: trans); if (!operations.Any(p => p.Mold == Shared.Operations.OperationMold.Query || p.Mold == Shared.Operations.OperationMold.Look)) { throw new BusinessException($"分配的权限至少要包含查询或是查看类型操作"); } await _rolePermissionRepository.DeleteAsync(p => p.RoleId == roleId, conn, trans); foreach (var permissionId in input.PermissionIds) { var permission = await _permissionRepository.SingleOrDefaultAsync(p => p.Id == permissionId); if (permission == null) { throw new BusinessException($"不存在Id为{permissionId}的权限信息"); } await _rolePermissionRepository.InsertAsync(new RolePermission() { PermissionId = permissionId, RoleId = roleId }, conn, trans); } }, Connection); }
/// <summary> /// 创建新角色 /// </summary> public async Task CreateRole(CreateRoleInput input, int tenantId) { using (CurrentUnitOfWork.SetTenantId(tenantId)) { await _roleAppService.CreateRole(input); } }
public async Task <string> Create(CreateRoleInput input) { input.CheckDataAnnotations().CheckValidResult(); await _roleDomainService.Create(input); return("新增角色信息成功"); }
public IHttpActionResult CreateRole(CreateRoleInput input) { Init(); input.AccessToken = ApiSession.AccessToken; CreateRoleOutput output = _rolesSvc.CreateRole(input); return(Ok(output)); }
public async Task Edit(CreateRoleInput model) { var entity = await _roleRepository.GetAsync(model.Id); entity.Name = model.Name; entity.DisplayName = model.DisplayName; await _roleRepository.UpdateAsync(entity); }
public async Task <int> Create(CreateRoleInput model) { var entity = model.MapTo <Role>(); entity.TenantId = 1; var userid = await _roleRepository.InsertAndGetIdAsync(entity); return(userid); }
/// <summary> /// 创建新角色 /// </summary> public async Task CreateRole(CreateRoleInput input) { var role = new SysRole(AbpSession.TenantId, input.Name, input.DisplayName) { IsDefault = input.IsDefault }; CheckErrors(await _roleManager.CreateAsync(role)); }
public async Task <string> Create(CreateRoleInput input) { input.CheckDataAnnotations().CheckValidResult(); CheckIsAllOrg(input); //_session.CheckLoginUserDataPermision(input.DataPermissionType,"您设置的角色的数据权限大于您拥有数据权限,系统不允许该操作"); await _roleDomainService.Create(input); return("新增角色信息成功"); }
public async Task Create(CreateRoleInput input) { var exsitRole = await _roleRepository.FirstOrDefaultAsync(p => p.Name == input.Name); if (exsitRole != null) { throw new BusinessException($"系统中已经存在{input.Name}的角色"); } var role = input.MapTo <Role>(); await _roleRepository.InsertAsync(role); }
//[AbpMvcAuthorize("Administration.Role")] public async Task <JsonResult> Edit(CreateRoleInput model) { if (ModelState.IsValid) { await _roleAppService.Edit(model); return(Json(new { result = true, errors = "" })); } return(Json(new { result = false, errors = ModelState.AllModelStateErrors() })); }
public Role Addinfo(CreateRoleInput input) { Role role = new Role() { RoleName = input.RoleName, Remark = input.Remark, CreateUser = input.CreateUser, CreateTime = DateTime.Now, OrderID = input.OrderID, CreateIP = IPHelper.GetIPAddress }; db.Roles.Add(role); List <RoleNavAction> roleNavActions = new List <RoleNavAction>(); if (!string.IsNullOrEmpty(input.Nav_SelActions)) { string[] NavSelActionArr = input.Nav_SelActions.Split(','); foreach (var nav in NavSelActionArr) { if (!string.IsNullOrWhiteSpace(nav)) { var arr = nav.Split('_'); roleNavActions.Add(new RoleNavAction() { Action_Code = arr[1], CreateTime = DateTime.Now, Nav_Code = arr[0], Role = role }); } } } List <RoleArticleCategoryAction> roleArticleCategoryActions = new List <RoleArticleCategoryAction>(); if (!string.IsNullOrEmpty(input.Cate_SelActions)) { string[] CateSelActionArr = input.Cate_SelActions.Split(','); foreach (var cate in CateSelActionArr) { if (!string.IsNullOrWhiteSpace(cate)) { var arr = cate.Split('_'); roleArticleCategoryActions.Add(new RoleArticleCategoryAction() { ActionCode = arr[1], ArticleCategoryID = Convert.ToInt32(arr[0]), Role = role, CreateTime = DateTime.Now }); } } } db.RoleNavActions.AddRange(roleNavActions); db.RoleArticleCategoryActions.AddRange(roleArticleCategoryActions); return(db.SaveChanges() > 0 ? role : null); }
public async Task <string> Create(CreateRoleInput input) { input.CheckDataAnnotations().CheckValidResult(); var exsitRole = await _roleRepository.FirstOrDefaultAsync(p => p.Code == input.Code); if (exsitRole != null) { throw new UserFriendlyException($"已经存在{input.Code}的角色信息"); } await _roleRepository.InsertAsync(input.MapTo <Role>()); return("新增角色成功"); }
public async Task <IActionResult> CreateRoleAsync([FromBody] CreateRoleInput input) { var permissionIds = input.PermissionIds.Select(x => (GuidRequired)x); var request = new CreateRoleRequest { Name = input.Name, IsEnabled = input.IsEnabled, }; request.PermissionIds.AddRange(permissionIds); var response = (Guid)await _authorizationClient.CreateRoleAsync(request); return(CreatedAtAction(nameof(GetRoleAsync), new { Id = response }, default)); }
public async Task <ResponseBase <bool> > Create(CreateRoleInput input) { if ((await _roleManager.FindByNameAsync(input.Name)) != null) { return(new ResponseBase <bool>() { Result = false, Message = "Role Exsit" }); } var role = _mapper.Map <IdentityRole>(input); await _roleManager.CreateAsync(role); var claims = _mapper.Map <IList <IdentityRoleClaim <string> > >(input.RoleClaims).Select(a => { a.RoleId = role.Id; return(a); }).ToList(); await _roleRepository.AddClaims(claims); return(new ResponseBase <bool>() { Result = true }); }
public CreateRoleOutput CreateRole(CreateRoleInput input) { try { RestHTTP http = new RestHTTP(); RestRequest req = new RestRequest("api/roles/create", RestSharp.Method.POST); req.AddHeader("Content-Type", "application/json"); req.AddHeader("Authorization", "Bearer " + input.AccessToken); req.AddJsonBody(input); CreateRoleOutput response = http.HttpPost <CreateRoleOutput>(req); return(response); } catch (Exception ex) { WriteLogFile.Append("CreateRole : "); WriteLogFile.Append(ex.Message); WriteLogFile.Append(ex.StackTrace); } return(null); }
private async Task CreateAdminAndRole(long tenantId, CreateTenantInput input, DbConnection conn, DbTransaction trans) { var tenantConfig = _tenantConfigProvider.Get(); if (tenantConfig == null || tenantConfig.SuperUserPassword.IsNullOrWhiteSpace() || tenantConfig.SuperUserPassword.IsNullOrWhiteSpace()) { throw new BusinessException("获取租户默认管理员账号和密码失败"); } var permissions = await _permissionRepository.GetAllAsync(); var createRole = new CreateRoleInput() { Identification = input.Identification + "_admin", Name = "管理员", PermissionIds = permissions.Select(p => p.Id).ToArray(), DataPermissionType = DataPermissionType.AllOrg, IsAllOrg = true, Memo = "创建租户时,初始化的角色", }; var roleId = await _roleDomainService.Create(createRole, conn, trans, tenantId); var createUser = new CreateUserInput() { OrgId = null, UserName = tenantConfig.SuperUserAccount, Password = tenantConfig.SuperUserPassword, ChineseName = tenantConfig.ChineseName ?? "管理员", Memo = "创建租户时,初始化的用户", RoleIds = new[] { roleId }, Status = Common.Status.Valid }; await _userDomainService.Create(createUser, conn, trans, tenantId); }
public ResponseInfoModel AddInfo([FromBody] CreateRoleInput input) { ResponseInfoModel json = new ResponseInfoModel() { Success = 1, Result = new object() }; try { CheckModelState(); var role = _roleService.Addinfo(input); if (role == null) { json.Success = 0; json.Result = LocalizationConst.InsertFail; } else { _logService.Insert(new Log() { ActionContent = LocalizationConst.Insert, SourceType = _moduleName, SourceID = role.ID, LogTime = DateTime.Now, LogUserID = role.ID, LogIPAddress = IPHelper.GetIPAddress, }); } } catch (Exception e) { DisposeUserFriendlyException(e, ref json, "api/role/addInfo", LocalizationConst.InsertFail); } return(json); }
public async Task <long> Create(CreateRoleInput input, DbConnection conn, DbTransaction trans, long?tenantId = null) { using (var locker = await _lockerProvider.CreateLockAsync("CreateRole")) { return(await locker.Lock(async() => { var exsitRole = await _roleRepository.FirstOrDefaultAsync(p => p.Identification == input.Identification, false); if (exsitRole != null) { throw new BusinessException($"系统中已经存在{input.Identification}的角色"); } CheckUserDefinedDataPermission(input.DataPermissionType, input.DataPermissionOrgIds); var role = input.MapTo <Role>(); role.TenantId = _session.TenantId; if (tenantId.HasValue) { role.TenantId = tenantId.Value; } var roleId = await _roleRepository.InsertAndGetIdAsync(role, conn, trans); await _rolePermissionRepository.DeleteAsync(p => p.RoleId == role.Id, conn, trans); var insertSql = "INSERT INTO RolePermission(PermissionId,RoleId,CreateTime,CreateBy,TenantId) VALUES(@PermissionId,@RoleId,@CreationTime,@CreatorUserId,@TenantId)"; var rolePermissions = new List <RolePermission>(); foreach (var permissionId in input.PermissionIds) { rolePermissions.Add(new RolePermission { PermissionId = permissionId, RoleId = roleId, CreationTime = DateTime.Now, CreatorUserId = _session.UserId, TenantId = role.TenantId }); } await conn.ExecuteAsync(insertSql, rolePermissions, trans); if (!input.IsAllOrg) { foreach (var orgId in input.OrgIds) { var roleOrg = new RoleOrganization() { RoleId = roleId, OrgId = orgId, TenantId = role.TenantId }; await _roleOrganizationRepository.InsertAsync(roleOrg, conn, trans); } } if (input.DataPermissionType == DataPermissionType.UserDefined) { var insertDataPermissionOrgSql = "INSERT INTO RoleDataPermissionOrgRelation(RoleId,OrgId,CreateTime,CreateBy,TenantId) VALUES(@RoleId,@OrgId,@CreationTime,@CreatorUserId,@TenantId)"; var dataPermissionOrgDatas = new List <RoleDataPermissionOrgRelation>(); foreach (var orgId in input.DataPermissionOrgIds) { dataPermissionOrgDatas.Add(new RoleDataPermissionOrgRelation() { RoleId = roleId, OrgId = orgId, CreationTime = DateTime.Now, CreatorUserId = _session.UserId, TenantId = role.TenantId }); } await conn.ExecuteAsync(insertDataPermissionOrgSql, dataPermissionOrgDatas, trans); } return role.Id; })); } }
public CreateRoleOutput CreateRole(CreateRoleInput input) { _roleService.CreateRole(input.Role, input.GrantedPermissions); return(new CreateRoleOutput()); }
/// <summary> /// 用户列表 /// </summary> /// <returns></returns> //[AbpMvcAuthorize("Administration.Role")] public PartialViewResult Create() { var model = new CreateRoleInput(); return(PartialView(model)); }
public async Task <ResponseBase <bool> > Create(CreateRoleInput input) { return(await _roleSerivce.Create(input)); }
[AbpAuthorize("CanCreateRoles")] //An example of permission checking public async Task CreateRole(CreateRoleInput input) { await _RoleRepository.InsertAsync(new Role(input.Title, input.Text)); }
public async Task CreateRoleAsync(CreateRoleInput input) { var role = input.Role.MapTo <Role>(); await _roleManager.CreateAsync(role); }