예제 #1
0
        public async Task <int> CreatePermissionGroup(PermissionGroupDetailRq permissionGroupDetailRq)
        {
            int createdPermissionGroupId = await CreatePermissionGroupDetailAsync(new PermissionGroup(permissionGroupDetailRq.Name, permissionGroupDetailRq.Description));

            await AddMemberToPermissionGroupAsync(createdPermissionGroupId, permissionGroupDetailRq.Users);

            GrantMenuPermissionToGroup(createdPermissionGroupId, permissionGroupDetailRq.MenuPms);

            await _uow.SaveChangesAsync();

            return(createdPermissionGroupId);
        }
예제 #2
0
        public async Task <bool> UpdatePermissionGroup(int id, PermissionGroupDetailRq permissionGroupDetailRq)
        {
            try
            {
                var permissionGroup = await _permissionGroupRepository.GetEntityByIdAsync(id);

                var permissionMembership = await _permissionMembershipRepository.GetAllMemberByPermissionGroupId(permissionGroup.Id).Cast <PermissionMembership>().ToListAsync();

                var menuPms = _menuPermissionRepository.GetMenuPermissionByPermissionGroupId(permissionGroup.Id).Cast <MenuPermission>().FirstOrDefault();

                _mapper.Map(permissionGroupDetailRq.MenuPms, menuPms);
                _menuPermissionRepository.Update(menuPms);

                permissionMembership.ForEach(pm =>
                {
                    if (!permissionGroupDetailRq.Users.Contains(pm.UserId))
                    {
                        _permissionMembershipRepository.Delete(pm);
                    }
                });

                permissionGroupDetailRq.Users.ForEach(u =>
                {
                    if (!permissionMembership.Select(p => p.UserId).Contains(u))
                    {
                        _permissionMembershipRepository.Create(new PermissionMembership(permissionGroup.Id, u));
                    }
                });

                if (_uow.SaveChangesAsync().Result > 0)
                {
                    permissionGroup.Name        = permissionGroupDetailRq.Name;
                    permissionGroup.Description = permissionGroupDetailRq.Description;
                    _permissionGroupRepository.Update(permissionGroup);
                    return(await _uow.SaveChangesAsync() > 0);
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }