Help me fix or release this issue My Task: correct guesses/games played If the success rate is the same - player with fewer total tries is ranked higher Input minimum games played N - players will be included in the leaderboard if at least N games are played
My Players model:
[Table("players")]
public class Player
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string Id { get; set; }
[Required]
[Display(Name = "Player name")]
public string Name { get; set; }
[JsonIgnore]
public List<Game> Games { get; set; }
}
I am creating leaderbords list from Games table, And this is my Games model:
[Table("games")]
public class Game
{
public Game()
{
this.StartDate = DateTime.Now;
this.Attempts = 0;
this.EndDate = null;
this.Result = GameResultType.InGame;
}
[Key]
public int ID { get; set; }
[Required]
[Display(Name = "Player")]
public Player Player
{
get;
set;
}
[Display(Name = "Count Attempts")]
public int Attempts
{
get;
set;
}
[Required]
[Display(Name = "Random number")]
[JsonIgnore]
public int RandomNumber
{
get;
set;
}
[Display(Name = "Game start datetime")]
public DateTime StartDate
{
get;
set;
}
[Display(Name = "Game end datetime")]
public DateTime? EndDate
{
get;
set;
}
[Display(Name = "Status of the game")]
public StatusType Status
{
get;
set;
}
[Display(Name = "Status of the game")]
public GameResultType Result
{
get;
set;
}
And i should get leaderboards which players played N games
Here is my query:
var noticesGrouped = _context.Games
.GroupBy(n => n.Player)
.Select(group =>
new
{
PlayerName = group.Key.Name,
Games = group.Key.Games.ToList(),
Count = group.Key.Games.Count()
}).Where(x => x.Games.Count > 1).ToList();