public async Task HandleEventAsync(EntityDeletedEto <TenantEto> eventData)
        {
            using var unitOfWork = UnitOfWorkManager.Begin();
            // 订阅租户删除事件,删除管理员角色所有权限
            // TODO: 租户貌似不存在了,删除应该会失败
            // 有缓存存在的话,可以获取到租户连接字符串
            using (CurrentTenant.Change(eventData.Entity.Id))
            {
                // var grantPermissions = await PermissionGrantRepository.GetListAsync("R", "admin");

                // EfCore MySql 批量删除还是一条一条的语句?
                // PermissionGrantRepository.GetDbSet().RemoveRange(grantPermissions);
                var dbContext = await PermissionGrantRepository.GetDbContextAsync();

                var permissionEntityType    = dbContext.Model.FindEntityType(typeof(PermissionGrant));
                var permissionTableName     = permissionEntityType.GetTableName();
                var batchRmovePermissionSql = string.Empty;
                if (dbContext.Database.IsMySql())
                {
                    batchRmovePermissionSql = BuildMySqlBatchDeleteScript(permissionTableName, eventData.Entity.Id);
                }
                else
                {
                    batchRmovePermissionSql = BuildSqlServerBatchDeleteScript(permissionTableName, eventData.Entity.Id);
                }

                await dbContext.Database.ExecuteSqlRawAsync(batchRmovePermissionSql);

                await unitOfWork.SaveChangesAsync();
            }
        }
Exemplo n.º 2
0
        public virtual async Task HandleEventAsync(EntityDeletedEto <PaymentEto> eventData)
        {
            var payment = await _paymentRepository.FindAsync(eventData.Entity.Id);

            if (payment == null)
            {
                return;
            }

            await _paymentRepository.DeleteAsync(payment, true);
        }
Exemplo n.º 3
0
        public virtual async Task HandleEventAsync(EntityDeletedEto <PaymentEto> eventData)
        {
            using var changeTenant = _currentTenant.Change(eventData.Entity.TenantId);

            var payment = await _paymentRepository.FindAsync(eventData.Entity.Id);

            if (payment == null)
            {
                return;
            }

            await _paymentRepository.DeleteAsync(payment, true);
        }
Exemplo n.º 4
0
        public virtual async Task HandleEventAsync(EntityDeletedEto <RefundEto> eventData)
        {
            using var changeTenant = _currentTenant.Change(eventData.Entity.TenantId);

            var refund = await _refundRepository.FindAsync(eventData.Entity.Id);

            if (refund == null)
            {
                return;
            }

            await _refundRepository.DeleteAsync(refund, true);
        }
Exemplo n.º 5
0
        public virtual async Task HandleEventAsync(EntityDeletedEto <PaymentEto> eventData)
        {
            using var uow = _unitOfWorkManager.Begin(isTransactional: true);

            using var changeTenant = _currentTenant.Change(eventData.Entity.TenantId);

            var payment = await _paymentRepository.FindAsync(eventData.Entity.Id);

            if (payment == null)
            {
                return;
            }

            await _paymentRepository.DeleteAsync(payment, true);

            await uow.CompleteAsync();
        }
Exemplo n.º 6
0
        public async Task HandleEventAsync(EntityDeletedEto <TodoItemEto> eventData)
        {
            var dateTime    = eventData.Entity.CreationTime;
            var todoSummary = await _todoSummaryRepository.FirstOrDefaultAsync(
                x => x.Year == dateTime.Year &&
                x.Month == dateTime.Month &&
                x.Day == dateTime.Day
                );

            if (todoSummary != null)
            {
                todoSummary.Decrease();
                await _todoSummaryRepository.UpdateAsync(todoSummary);

                Console.WriteLine("Decreased total count: " + todoSummary);
            }
        }
Exemplo n.º 7
0
 public async Task HandleEventAsync(EntityDeletedEto <IdentityRoleEto> eventData)
 {
     await PermissionManager.DeleteAsync(RolePermissionValueProvider.ProviderName, eventData.Entity.Name);
 }
 public virtual async Task HandleEventAsync(EntityDeletedEto <TenantEto> eventData)
 {
     var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(eventData.Entity.Id.ToString());
     await _cache.RemoveAsync(cacheKey);
 }