public async Task InsertAsync(ModifyRoleDto role) { bool isRepeatName = await _roleRepo.Select.AnyAsync(r => r.Name == role.Name); if (isRepeatName)//角色名重复 { throw new KnownException("角色名称重复,请重新输入", ServiceResultCode.RepeatField); } var permissions = await _permissionRepo.Select.Where(p => p.IsDeleted == false).ToListAsync(); foreach (var permissionId in role.PermissionIds) { if (!permissions.Any(p => p.Id == permissionId)) { throw new KnownException($"Id:{permissionId} 权限不存在!", ServiceResultCode.NotFound); } } var input = Mapper.Map <RoleEntity>(role); var entity = await _roleRepo.InsertAsync(input); await _rolePermissionRepo.InsertAsync(role.PermissionIds.Select(p => new RolePermissionEntity { RoleId = entity.Id, PermissionId = p })); }
public async Task <IActionResult> Put([FromBody] ModifyRoleDto command) { await this.SendCommandAsync <ModifyRoleCommand>(new ModifyRoleCommand(command.Id, command.Name, command.Code, command.PermissionIds, command.Version)); return(Ok()); }
public async Task <JsonResult> Update(ModifyRoleDto model) { var result = await _roleAppService.Update(model); OutputModel outputModel = new OutputModel(); outputModel.Data = result; return(new JsonResult(outputModel)); }
public Task UpdateAsync(ModifyRoleDto role) { throw new System.NotImplementedException(); }
public async Task <ServiceResult> UpdateAsync([FromBody] ModifyRoleDto dto) { await _roleService.UpdateAsync(dto); return(ServiceResult.Successed("角色更新成功!")); }
public async Task <ServiceResult> CreateAsync([FromBody] ModifyRoleDto dto) { await _roleService.InsertAsync(dto); return(ServiceResult.Successed("角色创建成功")); }
public async Task <Result> Update(ModifyRoleDto dto) { return(await _roleService.Update(_mapper.Map <Rolepermission>(dto))); }