|
@@ -1,5 +1,10 @@
|
|
|
+using System;
|
|
|
+using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
+using MafiaTelegramBot.CustomCollections;
|
|
|
using MafiaTelegramBot.DataBase.Entity;
|
|
|
+using MafiaTelegramBot.Resources;
|
|
|
+using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
namespace MafiaTelegramBot.DataBase.EntityDao
|
|
|
{
|
|
@@ -11,5 +16,27 @@ namespace MafiaTelegramBot.DataBase.EntityDao
|
|
|
{
|
|
|
return Task.CompletedTask;
|
|
|
}
|
|
|
+
|
|
|
+ public static async Task CreatePlayerStats(long id)
|
|
|
+ {
|
|
|
+ var actualPlayerStats = await DataBase.Statistics.Where(s => s.UserId == id).ToListAsync();
|
|
|
+
|
|
|
+ var missingRoles = Enum.GetValues(typeof(Roles)).Cast<Roles>().ToList();
|
|
|
+
|
|
|
+ foreach (var entity in actualPlayerStats)
|
|
|
+ {
|
|
|
+ missingRoles.Remove((Roles) Enum.Parse(typeof(Roles),entity.Role));
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var role in missingRoles)
|
|
|
+ {
|
|
|
+ var newStatsRow = new StatisticsEntity
|
|
|
+ {
|
|
|
+ UserId = id, Role = role.ToString(), Games = 0, Wins = 0
|
|
|
+ };
|
|
|
+
|
|
|
+ await DataBase.Statistics.AddAsync(newStatsRow);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|