| | |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.System; |
| | | using WIDESEA_SystemRepository; |
| | | using WIDESEA_Core.Helper; |
| | | |
| | | namespace WIDESEA_SystemService |
| | | { |
| | |
| | | _RoleAuthRepository = roleAuthRepository; |
| | | } |
| | | |
| | | public override WebResponseContent AddData(SaveModel saveModel) |
| | | { |
| | | string authorityScope = saveModel.MainData["authorityScope"].ToString(); |
| | | Sys_Role role = saveModel.MainData.DicToModel<Sys_Role>(); |
| | | if (BaseDal.QueryFirst(x => x.RoleName == role.RoleName) != null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"è§è²åéå¤"); |
| | | } |
| | | List<Dt_Warehouse> warehouses = BaseDal.Db.Queryable<Dt_Warehouse>().Where(x => true).ToList(); |
| | | List<Sys_RoleDataPermission> roleDataPermissions = new List<Sys_RoleDataPermission>(); |
| | | if (!string.IsNullOrEmpty(authorityScope)) |
| | | { |
| | | string[] scopes = authorityScope.Split(','); |
| | | foreach (string scope in scopes) |
| | | { |
| | | Dt_Warehouse? warehouse = warehouses.FirstOrDefault(x => x.WarehouseId == Convert.ToInt32(scope)); |
| | | if (warehouse != null) |
| | | { |
| | | roleDataPermissions.Add(new Sys_RoleDataPermission |
| | | { |
| | | WarehouseId = warehouse.WarehouseId, |
| | | WarehouseName = warehouse.WarehouseName, |
| | | RoleName = role.RoleName |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | int roleId = BaseDal.AddData(role); |
| | | if (roleDataPermissions.Count > 0) |
| | | { |
| | | roleDataPermissions.ForEach(x => { x.RoleId = roleId; }); |
| | | BaseDal.Db.Insertable(roleDataPermissions).ExecuteCommand(); |
| | | } |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | public override WebResponseContent UpdateData(SaveModel saveModel) |
| | | { |
| | | string authorityScope = saveModel.MainData["authorityScope"].ToString(); |
| | | Sys_Role role = saveModel.MainData.DicToModel<Sys_Role>(); |
| | | if (BaseDal.QueryFirst(x => x.RoleId == role.RoleId) == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥æ°æ®"); |
| | | } |
| | | List<Dt_Warehouse> warehouses = BaseDal.Db.Queryable<Dt_Warehouse>().Where(x => true).ToList(); |
| | | |
| | | List<Sys_RoleDataPermission> oldDatas = BaseDal.Db.Queryable<Sys_RoleDataPermission>().Where(x => x.RoleId == role.RoleId).ToList(); |
| | | List<Sys_RoleDataPermission> roleDataPermissions = new List<Sys_RoleDataPermission>(); |
| | | if (!string.IsNullOrEmpty(authorityScope)) |
| | | { |
| | | string[] scopes = authorityScope.Split(','); |
| | | foreach (string scope in scopes) |
| | | { |
| | | Sys_RoleDataPermission? oldData = oldDatas.FirstOrDefault(x => x.WarehouseId == Convert.ToInt32(scope)); |
| | | if (oldData == null) |
| | | { |
| | | Dt_Warehouse? warehouse = warehouses.FirstOrDefault(x => x.WarehouseId == Convert.ToInt32(scope)); |
| | | if (warehouse != null) |
| | | { |
| | | roleDataPermissions.Add(new Sys_RoleDataPermission |
| | | { |
| | | WarehouseId = warehouse.WarehouseId, |
| | | WarehouseName = warehouse.WarehouseName, |
| | | RoleName = role.RoleName |
| | | }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | oldDatas.Remove(oldData); |
| | | } |
| | | } |
| | | } |
| | | |
| | | roleDataPermissions.ForEach(x => { x.RoleId = role.RoleId; }); |
| | | BaseDal.Db.Insertable(roleDataPermissions).ExecuteCommand(); |
| | | BaseDal.Db.Deleteable(oldDatas).ExecuteCommand(); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | public List<RoleNodes> GetAllChildren(int roleId) |
| | | { |
| | | if (roleId <= 0) return new List<RoleNodes>() { }; |