Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task Consume(ConsumeContext <IDeleteLead> 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 leads = await _leadRepository.Delete(context.Message);

            //index to es
            var response = await _esClient.IndexManyAsync(leads, "leads");

            foreach (var lead in leads)
            {
                await context.Publish <ICreateActivityHistoryLead>(
                    new
                {
                    lead.CompanyId,
                    LeadId    = lead.Id,
                    Type      = "edit",
                    Activity  = "deleteLead",
                    CreatedBy = lead.UpdatedBy,
                    CreatedAt = lead.UpdatedAt
                }
                    );
            }
            await context.RespondAsync <ILeadDeleted>(new { Ids = leads.Select(s => s.Id) });

            Log.Information("Completed command {CommandName}-{MessageId} {ExecuteTime}ms", GetType().Name, context.MessageId, (Stopwatch.GetTimestamp() - start) * 1000 / (double)Stopwatch.Frequency);
        }
Beispiel #2
0
        public async ValueTask <ActionResult> DeleteLeadById(long leadId)
        {
            DataWrapper <LeadDto> dataWrapper = await _repo.GetById(leadId);

            if (dataWrapper.Data == null)
            {
                return(BadRequest("Lead was not found"));
            }
            await _repo.Delete(leadId);

            _logger.Info($"Delete lead with Id: {dataWrapper.Data.Id}");
            return(Ok("Successfully deleted"));
        }