How to replace with null or blank values

Asked

Viewed 43 times

0

Problem: When the customer clicks to send the request the system takes the product selected and the dimensions of that product. Only not all products have box or is any other feature of the same.

Process: When the customer clicks to send a quote an email is fired to the store with the product + dimensions (Size, Box, Color...) Through the back-end I give a replace in my Html for example:

Clase Enviar e-mail:

 private string CorpoEmailOrcamento(string lead, string telefone, string email, string produto, string caixa, string essencia, string tamanho, string tipo, string utilizacao, string mensagem, string callback, string webRootPath)
    {

        string body = string.Empty;

        //using streamreader for reading my htmltemplate   

        using (StreamReader reader = new StreamReader(Path.Combine(webRootPath, "emailmodel/orcamento.html")))
        {

            body = reader.ReadToEnd();

        }

        body = body.Replace("{lead}", lead);
        body = body.Replace("{telefone}", telefone);
        body = body.Replace("{email}", email);
        body = body.Replace("{produto}", produto);
        body = body.Replace("{<li><strong>Caixa:</strong> {caixa}</li>}", caixa);
        body = body.Replace("{essencia}", essencia);
        body = body.Replace("{tamanho}", tamanho);
        body = body.Replace("{tipo}", tipo);
        body = body.Replace("{utilizacao}", utilizacao);
        body = body.Replace("{mensagem}", mensagem);
        body = body.Replace("{callback}", callback);


        return body;

    }

Then he replaces this piece of code.

<ul>                                                                                                   
<li><strong>Nome:</strong> {lead}</li>                                                                                  <li><strong>Telefone:</strong> {telefone}</li>                                                                                                       <li><strong>Produto:</strong> {produto}</li>
<li><strong>Caixa:</strong> {caixa}</li>
<li><strong>Essência:</strong> {essencia}</li>
<li><strong>Tamanho:</strong> {tamanho}</li>
<li><strong>Tipo:</strong> {tipo}</li>
<li><strong>Utilização:</strong> {utilizacao}</li>
<li><strong>Mensagem:</strong> {mensagem}</li>
</ul>

If the product has any beauty feature it sends the problem right this being if the product has no feature there is a strange result in e-mial as for example:

inserir a descrição da imagem aqui

Solution: I would like when the email is sent if the product selected has no feature so it does not display that setting.

Example if Product A has no box it does not need to go in Email Box: {box}

1 answer

1


You can do the validation directly on C#, but in this case, the HTML control would be on the server.

Example On the server, would be the validation part and makes the insertion of content HTML or a emptiness, if the variable has no value.

body = !string.IsNullOrEmpty(lead) ? body.Replace("{lead}", string.Format("<li><strong>Nome: </strong>{0}</li>", lead)) : body.Replace("{lead}", "");

In the view, it would be just the tag {lead}, location where HTML will be replaced by content generated on the server.

Browser other questions tagged

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