/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task Consume(ConsumeContext <IDeleteTeam> context) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Console(theme: ConsoleTheme.None) .CreateLogger(); var start = Stopwatch.GetTimestamp(); Log.Information("Received command {CommandName}-{MessageId}: {@Messages}", GetType().Name, context.MessageId, context.Message); var teams = await _teamRepository.Delete(context.Message); var ids = teams.Select(s => s.Id).ToList(); await context.RespondAsync <ITeamDeleted>(new { Ids = ids }); //index to es if (teams.Count > 0) { await _esClient.IndexManyAsync(teams, "teams"); } var teamUsers = await _teamUserRepository.Delete(ids, context.Message.CompanyId, context.Message.UpdatedBy); if (teamUsers.Count > 0) { await _esClient.IndexManyAsync(teamUsers, "team_users"); } Log.Information("Completed command {CommandName}-{MessageId} {ExecuteTime}ms", GetType().Name, context.MessageId, (Stopwatch.GetTimestamp() - start) * 1000 / (double)Stopwatch.Frequency); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task Consume(ConsumeContext <IDeleteTeamUsers> context) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Console(theme: ConsoleTheme.None) .CreateLogger(); var start = Stopwatch.GetTimestamp(); Log.Information("Received command {CommandName}-{MessageId}: {@Messages}", GetType().Name, context.MessageId, context.Message); var teamUsers = await _teamUsersRepository.Delete(context.Message); await context.RespondAsync <ITeamUsersDeleted>(new { TeamUsers = teamUsers }); if (teamUsers.Count > 0) { await _esClient.IndexManyAsync(teamUsers, "team_users"); } foreach (var teamUser in teamUsers) { await _distributedCache.RemoveAsync($"access-right-{teamUser.CompanyId}-{teamUser.UserId}"); } Log.Information("Completed command {CommandName}-{MessageId} {ExecuteTime}ms", GetType().Name, context.MessageId, (Stopwatch.GetTimestamp() - start) * 1000 / (double)Stopwatch.Frequency); }