Error Request Mail

Asked

Viewed 34 times

0

Could someone give me a hand here? I’m doing an environment check to send a certain email, only the following error is occurring.

inserir a descrição da imagem aqui

Could you tell me how to fix this? My code is below

public void NovoEventoAdverso(int patientId, int hospitalId, int usuarioId)
{
    var cadastroRepository = new CadastroRepository();
    var investigadorRepository = new UsuarioRepository();
    var randomizacaoRepository = new RandomizacaoRepository();

    var paciente = cadastroRepository.GetByPatientId(patientId, hospitalId);
    var investigador = investigadorRepository.GetbyId(usuarioId);
    var randomizacao = randomizacaoRepository.GetByPatientId(patientId, hospitalId);

    var isHomolog = Request.Url.AbsoluteUri.Contains("homolog") || Request.Url.AbsoluteUri.Contains("localhost") ? true : false;


    MailMessage objEmail = FactoryMailMessage();

    objEmail.To.Add("AAAA BBBB <[email protected]>");

    objEmail.Subject = $"Novo Evento Adverso - {paciente.inpac}";

    var conteudo = "Novo Evento Adverso cadastrado:<br />";
    conteudo += $"Iniciais do Paciente: {paciente.inpac}<br />";
    conteudo += $"Nome do Investigador: {investigador.Nome}<br />";
    conteudo += $"Data da Randomização: {randomizacao.RandomizacaoData.Value.ToString("dd/MM/yyyy")}<br />";
    conteudo += $"Data do Preenchimento: {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}";

    objEmail.Body = conteudo;

    EnviarEmail(objEmail);
}
  • Try it => Httpcontext.Request

  • It didn’t work This part of Request.Url .... I took it from my index because I used it to validate my environment view. And I’m trying to implement in my Email.Cs to send a certain email depenendo the environment

  • If the emails are different, you cannot do 1 method for each email?

  • The emails are not different, but in my case I need to do a check to see which environment a form was registered. Because it is the following if a form is registered I receive an email warning, only I need to identify where this form was registered, if it was approval or if it was production I could understand?

  • No, but you can pass this check as a BOOLEAN per parameter to the method, you cannot?

  • The error already says, Request does not exist in your context. You referenced (using ...) the correct Assembly?

  • @Gabrielcoletta I can’t import any using Cs for this Request

  • I mean you reference this assembly in the class where your method NovoEventoAdverso this. Httpcontext needs the system.web that is found in Asp.net packages. If you are in a layer without this dll it won’t even work.

  • you are working with Asp.net core?

  • @Leandroangelo Yes I am

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.