Selaa lähdekoodia

Database structure

Tigran 4 vuotta sitten
vanhempi
commit
88de5e4b3d

+ 30 - 0
MafiaTelegramBot/DataBase/StatisticsEntity.cs

@@ -0,0 +1,30 @@
+using MafiaTelegramBot.Resources;
+
+namespace MafiaTelegramBot.DataBase
+{
+    public class StatisticsEntity
+    {
+        public long UserId { get; init; }
+        public Roles Role { get; init; }
+
+        private int _games = 0;
+        public int Games
+        {
+            get=> _games;
+            set
+            {
+                _games = value;
+            }
+        }
+
+        private int _wins = 0;
+        public int Wins
+        {
+            get=> _wins;
+            set
+            {
+                _wins = value;
+            }
+        }
+    }
+}

+ 8 - 8
MafiaTelegramBot/DataBase/UserDao.cs

@@ -6,9 +6,9 @@ namespace MafiaTelegramBot.DataBase
 {
     public static class UserDao
     {
-        private static readonly List<User> DataBase = new();
-        private static readonly Dictionary<long,User> ActiveUsers = new();
-        public static async Task<User> GetUserById(long id)
+        private static readonly List<UserEntity> DataBase = new();
+        private static readonly Dictionary<long,UserEntity> ActiveUsers = new();
+        public static async Task<UserEntity> GetUserById(long id)
         {
             if (ActiveUsers.ContainsKey(id)) return ActiveUsers[id];
             var user = await Task.Run(()=> DataBase.First(user1 => user1.Id == id));
@@ -16,16 +16,16 @@ namespace MafiaTelegramBot.DataBase
             return user;
         }
 
-        private static User ConvertToUser()
+        private static UserEntity ConvertToUser()
         {
             return new();
         }
         
-        public static async Task Update(User user)
+        public static async Task Update(UserEntity userEntity)
         {
-            var updateIndex = await Task.Run(() => DataBase.FindIndex(user1 => user1.Id == user.Id));
-            if (updateIndex != -1) DataBase[updateIndex] = user;
-            else DataBase.Add(user);
+            var updateIndex = await Task.Run(() => DataBase.FindIndex(user1 => user1.Id == userEntity.Id));
+            if (updateIndex != -1) DataBase[updateIndex] = userEntity;
+            else DataBase.Add(userEntity);
         }
 
         public static async Task<bool> UserExists(long id)

+ 31 - 10
MafiaTelegramBot/DataBase/User.cs → MafiaTelegramBot/DataBase/UserEntity.cs

@@ -2,25 +2,41 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
-using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 
 namespace MafiaTelegramBot.DataBase
 {
-    public class User
+    public class UserEntity
     {
         public long Id { get; init; }
         public long ChatId { get; init; }
-        public string Username { get; init; } = strings.no_name;
-        public int Games { get; set; } = 0;
-        public string NickName { get; set; } = "";
-        public int Wins { get; set; } = 0;
-        public Dictionary<Roles, int> RoleGames = new();
-        public Dictionary<Roles, int> RoleWins = new();
+        
+        private string _username = strings.no_name;
+        public string Username
+        {
+            get => _username;
+            set
+            {
+                if(_username != strings.no_name) OnPropertyChangedListener("Username", value);
+                _username = value;
+            }
+        }
+
+        private string _nickName = "";
+        public string NickName
+        {
+            get => _nickName;
+            set
+            {
+                if(_nickName != "") OnPropertyChangedListener("NickName", value);
+                _nickName = value;
+            }
+        }
+        
+        public Dictionary<Roles, StatisticsEntity> Statistics = new();
 
         private Roles _currentRole = Roles.None;
         public int TurnOrder = -1;
-
         private string _roomKey = "";
         
 
@@ -63,7 +79,7 @@ namespace MafiaTelegramBot.DataBase
 
         public override bool Equals(object? obj)
         {
-            return obj is User user && user.Id == Id;
+            return obj is UserEntity user && user.Id == Id;
         }
 
         public override int GetHashCode()
@@ -80,5 +96,10 @@ namespace MafiaTelegramBot.DataBase
         {
             return roles.ResourceManager.GetString(_currentRole.ToString())!;
         }
+
+        private void OnPropertyChangedListener<T>(string property, T value)
+        {
+            
+        }
     }
 }