public ActionResult <InfotecTalk> Post(InfotecTalk infotecTalk) { try { var contador = 0; using (var context = new InfotecContext(_configuration)) { if (AddClientesOmni(context, infotecTalk)) { contador++; } infotecTalk.talk_histories .ForEach(h => { if (AddClientesOmniMsg(context, infotecTalk.id, h)) { contador++; } }); context.SaveChanges(); } _logger.LogInformation($"Foram incluidas {contador} mensagens."); return(Ok(infotecTalk)); } catch (Exception error) { _logger.LogError(error.InnerException != null ? error.InnerException.Message : error.Message); return(StatusCode(500)); } }
private bool AddClientesOmni(InfotecContext context, InfotecTalk infotecTalk) { if (context.ClientesOmni.AsNoTracking().Any(c => Equals(c.talk_id, infotecTalk.id))) { return(false); } context.ClientesOmni.Add( new ClientesOmni { talk_id = infotecTalk.id, customer_id = infotecTalk.customer_id, channel_id = infotecTalk.channel_id, finished_at = Convert.ToDateTime(infotecTalk.finished_at), created_at = Convert.ToDateTime(infotecTalk.created_at), json = JsonSerializer.Serialize(infotecTalk) } ); return(true); }