public SaveResponse Update(IUnitOfWork uow, RolePermissionUpdateRequest request) { Check.NotNull(request, "request"); Check.NotNull(request.RoleID, "roleID"); Check.NotNull(request.Permissions, "permissions"); var roleID = request.RoleID.Value; var oldList = new HashSet<string>( GetExisting(uow.Connection, roleID, request.Module, request.Submodule) .Select(x => x.PermissionKey), StringComparer.OrdinalIgnoreCase); var newList = new HashSet<string>(request.Permissions.ToList(), StringComparer.OrdinalIgnoreCase); var allowedKeys = new UserPermissionRepository().ListPermissionKeys() .Entities.ToDictionary(x => x); if (newList.Any(x => !allowedKeys.ContainsKey(x))) throw new AccessViolationException(); if (oldList.SetEquals(newList)) return new SaveResponse(); foreach (var k in oldList) { if (newList.Contains(k)) continue; new SqlDelete(fld.TableName) .Where( new Criteria(fld.RoleId) == roleID & new Criteria(fld.PermissionKey) == k) .Execute(uow.Connection); } foreach (var k in newList) { if (oldList.Contains(k)) continue; uow.Connection.Insert(new MyRow { RoleId = roleID, PermissionKey = k }); } BatchGenerationUpdater.OnCommit(uow, fld.GenerationKey); BatchGenerationUpdater.OnCommit(uow, Entities.UserPermissionRow.Fields.GenerationKey); return new SaveResponse(); }
public SaveResponse Update(IUnitOfWork uow, RolePermissionUpdateRequest request) { return new MyRepository().Update(uow, request); }
public SaveResponse Update(IUnitOfWork uow, RolePermissionUpdateRequest request) { Check.NotNull(request, "request"); Check.NotNull(request.RoleID, "roleID"); Check.NotNull(request.Permissions, "permissions"); var roleID = request.RoleID.Value; var oldList = new HashSet <string>( GetExisting(uow.Connection, roleID, request.Module, request.Submodule) .Select(x => x.PermissionKey), StringComparer.OrdinalIgnoreCase); var newList = new HashSet <string>(request.Permissions.ToList(), StringComparer.OrdinalIgnoreCase); var allowedKeys = new UserPermissionRepository() .ListPermissionKeys() .Entities.ToDictionary(x => x); if (newList.Any(x => !allowedKeys.ContainsKey(x))) { throw new AccessViolationException(); } if (oldList.SetEquals(newList)) { return(new SaveResponse()); } foreach (var k in oldList) { if (newList.Contains(k)) { continue; } new SqlDelete(fld.TableName) .Where( new Criteria(fld.RoleId) == roleID & new Criteria(fld.PermissionKey) == k) .Execute(uow.Connection); } foreach (var k in newList) { if (oldList.Contains(k)) { continue; } uow.Connection.Insert(new MyRow { RoleId = roleID, PermissionKey = k }); } BatchGenerationUpdater.OnCommit(uow, fld.GenerationKey); BatchGenerationUpdater.OnCommit(uow, Entities.UserPermissionRow.Fields.GenerationKey); return(new SaveResponse()); }
public SaveResponse Update(IUnitOfWork uow, RolePermissionUpdateRequest request) { return(new MyRepository().Update(uow, request)); }
public SaveResponse Update(IUnitOfWork uow, RolePermissionUpdateRequest request) { if (request is null) { throw new ArgumentNullException("request"); } if (request.RoleID is null) { throw new ArgumentNullException("roleID"); } if (request.Permissions is null) { throw new ArgumentNullException("permissions"); } var roleID = request.RoleID.Value; var oldList = new HashSet <string>( GetExisting(uow.Connection, roleID, request.Module, request.Submodule) .Select(x => x.PermissionKey), StringComparer.OrdinalIgnoreCase); var newList = new HashSet <string>(request.Permissions.ToList(), StringComparer.OrdinalIgnoreCase); if (oldList.SetEquals(newList)) { return(new SaveResponse()); } foreach (var k in oldList) { if (newList.Contains(k)) { continue; } new SqlDelete(fld.TableName) .Where( new Criteria(fld.RoleId) == roleID & new Criteria(fld.PermissionKey) == k) .Execute(uow.Connection); } foreach (var k in newList) { if (oldList.Contains(k)) { continue; } uow.Connection.Insert(new MyRow { RoleId = roleID, PermissionKey = k }); } Cache.InvalidateOnCommit(uow, fld); Cache.InvalidateOnCommit(uow, Entities.UserPermissionRow.Fields); return(new SaveResponse()); }