Ejemplo n.º 1
0
        public async Task ExchangeWebMenuAuthorityParentIDAsync(Guid id, Guid?parentID, Guid?targetID, bool forUnder = true)
        {
            if (parentID.HasValue && !await _webMenuAuthorityRepository.ExistedAsync(parentID.Value))
            {
                throw new InvalidOperationException("父级唯一标识不存在");
            }
            WebMenuAuthority webMenuAuthorityFromDB = await _webMenuAuthorityRepository.FirstOrDefaultAsync(id);

            if (webMenuAuthorityFromDB == null)
            {
                throw new InvalidOperationException("该网页菜单权限不存在");
            }
            webMenuAuthorityFromDB.ParentID = parentID;
            if (targetID.HasValue)
            {
                WebMenuAuthority indexWebMenuAuthority = await _webMenuAuthorityRepository.FirstOrDefaultAsync(targetID.Value);

                List <WebMenuAuthority> webMenuAuthorities = await GetWebMenuAuthoritiesByIndex(webMenuAuthorityFromDB, indexWebMenuAuthority);

                ExchangeIndex(id, forUnder, webMenuAuthorities);
            }
            _authorityUnitOfWork.RegisterEdit(webMenuAuthorityFromDB);
            await _authorityUnitOfWork.CommitAsync();

            _webMenuAuthorityRepository.ClearCache();
        }
Ejemplo n.º 2
0
        public async Task ExchangeWebMenuAuthorityParentIDAsync(Guid id, Guid?parentID, Guid?indexID, bool forUnder = true)
        {
            if (parentID.HasValue && !await _webMenuAuthorityRepository.ExistedAsync(parentID.Value))
            {
                throw new InvalidOperationException("父级唯一标识不存在");
            }
            WebMenuAuthority webMenuAuthorityFromDB = await _webMenuAuthorityRepository.FirstOrDefaultAsync(id);

            if (webMenuAuthorityFromDB == null)
            {
                throw new InvalidOperationException("该网页菜单权限不存在");
            }
            webMenuAuthorityFromDB.ParentID = parentID;
            if (indexID.HasValue)
            {
                WebMenuAuthority indexWebMenuAuthority = await _webMenuAuthorityRepository.FirstOrDefaultAsync(indexID.Value);

                if (indexWebMenuAuthority == null)
                {
                    throw new InvalidOperationException("位序唯一标项不存在");
                }
                if (forUnder && webMenuAuthorityFromDB.Index < indexWebMenuAuthority.Index ||
                    !forUnder && webMenuAuthorityFromDB.Index > indexWebMenuAuthority.Index)
                {
                    ExchangeIndex(webMenuAuthorityFromDB, indexWebMenuAuthority);
                    _authorityUnitOfWork.RegisterEdit(indexWebMenuAuthority);
                }
            }
            _authorityUnitOfWork.RegisterEdit(webMenuAuthorityFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }