0

Hopefully this is a easy question, i tried to do what i cound do on my own. But i can't solve the rest part.

Out for every row, i want to check if the date is heigher or lower equels to the last. But how?

As you can see yon on the image and the sample code.

Click and see the image exsample

And the following code:

@using Scoutpocket.Models.Database;
@model Tuple<List<Properties>, List<SubProperties>, List<Rating>>

<div class="container">

    @foreach (var item in Model.Item1)
    {
        <br />
        <br />
        <b>
            @item.PropertiesName
        </b>

        <br />




        foreach (var item2 in item.SubProperties)
        {
            @item2.SubPropertiesName<br />

            int count = 2;
            int getLast = 1;


            foreach (var item3 in item2.rating.Where(x => x.PlayerID == 1).Take(count).OrderByDescending(x => x.Date))
            {

                for (int i = 0; i < getLast; i++)
                {
                    // Check the index of the last row, and check if the current date is lower or heighter.


                    <b>Compare date on last and newst</b>
                }

                <span>Rating ID: @item3.RatingID</span>
                <span> | </span>
                <span>Value: @item3.Value</span>
                <span> | </span>
                <span>ScoutID: @item3.ScoutID</span>

                <span> | </span>
                <span>PlayerID: @item3.PlayerID</span>

                <span> | </span>
                <span>Date: @item3.Date</span>
                <br/>
            }

        }
    }

</div>

1 Answers1

0

If you're using List types, you can easily use Count to get the size and do list.Count - 1 to get last index. That will return the last element; make sure to validate the count, other wise index out of bounds might be raised. For instance,

var _dateHigh = Model.Item1.Last(); // extension methods
// same for dateLow
@foreach (var item in Model.Item1) {
    // run the code here.
}

If the last element changes with each iteration, then I recommend using a nested variable in the loop. We cannot help much, as you did not share the model structures, so there is very much less that we can help with.

How can I find the last element in a List<> ?

Community
  • 1
  • 1
Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103