Skip to content

Commit

Permalink
优化角色新建或修改时,禁止相同的角色名
Browse files Browse the repository at this point in the history
  • Loading branch information
jxx committed Dec 8, 2019
1 parent e436ae3 commit f43b392
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Vue.Net/VOL.System/Services/System/Partial/Sys_RoleService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using VOL.Core.Extensions;
using VOL.Core.ManageUser;
Expand Down Expand Up @@ -249,15 +250,34 @@ public async Task<WebResponseContent> SavePermission(List<UserPermissions> userP

public override WebResponseContent Add(SaveModel saveDataModel)
{
AddOnExecuting = (Sys_Role role, object obj) =>
{
return ValidateRoleName(role, x => x.RoleName == role.RoleName);
};
return RemoveCache(base.Add(saveDataModel));
}

public override WebResponseContent Del(object[] keys, bool delList = true)
{
return RemoveCache(base.Del(keys, delList));
}

private WebResponseContent ValidateRoleName(Sys_Role role, Expression<Func<Sys_Role, bool>> predicate)
{
WebResponseContent responseContent = new WebResponseContent(true);
if (repository.Exists(predicate))
{
return responseContent.Error($"角色名【{role.RoleName}】已存在,请设置其他角色名");
}
return responseContent;
}

public override WebResponseContent Update(SaveModel saveModel)
{
UpdateOnExecuting = (Sys_Role role, object obj1, object obj2, List<object> obj3) =>
{
return ValidateRoleName(role, x => x.RoleName == role.RoleName && x.Role_Id != role.Role_Id);
};
return RemoveCache(base.Update(saveModel));
}
private WebResponseContent RemoveCache(WebResponseContent webResponse)
Expand Down

0 comments on commit f43b392

Please sign in to comment.