0
I have an appointment with a group.
public List<TB_POSSIBILIDADE> ListarTodos(int id)
{
var strQuery = "";
strQuery += " select ";
strQuery += " a.IDPOSSIBILIDADE,";
strQuery += " a.IDTITULOPOSS,";
strQuery += " A.IDMODALIDADE,";
strQuery += " a.TITULO,";
strQuery += " a.DESCRICAO01,";
strQuery += " a.DESCRICAO02,";
strQuery += " a.DESCRICAO03,";
strQuery += " a.VALOR01,";
strQuery += " a.VALOR02,";
strQuery += " a.VALOR03,";
strQuery += " a.MARCA1,";
strQuery += " a.MARCA2,";
strQuery += " a.MARCA3,";
strQuery += " a.VALORAPOSTA1,";
strQuery += " a.VALORAPOSTA2,";
strQuery += " a.VALORAPOSTA3,";
strQuery += " a.VALORTOTAL1,";
strQuery += " a.VALORTOTALRETORNO";
strQuery += " from TB_POSSIBILIDADE a";
strQuery += " inner join TB_TITULO_POSSIBILIDADE b on a.IDTITULOPOSS = b.IDTITULOPOSS";
strQuery += string.Format(" where A.IDMODALIDADE = {0} ", id);
strQuery += " group by a.IDTITULOPOSS,a.IDPOSSIBILIDADE,";
strQuery += " b.DESCRICAO, a.TITULO,";
strQuery += " a.DESCRICAO01, a.DESCRICAO02,";
strQuery += " a.DESCRICAO03,a.VALOR01,";
strQuery += " a.VALOR02,a.VALOR03,";
strQuery += " a.MARCA1,a.MARCA2,";
strQuery += " a.MARCA3, a.VALORAPOSTA1,";
strQuery += " a.VALORAPOSTA2, a.VALORAPOSTA3,";
strQuery += " a.VALORTOTAL1,a.VALORTOTALRETORNO,A.IDMODALIDADE";
using (contexto = new Contexto())
{
var retornoDataReader = contexto.ExecutaComandoComRetorno(strQuery);
return TransformaReaderEmListaObjetos(retornoDataReader);
}
}
I have an accordion where in the body in a few moments I will have more than 1 option.
I have the first option with only one line: Initial A title : winner
I have the second option where I have 1 title and 4 more contents initial A title : mode 02
I want to repeat this content within the same accordion
I created a class:
namespace Generico.Dominio
{
public class TitulosNaLista
{
public string Titulo { get; set; }
}
}
In Controller I made:
//verifcar os titulos na lista
List<TitulosNaLista> ver = new List<TitulosNaLista>();
public bool VerificarTitulos(string Titulo)
{
return ver.Any(ls => ls.Titulo == Titulo);
}
in the view:
<div class="list-group">
<a href="#" class="list-group-item active">
Selecione uma opção:
</a>
@if (Model.Count() > 0)
{
foreach (var item in Model)
{
if(!VerificarTitulos(item.TITULO))
{
<!--inicio-->
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#@Html.DisplayFor(c => item.IDPOSSIBILIDADE)">
@Html.DisplayFor(c => item.TITULO)
</a>
</h4>
</div>
<!--inicio do corpo-->
<div id="@Html.DisplayFor(c => item.IDPOSSIBILIDADE)" class="panel-collapse collapse">
<div class="panel-body">
<div class="row">
<div class="col-md-3 form-group">
@Html.DisplayFor(c => item.DESCRICAO01) | R$ @Html.DisplayFor(c => item.VALOR01)
@Html.TextBoxFor(c => item.VALORAPOSTA1, new { placeholder = "valor ", @class = "form-control" })
</div>
<div class="col-md-3 form-group">
@Html.DisplayFor(c => item.DESCRICAO02) | R$ @Html.DisplayFor(c => item.VALOR02)
@Html.TextBoxFor(c => item.VALORAPOSTA2, new { placeholder = "valor ", @class = "form-control" })
</div>
<div class="col-md-3 form-group">
@Html.DisplayFor(c => item.DESCRICAO03) | R$ @Html.DisplayFor(c => item.VALOR03)
@Html.TextBoxFor(c => item.VALORAPOSTA3, new { placeholder = "valor ", @class = "form-control" })
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="submit" name="opcao" value="">Gravar</button>
</div>
</div>
</div>
<!--fim do corpo -->
</div>
}
</div>
<!--fim -->
}
}
}
</div>
Why not change the query by adding one
group by
?– Marllon Nasser
Friend, I suggest you change your question, your problem is in your query and not in foreach !
– Maurício Júnior
Expose the query that will be easier to help!
– Maurício Júnior
As I mentioned in my question, the data is in the same table, I don’t have two tables
– Harry
I’ll create another table for the title and post the question
– Harry
@Mauríciojúnior, I made the adjustment, you can give me a help! I appreciate
– Harry
@Marllonnasser, I made the adjustment, I could see now! I thank you
– Harry
The problem is in the query... you need all the information from select? Because apparently you don’t need... You can even solve in the view, but will be a gambiarra at the end.
– Marllon Nasser
@Marllonnasser, I changed my question, added the code that was suggested by Joy, note that I have a class Titulosnalista and in control I have a Verifititulos, I wanted to see what the best solution to solve this
– Harry
You bring the data by query...the data already come wrong, right? ... you have to handle in query, not in application.
– Marllon Nasser