1
My question is this:.
I need to display 2 status on a page that would be Primeiro
and Alterado
, where the first sql line with the date of 2018-03-05 10:24:55.787
get the status Primeiro
and the second sql line with the date 2018-03-05 10:30:09.727
get the status Alterado
and the third line gets the status Ativo
but it is already working as you can see in the code below.
<td class="text-center">
@if (item.StatPree == 1)
{
<a class="ui teal label">Ativo</a>
}
else {
if (...)
{
<a class="ui yellow label">Primeiro</a>
}
else
{
<a class="ui orange label">Alterado</a>
}
}
</td>
The variable is like public DateTime? DataEdicao { get; set; }
q bank you use ?
– Rovann Linhalis
also show where your item comes from, probably a list of items
– Rovann Linhalis
I use the Sqlserver
– Leonardo Macedo
Have you thought about using another code that differentiates the "First", as -1?
– e.leal.br
need to give more details of the data, as they come... at first, thinking it will return the data as they are in the database, just sort, take the first item as "First" and the last as "Changed"
– Ricardo Pontual
What do you mean? You can give me an example?
– Leonardo Macedo
If your data is in a
List
by namedados
, could do so:var primeiro=dados.Where(a => a.StatPree == 0).OrderBy(a => a.DataEdicao).FirstOrDefault(); var alterado = dados.Where(a => a.StatPree == 0).OrderBy(a => a.DataAlteracao).LastOrDefault();
– Ricardo Pontual
@Leonardomacedo maybe in the same place where you make the differentiation from 0 to 1 (an update method, for example), you use another code for when to display the value "First".
– e.leal.br
So in statpree I can’t touch it because it’s a system audit page
– Leonardo Macedo
@Ricardopunctual I’m testing your function you sent me
– Leonardo Macedo
@Ricardopunctual My data is inside a foreach (var item in Model) in this case would be correct Model.Orderby?
– Leonardo Macedo
@Rovannlinhalis published the answer with the same solution I talked about, just a little different already making the comparison. good luck
– Ricardo Pontual
@Ricardopunctual, you gave an example by selecting a record within the list, in the first, ok, but in the changed, it can have X changes, it would not work the way you said. It would have to be at least a Tolist() at the end. Besides, it would have to change the logic of the loop, to display the data from two different sources.
– Rovann Linhalis
@Rovannlinhalis I’m not criticizing your answer, I just answered Leonardo’s comment about him using the foreach, then I saw that you had answered and commented pq no longer need to give examples because your answer already answered his question :)
– Ricardo Pontual