Ver código fonte

分配权限

Dun.Jason 2 anos atrás
pai
commit
a543e8c49e
1 arquivos alterados com 7 adições e 2 exclusões
  1. 7 2
      src/Hotline.Api/Controllers/RoleController.cs

+ 7 - 2
src/Hotline.Api/Controllers/RoleController.cs

@@ -100,8 +100,13 @@ public class RoleController : BaseController
     [HttpPost("allocationauthority")]
     public async Task AllocationAuthority(RoleAuthorityDto dto)
     {
-        var list = _mapper.Map<SystemAuthority>(dto);
-        await _systemAuthorityRepository.AddAsync(list);
+        //判断是否存在,如果存在就做更新
+        var ishas =await _systemAuthorityRepository.AnyAsync(x => x.RoleId == dto.RoleId);
+        var model = _mapper.Map<SystemAuthority>(dto);
+        if (!ishas)
+            await _systemAuthorityRepository.AddAsync(model);
+        else
+            await _systemAuthorityRepository.UpdateAsync(model);
     }
 
     /// <summary>