'How to get the rank list of multiple number in a sublist and populate it?
I have a TeamSquad made of players and each have tests store in a table. Test results are stored in fields (int) such as RF1 and LF1. (right foot and Left Foot). The data for the RF1 and LF1 has been populated on a prior date. For each player. But I may not have a result in RF1 or LF1 for a player yet.
List< TeamSquadViewModel > teamsquad = new List< TeamSquadViewModel >();
foreach (var item in teamsquadlist)
{
TeamSquadViewModel data = new TeamSquadViewModel();
data.Player = item;
data.IsSelected = false;
data.UserId = item.UserId;
if (_testRepository.GetAllTestsForAPlayer(userlogged.User_Club_id, item.UserId).Any())
{
data.StatExists = true;
data.LastTests = _testRepository.GetAllTestsForAPlayer(userlogged.User_Club_id, item.UserId).OrderByDescending(e => e.Test_Date_Record).FirstOrDefault();
}
teamsquad.Add(data);
}
public class TeamSquadViewModel {
public Player Player { get; set; }
public bool IsSelected { get; set; }
public string UserId { get; set; }
public bool StatExists { get; set; }
//STATS AREA
public Test LastTests { get; internal set; }
}
public class Test : BaseModel
{
[Required]
public int Test_RF1
{
get
{
return GetValue<int>();
}
set
{
SetValue(value);
}
}
[Required]
public int Test_LF1
{
get
{
return GetValue<int>();
}
set
{
SetValue(value);
}
}
}
For each player, I have a
TeamSquadViewModel data = new TeamSquadViewModel();
Test_RF1 and TestRF1 and results of a test at a certain date. So I want to have a ranking on the last tests results for each player.
So how do I get the ranking of Test_RF1
, Test_LF1
and store it (I think I need 2 properties in my viewmodel) knowing that:
Some players may have the same results. I may not have the results yet from a player. (I'm ok we consider it to be 0).
Here an example:
Rank | Score | Player |
---|---|---|
1 | 44 | Martin Dow |
2 | 42 | Jason Doe |
2 | 42 | Big Doe |
4 | 41 | Gary Doe |
4 | 41 | Bernard Doe |
4 | 41 | Barry Doe |
7 | 39 | Stephen Doe |
8 | 0 | John Doe |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|