소스 검색

Add AppSettings properties

Tigran 4 년 전
부모
커밋
08df790879
3개의 변경된 파일20개의 추가작업 그리고 7개의 파일을 삭제
  1. 10 3
      MafiaTelegramBot/DataBase/Mafia.cs
  2. 2 2
      MafiaTelegramBot/DataBase/UserEntity.cs
  3. 8 2
      MafiaTelegramBot/Resources/AppSettings.cs

+ 10 - 3
MafiaTelegramBot/DataBase/Mafia.cs

@@ -1,4 +1,5 @@
 using System.ComponentModel.DataAnnotations.Schema;
+using MafiaTelegramBot.Resources;
 using Microsoft.EntityFrameworkCore;
 
 namespace MafiaTelegramBot.DataBase
@@ -7,14 +8,20 @@ namespace MafiaTelegramBot.DataBase
     {
         public DbSet<UserEntity> Users { get; set; }
         //public DbSet<StatisticsEntity> Statistics { get; set; }
-        
+
         protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
         {
             //#warning To protect potentially sensitive information in your connection string, 
             //you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 
             //for guidance on storing connection strings.
-     
-            optionsBuilder.UseMySQL("server=192.168.2.2;port=3306;database=mafia;uid=mafia_bot; pwd=73*MYSQLpassword73*");
+
+            optionsBuilder.UseMySQL(
+                $"server={AppSettings.IpAddress};" +
+                $"port={AppSettings.Port};" +
+                $"database={AppSettings.Database};" +
+                $"uid={AppSettings.Uid};" +
+                $"pwd={AppSettings.Pwd}"
+            );
         }
     }
 }

+ 2 - 2
MafiaTelegramBot/DataBase/UserEntity.cs

@@ -25,7 +25,7 @@ namespace MafiaTelegramBot.DataBase
             get => _username;
             set
             {
-                if(_username != strings.no_name) OnPropertyChangedListener("Username", value);
+                if(_username != strings.no_name && _username != value) OnPropertyChangedListener("Username", value);
                 _username = value;
             }
         }
@@ -37,7 +37,7 @@ namespace MafiaTelegramBot.DataBase
             get => _nickName;
             set
             {
-                if(_nickName != "") OnPropertyChangedListener("NickName", value);
+                if(_nickName != "" && _nickName != value) OnPropertyChangedListener("NickName", value);
                 _nickName = value;
             }
         }

+ 8 - 2
MafiaTelegramBot/Resources/AppSettings.cs

@@ -3,7 +3,13 @@ namespace MafiaTelegramBot.Resources
     public static class AppSettings
     {
         //public static string Url { get; set; } = ""; //TODO use this if need html tg api to get message updates
-        public static string Name { get; set; } = ""; //TODO paste your bot name here if need using full commands like /start@mafiabot, if value "", triggers to all /start commands
-        public static string Token { get; set; } = "1729356281:AAG8D_hO9b2WIS19doTVrPiPW3q7GFwAX2w"; //TODO paste your bot token here
+        public static string Name { get; } = ""; //TODO paste your bot name here if need using full commands like /start@mafiabot, if value "", triggers to all /start commands
+        public static string Token { get; } = ""; //TODO paste your bot token here
+        public static string IpAddress { get; } = ""; //TODO paste your database ip address here
+        public static string Port { get; } = ""; //TODO paste your database port here
+        public static string Database { get; } = ""; //TODO paste your database name here
+        public static string Uid { get; } = ""; //TODO paste your database username here
+        public static string Pwd { get; } = ""; //TODO paste your database password here
+        
     }
 }