{"id":389199,"date":"2024-06-29T08:26:29","date_gmt":"2024-06-29T08:26:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=389199"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=389199","title":{"rendered":"<span>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 Telegram.Bot \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440 \u043d\u0430 C#<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u0427\u0430\u0441\u0442\u044c 1<\/h2>\n<h2>\u041f\u043e\u0447\u0435\u043c\u0443?<\/h2>\n<p>\u0420\u0435\u0448\u0438\u043b \u044f \u043f\u043e\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u0448\u0430\u0440\u043f\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c EF. \u041f\u043e\u043a\u0430 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b\u0441\u044f \u0437\u0430\u043c\u0435\u0442\u0438\u043b, \u0447\u0442\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u043e\u0432 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u043d\u0430 C# \u043d\u0435\u043c\u043d\u043e\u0433\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c\u0438 \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u043a\u0430\u043c\u0438. <\/p>\n<h2>\u0427\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u043e\u0442:<\/h2>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0431\u043e\u0442\u0430 &#8212; \u0443\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043e\u0431\u043c\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u0438 \u043f\u043e\u0434\u0447\u0438\u043d\u0435\u043d\u043d\u044b\u043c\u0438 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0433\u043b\u0430\u0432\u043d\u044b\u0439(\u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440) \u043c\u043e\u0433 \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435\u043c \u0438\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0447\u0438\u043d\u0435\u043d\u043d\u043e\u043c\u0443(\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044e), \u0430 \u043f\u043e\u0434\u0447\u0438\u043d\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0433\u043b\u0430\u0432\u043d\u044b\u043c. WebHook \u043d\u0435 \u043d\u0443\u0436\u0435\u043d, \u0442.\u043a. \u0431\u043e\u0442 \u0441\u0443\u0433\u0443\u0431\u043e \u0434\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438.<\/p>\n<h2>\u041c\u043e\u0434\u0435\u043b\u044c \u0411\u0414<\/h2>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0448\u0438\u043b \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e \u0438\u0442\u043e\u0433\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/68a\/5b5\/db6\/68a5b5db680fbf303b5b5815ba942cd1.jpg\" width=\"689\" height=\"571\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/68a\/5b5\/db6\/68a5b5db680fbf303b5b5815ba942cd1.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 1:<\/h2>\n<p>\u0414\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b Postgre SQL 15, \u0430 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 PgAdmin 4. \u0421\u043e\u0437\u0434\u0430\u043b \u0431\u0434 Users \u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u043b \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e.<\/p>\n<details class=\"spoiler\">\n<summary>\u0441\u043a\u0430\u0447\u0430\u0442\u044c <\/summary>\n<div class=\"spoiler__content\">\n<p><a href=\"https:\/\/www.enterprisedb.com\/postgresql-tutorial-resources-training?uuid=7ce7e93f-e1eb-4e42-85fa-84c0c98859ee&amp;campaignId=7012J000001h3GiQAI\" rel=\"noopener noreferrer nofollow\">https:\/\/www.enterprisedb.com\/postgresql-tutorial-resources-training?uuid=7ce7e93f-e1eb-4e42-85fa-84c0c98859ee&amp;campaignId=7012J000001h3GiQAI<\/a><\/p>\n<p><a href=\"https:\/\/www.pgadmin.org\/download\/pgadmin-4-windows\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.pgadmin.org\/download\/pgadmin-4-windows\/<\/a><\/p>\n<\/div>\n<\/details>\n<h2>\u0428\u0430\u0433 2:<\/h2>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0432 VS \u0447\u0435\u0440\u0435\u0437 NuGET:<\/p>\n<ul>\n<li>\n<p>Microsoft.EntityFrameworkCore.Tools<\/p>\n<\/li>\n<li>\n<p>Newtonsoft.Json<\/p>\n<\/li>\n<li>\n<p>Npgsql.EntityFrameworkCore.PostgreSQL<\/p>\n<\/li>\n<li>\n<p>Telegram.Bot<\/p>\n<\/li>\n<li>\n<p>Telegram.Bot.Extensions.Polling<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b65\/68f\/178\/b6568f178263d6cbe36db40400733fc6.png\" width=\"996\" height=\"341\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b65\/68f\/178\/b6568f178263d6cbe36db40400733fc6.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 3:<\/h2>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d <a href=\"https:\/\/telegram.me\/BotFather\" rel=\"noopener noreferrer nofollow\">https:\/\/telegram.me\/BotFather<\/a> \u0438 \u043f\u043b\u0430\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043a\u043e\u0434\u0443.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/868\/d1f\/9f7\/868d1f9f77960080eabba12fd2374227.png\" width=\"608\" height=\"617\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/868\/d1f\/9f7\/868d1f9f77960080eabba12fd2374227.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 4:<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 Program.cs \u0438 \u0432\u043d\u0435\u0441\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u041c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<pre><code class=\"cs\">using Telegram.Bot; using Telegram.Bot.Extensions.Polling; using Telegram.Bot.Types.ReplyMarkups; using CETmsgr.keyboards; using CETmsgr.dbutils; using Update = Telegram.Bot.Types.Update; using Telegram.Bot.Types.Enums;  namespace CETmsgr {     class Program     {         static ITelegramBotClient bot = new TelegramBotClient(\"TOKEN\");         public static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)         {             Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(update));           if (update.Type == UpdateType.Message)           {           \/\/ \u0422\u0443\u0442 \u0431\u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f             \/\/ \u0414\u0430\u043b\u044c\u0448\u0435 \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0441\u0442\u0430\u0440\u0442, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 botfather             \/\/ \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 program.cs \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u044b\u0432\u0435\u0434\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0431\u043e\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d             \/\/ \u0430 \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0431\u043e\u0442 \u043d\u0430\u043f\u0438\u0448\u0435\u0442 \u041f\u0440\u0438\u0432\u0435\u0442             if (message.Text.ToLower() == \"\/start\")                 {                     await DataBaseMethods.ToggleInDialogStatus(update.Message.Chat.Id, 0);                     await botClient.SendTextMessageAsync(                         chatId: message.Chat,                         text: \"\u041f\u0440\u0438\u0432\u0435\u0442\");                      return;           }           if (update.Type == UpdateType.CallbackQuery)           {           \/\/ \u0422\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043d\u0430 inline \u043a\u043d\u043e\u043f\u043a\u0438           }           public static async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)         {             \/\/ \u0414\u0430\u043d\u043d\u044b\u0439 \u0425\u0435\u043d\u0434\u043b\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0438\u0445 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432 \u0432\u0438\u0434\u0435 JSON             Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(exception));         }         static void Main(string[] args)         {              Console.WriteLine(\"\u0417\u0430\u043f\u0443\u0449\u0435\u043d \u0431\u043e\u0442 \" + bot.GetMeAsync().Result.FirstName);             var cts = new CancellationTokenSource();             var cancellationToken = cts.Token;             var receiverOptions = new ReceiverOptions             {                 AllowedUpdates = { }, \/\/ \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u0438\u0434\u044b \u0430\u043f\u0434\u0435\u0439\u0442\u043e\u0432             };             bot.StartReceiving(                 HandleUpdateAsync,                 HandleErrorAsync,                 receiverOptions,                 cancellationToken             );             Console.ReadLine();                      }     } }<\/code><\/pre>\n<h2>\u0428\u0430\u0433 5:<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446, \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0430\u043f\u043a\u0443 dbutils \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u043d\u0443\u0436\u0434.<\/p>\n<p>UserRoles \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e \u0440\u043e\u043b\u044f\u043c.<\/p>\n<p>TrafficControllers \u0438 Drivers \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u044e\u0437\u0435\u0440\u0430\u043c.<\/p>\n<p>DialogMembers \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 id \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u043c\u0435\u0436\u0434\u0443 id 2\u0445 \u044e\u0437\u0435\u0440\u043e\u0432<\/p>\n<p>DialogMsgs \u044d\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 id \u0434\u0438\u0430\u043b\u043e\u0433\u0430 \u0438\u0437 DialogMembers <\/p>\n<p>DialogStatus \u0430 \u0432\u043e\u0442 \u044d\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u044e\u0437\u0435\u0440\u043e\u0432 \u0431\u043e\u0442\u0443. <\/p>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class UserRoles     {         [Key]         public long TgId { get; set; }         public string Role { get; set; }         public string? TgUsername { get; set; }         public long TgChatId { get; set; }         public int StageReg { get; set; }      } }<\/code><\/pre>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class Drivers     {         [Key]         public long IdDriver { get; set; }         public string Name { get; set; }         public string IdRoute { get; set; }         public string VehichleRegNum { get; set; }         public string DeviceSerialNum { get; set; }     } }<\/code><\/pre>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class TrafficControllers     {         [Key]         public long IdTc { get; set; }         public string Name { get; set; }     } }<\/code><\/pre>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class DialogMembers     {         [Key]         public int IdThread { get; set; }         public long IdTc { get; set; }         public long IdDriver { get; set; }     } }<\/code><\/pre>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class DialogMsgs     {         [Key]         public long IdUnique { get; set; }         public int IdThread { get; set; }         public string Created { get; set; }         public string UrgentLevel { get; set; }         public string Message { get; set; }     } }<\/code><\/pre>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class DialogStatus     {         [Key]         public long TgId { get; set; }         public int Status { get; set; }         public long CurrentDialog { get; set; }      } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0440\u0430 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0431\u0434 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0431\u0434:<\/p>\n<pre><code class=\"cs\">using Microsoft.EntityFrameworkCore;  namespace CETmsgr.dbutils {     public class ApplicationContext : DbContext     {         public DbSet&lt;UserRoles> UserRoles { get; set; }         public DbSet&lt;Drivers> Drivers { get; set; }         public DbSet&lt;TrafficControllers> TrafficControllers { get; set; }         public DbSet&lt;DialogMsgs> DialogMsgs { get; set; }         public DbSet&lt;DialogMembers> DialogMembers { get; set; }         public DbSet&lt;DialogStatus> DialogStatus { get; set; }          protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)         {             optionsBuilder.UseNpgsql(                 \"Host=localhost;\" +                 \"Port=5433;\" +                 \"Database=Users;\" +                 \"Username=postgres;\" +                 \"Password=zaqwsxzaq\");         }     } }      <\/code><\/pre>\n<p>\u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e:<\/p>\n<p>\u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0432\u0432\u043e\u0434\u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code>enable-migrations<\/code><\/pre>\n<pre><code>Add-migration *\u0418\u043c\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438*<\/code><\/pre>\n<pre><code>update-database<\/code><\/pre>\n<p>\u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<h2>\u0428\u0430\u0433 6:<\/h2>\n<p>\u0418\u0442\u0430\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c. \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0440\u0430\u043d\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0430\u043f\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b DataBaseMethods.cs. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u043e\u0439 \u0431\u043e\u0442 \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432 \u044f \u0432\u044b\u043b\u043e\u0436\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u0434\u0430\u0431\u044b \u043d\u0435 \u0437\u0430\u043f\u0443\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0430\u0441 \u0440\u0430\u0437\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<pre><code class=\"cs\">using Microsoft.EntityFrameworkCore; using System.Data;  namespace CETmsgr.dbutils {     internal class DataBaseMethods     {         \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c. \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043d\u0435 \u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0438\u0437\u043b\u0438\u0448\u043d\u0438\u043c\u0438, \u043d\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u0438\u0445 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043a \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442         public static async Task&lt;long> MsgCreateByDriverToTc(int IdThread, string Msg, string Crtd, string UL)         {             using (ApplicationContext db = new ApplicationContext())             {                 DialogMsgs newMSG = new DialogMsgs { IdThread = IdThread, Created = Crtd, UrgentLevel = UL, Message = Msg };                 await db.DialogMsgs.AddAsync(newMSG);                 await db.SaveChangesAsync();                 try                 {                     var getMSG = await db.DialogMsgs.OrderBy(x => x.Created).LastOrDefaultAsync(x => x.IdThread == IdThread);                     return getMSG.IdUnique;                 }                 catch(Exception ex)                 {                     return 123123;                 }                              }         }         \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u043e\u043c         public static async Task&lt;long> MsgCreateByTcToDriver(int IdThread, string Msg, string Crtd, string UL)         {             using (ApplicationContext db = new ApplicationContext())             {                 DialogMsgs newMSG = new DialogMsgs { IdThread = IdThread, Created = Crtd, UrgentLevel = UL, Message = Msg };                 await db.DialogMsgs.AddAsync(newMSG);                 await db.SaveChangesAsync();                 try                 {                     var getMSG = await db.DialogMsgs.OrderBy(x => x.IdUnique).LastOrDefaultAsync(x => x.IdThread == IdThread);                     return getMSG.IdUnique;                 }                 catch (Exception ex)                 {                     return 123123;                 }              }         }         \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u043e\u043c         public static async Task&lt;long> MsgRecievierTc(long IdUnique, int IdThread, long IdDriver)         {             using (ApplicationContext db = new ApplicationContext())             {                 var getMSG = await db.DialogMsgs.FirstOrDefaultAsync(x => x.IdUnique == IdUnique);                 var getId = await db.DialogMembers.FirstOrDefaultAsync(x => (x.IdThread == IdThread &amp;&amp; x.IdDriver == IdDriver));                 if (getMSG.IdThread == getId.IdThread)                 {                     return getId.IdTc;                 }                 else                 {                     return 404;                 }             }         }         \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c          public static async Task&lt;long> MsgRecievierDriver(long IdUnique, int IdThread, long IdTc)         {             using (ApplicationContext db = new ApplicationContext())             {                 var getMSG = await db.DialogMsgs.FirstOrDefaultAsync(x => x.IdUnique == IdUnique);                 var getId = await db.DialogMembers.FirstOrDefaultAsync(x => (x.IdThread == IdThread &amp;&amp; x.IdTc == IdTc));                 if (getMSG.IdThread == getId.IdThread)                 {                     return getId.IdDriver;                 }                 else                 {                     return 404;                 }             }         }         \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0443\u0442\u0441\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0447\u0442\u043e\u0431\u044b \u0431\u043e\u0442 \u043c\u043e\u0433 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0444\u0438\u043b\u044c\u0442\u0440\u0443         public static async Task&lt;int> GetStatus(long TgId)         {             using (ApplicationContext db = new ApplicationContext())             {                 var status = await db.DialogStatus.FirstOrDefaultAsync(x => x.TgId == TgId);                 return status.Status;             }         }         \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 id \u044e\u0437\u0435\u0440\u0430 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u0431\u043e\u0442\u0430 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u044e\u0437\u0435\u0440\u0430 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043e\u043a \u0432 \u0434\u0438\u0430\u043b\u043e\u0433\u0430\u0445         public static async Task&lt;long> GetAddress(long TgId)         {             using (ApplicationContext db = new ApplicationContext())             {                 var status = await db.DialogStatus.FirstOrDefaultAsync(x => x.TgId == TgId);                 return status.CurrentDialog;             }         }         \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 id \u0434\u0438\u0430\u043b\u043e\u0433\u0430 \u0438\u0437 \u0431\u0434         public static async Task&lt;int> GetThreadByDriver(long IdDriver)         {             using (ApplicationContext db = new ApplicationContext())             {                 var dialog = await db.DialogMembers.FirstOrDefaultAsync(x => x.IdDriver == IdDriver);                 return dialog.IdThread;             }         }         \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 id \u0434\u0438\u0430\u043b\u043e\u0433\u0430 \u0438\u0437 \u0431\u0434         public static async Task&lt;int> GetThreadByTc(long IdTc, long IdDriver)         {             using (ApplicationContext db = new ApplicationContext())             {                 var dialog = await db.DialogMembers.FirstOrDefaultAsync(x => x.IdTc == IdTc &amp;&amp; x.IdDriver == IdDriver);                 return dialog.IdThread;             }         }         \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u043e\u043b\u0438 \u044e\u0437\u0435\u0440\u0430         public static async Task&lt;UserRoles> GetUserRole(long TgId)         {             using (ApplicationContext db = new ApplicationContext())             {                 var user = await db.UserRoles.FirstOrDefaultAsync(x => x.TgId == TgId);                 return user;             }         }         \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f         public static async Task&lt;Drivers> GetDriverData(long IdDriver)         {             using (ApplicationContext db = new ApplicationContext())             {                 var driver = await db.Drivers.FirstOrDefaultAsync(x => x.IdDriver == IdDriver);                 return driver;             }         }         \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430         public static async Task&lt;TrafficControllers> GetTcData(long IdTc)         {             using (ApplicationContext db = new ApplicationContext())             {                 var tc = await db.TrafficControllers.FirstOrDefaultAsync(x => x.IdTc == IdTc);                 return tc;             }         }         \/\/ \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u044e\u0437\u0435\u0440\u0430 \u0438 id \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f         public static async Task ToggleInDialogStatus(long TgId, int Status, long receivier)         {             using (ApplicationContext db = new ApplicationContext())             {                 var dialogStatus = await db.DialogStatus.FirstOrDefaultAsync(x => x.TgId == TgId );                 if (dialogStatus is null)                 {                     DialogStatus StatusCreate = new DialogStatus { TgId = TgId, Status = Status, CurrentDialog = receivier};                     var result = await db.DialogStatus.AddAsync(StatusCreate);                     await db.SaveChangesAsync();                 }                 else                 {                     dialogStatus.Status = Status;                     dialogStatus.CurrentDialog = receivier;                     db.DialogStatus.Update(dialogStatus);                     await db.SaveChangesAsync();                 }             }         }         \/\/ \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u044e\u0437\u0435\u0440\u0430         public static async Task ToggleInDialogStatus(long TgId, int Status)         {             using (ApplicationContext db = new ApplicationContext())             {                 var dialogStatus = await db.DialogStatus.FirstOrDefaultAsync(x => x.TgId == TgId);                 if (dialogStatus is null)                 {                     DialogStatus StatusCreate = new DialogStatus { TgId = TgId, Status = Status, CurrentDialog = 0 };                     var result = await db.DialogStatus.AddAsync(StatusCreate);                     await db.SaveChangesAsync();                 }                 else                 {                     dialogStatus.Status = Status;                     dialogStatus.CurrentDialog = 0;                     db.DialogStatus.Update(dialogStatus);                     await db.SaveChangesAsync();                 }             }         }         \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u044e\u0437\u0435\u0440\u0430         public static async Task AddOrUpdateUser(long tg_ID, string role, string tg_username, long tg_chat_id, int StageReg)         {             using (ApplicationContext db = new ApplicationContext())             {                 var user = await db.UserRoles.FirstOrDefaultAsync(x => x.TgId == tg_ID);                 if (user is null)                 {                     if (tg_username == null)                     {                         tg_username = \"\u0411\u0435\u0437 \u043d\u0438\u043a\u0430\";                     }                     UserRoles newuser = new UserRoles { TgId = tg_ID, Role = role, TgUsername = tg_username, TgChatId = tg_chat_id, StageReg = StageReg };                     await db.UserRoles.AddAsync(newuser);                     await db.SaveChangesAsync();                 }                 else                 {                     user.Role = role;                     user.TgUsername = tg_username;                     db.UserRoles.Update(user);                     await db.SaveChangesAsync();                 }             }          }         \/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u0438\u0430\u043b\u043e\u0433\u0430         public static async Task DialogCreate(long IdTc, long IdDriver)         {             using (ApplicationContext db = new ApplicationContext())             {                 var dialogWithDriver = await db.DialogMembers.FirstOrDefaultAsync(x => x.IdDriver == IdDriver &amp;&amp; x.IdTc == IdTc);                 if (dialogWithDriver is null)                 {                     DialogMembers newDialog = new DialogMembers { IdDriver = IdDriver, IdTc = IdTc };                     var result = await db.DialogMembers.AddAsync(newDialog);                     await db.SaveChangesAsync();                 }                 else                 {                  }             }         }         \/\/ \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f         public static async Task StageIncrement(long tg_ID, int StageReg)         {             using (ApplicationContext db = new ApplicationContext())             {                 var user = await db.UserRoles.FirstOrDefaultAsync(x => x.TgId == tg_ID);                 user.StageReg = StageReg;                 db.UserRoles.Update(user);                 await db.SaveChangesAsync();             }         }         \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0434\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u043e \u043d\u0443\u043b\u044f\u043c, \u0447\u0442\u043e\u0431\u044b exception \u043d\u0435 \u0441\u043b\u043e\u0432\u0438\u0442\u044c         public static async Task AddDriver(long IdDriver)         {             using (ApplicationContext db = new ApplicationContext())             {                 var user = await db.Drivers.FirstOrDefaultAsync(x => x.IdDriver == IdDriver);                 if (user is null)                 {                 string Name = \"0\";                 string IdRoute = \"0\";                 string VehichleRegNum = \"0\";                 string DeviceSerialNum = \"0\";                 Drivers newDriver = new Drivers { IdDriver = IdDriver, Name = Name, IdRoute = IdRoute, VehichleRegNum = VehichleRegNum, DeviceSerialNum = DeviceSerialNum};                 var result = db.Drivers.AddAsync(newDriver);                 await db.SaveChangesAsync();                 }                              }         }         \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430         public static async Task AddTc(long IdTc)         {             using (ApplicationContext db = new ApplicationContext())             {                 var user = await db.TrafficControllers.FirstOrDefaultAsync(x => x.IdTc == IdTc);                 if (user is null)                 {                     string Name = \"0\";                     TrafficControllers newTc = new TrafficControllers { IdTc = IdTc, Name = Name};                     var result = await db.TrafficControllers.AddAsync(newTc);                     await db.SaveChangesAsync();                 }              }         }         \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0434 \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f         public static async Task AddDataDriverName(long IdDriver, string Name)         {             using (ApplicationContext db = new ApplicationContext())             {                 var Driver = await db.Drivers.FirstOrDefaultAsync(x => x.IdDriver == IdDriver);                 Driver.Name = Name;                 db.Drivers.Update(Driver);                 await db.SaveChangesAsync();             }         }         public static async Task AddDataDriverIdRoute(long IdDriver, string IdRoute)         {             using (ApplicationContext db = new ApplicationContext())             {                 var Driver = await db.Drivers.FirstOrDefaultAsync(x => x.IdDriver == IdDriver);                 Driver.IdRoute = IdRoute;                 db.Drivers.Update(Driver);                 await db.SaveChangesAsync();             }         }         public static async Task AddDataDriverVehichleRegNum(long IdDriver, string VehichleRegNum)         {             using (ApplicationContext db = new ApplicationContext())             {                 var Driver = await db.Drivers.FirstOrDefaultAsync(x => x.IdDriver == IdDriver);                 Driver.VehichleRegNum = VehichleRegNum;                 db.Drivers.Update(Driver);                 await db.SaveChangesAsync();             }         }         public static async Task AddDataDriverDeviceSerialNum(long IdDriver, string DeviceSerialNum)         {             using (ApplicationContext db = new ApplicationContext())             {                 var Driver = await db.Drivers.FirstOrDefaultAsync(x => x.IdDriver == IdDriver);                 Driver.DeviceSerialNum = DeviceSerialNum;                 db.Drivers.Update(Driver);                 await db.SaveChangesAsync();             }         }         \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0434 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430         public static async Task AddDataTcName(long IdDriver, string Name)         {             using (ApplicationContext db = new ApplicationContext())             {                 var tc = await db.TrafficControllers.FirstOrDefaultAsync(x => x.IdTc == IdDriver);                 tc.Name = Name;                 db.TrafficControllers.Update(tc);                 await db.SaveChangesAsync();             }         }         \/\/ \u0432\u044b\u0432\u043e\u0434 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439         public static List&lt;long> GetAllDriversId(string role)         {             \/\/Dictionary&lt;long, string> driversId_Name = new Dictionary&lt;long, string>();             using (ApplicationContext db = new ApplicationContext())             {                 var AllDrivers = db.UserRoles.Where(x => x.Role == role).ToList();                 List&lt;long> driversIDs = new List&lt;long>();                 foreach (var u in AllDrivers)                     driversIDs.Add(u.TgId);                 return driversIDs;             }          }     } }<\/code><\/pre>\n<h2>\u0424\u0438\u043d\u0430\u043b:<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u043e\u0442\u0430 \u043d\u0430 \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043f\u0438\u0448\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 kb. <\/p>\n<pre><code class=\"cs\">namespace CETmsgr.keyboards {     public static class kb     {         public static ReplyKeyboardMarkup Register = new(new[]         {             new KeyboardButton[] { \"\/reg\" },         })         { ResizeKeyboard = true };         public static InlineKeyboardMarkup Role = new(new[]         {             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u0412\u043e\u0434\u0438\u0442\u0435\u043b\u044c\", callbackData: \"driver\"),                 InlineKeyboardButton.WithCallbackData(text: \"\u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\", callbackData: \"controller\"),             },         });         public static InlineKeyboardMarkup Menu = new(new[]         {             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u0414\u0438\u0430\u043b\u043e\u0433\u0438\", callbackData: \"dialogs\"),                 InlineKeyboardButton.WithCallbackData(text: \"\u041f\u0440\u043e\u0444\u0438\u043b\u044c\", callbackData: \"profile\"),             },             \/\/new []             \/\/{             \/\/    InlineKeyboardButton.WithCallbackData(text: \"\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f\", callbackData: \"register\"),             \/\/},         });         public static InlineKeyboardMarkup ToMenu = new(new[]         {             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u041c\u0435\u043d\u044e\", callbackData: \"menu\"),             },         });          public static InlineKeyboardMarkup StartRegDriver = new(new[]         {             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u0412\u0430\u0448\u0435 \u0424\u0418\u041e\", callbackData: \"DriverName\"),             },             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430\", callbackData: \"IdRoute\"),             },                         new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0442\u0441\", callbackData: \"VehichleRegNum\"),             },                       new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u0421\u0435\u0440\u0438\u0439\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\", callbackData: \"DeviceSerialNum\"),             },             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u041e\u043a\u043e\u043d\u0447\u0438\u0442\u044c \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e\", callbackData: \"FinReg\"),             },         });         public static InlineKeyboardMarkup StartRegTC = new(new[]         {             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u0412\u0430\u0448\u0435 \u0424\u0418\u041e\", callbackData: \"TcName\"),             },             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u041e\u043a\u043e\u043d\u0447\u0438\u0442\u044c \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e\", callbackData: \"FinReg\"),             },         });         public static InlineKeyboardMarkup MsgToDriver = new(new[]         {             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u0412\u043e\u0434\u0438\u0442\u0435\u043b\u044c\", callbackData: \"driver\"),                 InlineKeyboardButton.WithCallbackData(text: \"\u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\", callbackData: \"controller\"),             },         });         public static InlineKeyboardMarkup MsgDispetcher = new(new[]         {             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\", callbackData: \"callTC\"),             },         });         public static InlineKeyboardMarkup TextAll = new(new[]         {             new []             {                 InlineKeyboardButton.WithCallbackData(text: \"\u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435\u043c\", callbackData: \"textall\"),             },         });     } }<\/code><\/pre>\n<p>\u0412\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u0432 \u043a\u043b\u0430\u0441\u0441 program<\/p>\n<pre><code class=\"cs\">using Telegram.Bot; using Telegram.Bot.Extensions.Polling; using Telegram.Bot.Types.ReplyMarkups; using CETmsgr.keyboards; using CETmsgr.dbutils; using Update = Telegram.Bot.Types.Update; using Telegram.Bot.Types.Enums;  namespace CETmsgr {       class Program     {         static ITelegramBotClient bot = new TelegramBotClient(\"TOKEN\");         public static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)         {             Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(update));                          if (update.Type == UpdateType.Message)             {                 string Time = DateTime.Now.ToShortTimeString();                 var message = update.Message;                  if (message.Text.ToLower() == \"\/reg\")                 {                     await DataBaseMethods.ToggleInDialogStatus(update.Message.Chat.Id, 0);                     await botClient.SendTextMessageAsync(                         message.Chat.Id,                         \"\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430...\",                         replyMarkup: new ReplyKeyboardRemove());                      var userData = await DataBaseMethods.GetUserRole(message.From.Id);                     if (userData != null)                     {                         await botClient.SendTextMessageAsync(                             message.Chat.Id,                             text: \"\u0412\u044b \u0443\u0436\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c\",                             replyMarkup: kb.ToMenu);                     }                     else                     {                          await botClient.SendTextMessageAsync(                             message.Chat.Id,                             text: \"\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0441\u0432\u043e\u044e \u0434\u043e\u043b\u0436\u043d\u043e\u0441\u0442\u044c\",                             replyMarkup: kb.Role);                     }                     return;                 }                 if (message.Text.ToLower() == \"\/start\")                 {                     await DataBaseMethods.ToggleInDialogStatus(update.Message.Chat.Id, 0);                     await botClient.SendTextMessageAsync(                         chatId: message.Chat,                         text: \"\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043c\u0435\u043d\u044e\",                         replyMarkup: kb.Menu);                      return;                 } \/\/ \u044d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u043b\u0438 \u0442\u0443\u0434\u0430 \u043a\u0443\u0434\u0430 \u043d\u0435 \u043d\u0430\u0434\u043e                 if (!message.Text.StartsWith(\"\/\"))                 {                     int dialogStatus = await DataBaseMethods.GetStatus(message.Chat.Id);                     var userDataReg = await DataBaseMethods.GetUserRole(message.Chat.Id);                     string role = userDataReg.Role;                     int countReg = userDataReg.StageReg; \/\/ \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u042f \u0414\u0418\u0421\u041f\u0415\u0422\u0427\u0415\u0420\u0410 \u0418 \u0412\u041e\u0414\u0418\u0422\u0415\u041b\u042f, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0438 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f                                         if (countReg == 1 &amp;&amp; role == \"driver\" &amp;&amp; dialogStatus == 0)                     {                         await DataBaseMethods.AddDataDriverName(message.From.Id, message.Text);                     }                     if (countReg == 1 &amp;&amp; role == \"controller\" &amp;&amp; dialogStatus == 0)                     {                         await DataBaseMethods.AddDataTcName(message.From.Id, message.Text);                         await botClient.SendTextMessageAsync(                             message.Chat.Id,                             text: \"\u0425\u043e\u0442\u0438\u0442\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u0432 \u043c\u0435\u043d\u044e?\",                             replyMarkup: kb.ToMenu);                     }                     if (countReg == 2 &amp;&amp; dialogStatus == 0)                     {                         await DataBaseMethods.AddDataDriverIdRoute(message.From.Id, message.Text);                     }                     if (countReg == 3 &amp;&amp; dialogStatus == 0)                     {                         await DataBaseMethods.AddDataDriverVehichleRegNum(message.From.Id, message.Text);                     }                     if (countReg == 4 &amp;&amp; dialogStatus == 0)                     {                         await DataBaseMethods.AddDataDriverDeviceSerialNum(message.From.Id, message.Text);                         await botClient.SendTextMessageAsync(                             message.Chat.Id,                             text: \"\u0425\u043e\u0442\u0438\u0442\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u0432 \u043c\u0435\u043d\u044e?\",                             replyMarkup: kb.ToMenu);                     } \/\/ \u0430 \u0432\u043e\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0441\u0442\u0430\u0442\u0443\u0441\u044b, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u043a\u043e\u043c \u0434\u0438\u0430\u043b\u043e\u0433\u0435, \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u043e\u0442\u0430, \/\/ \u043f\u043e\u043a\u0430 \u044e\u0437\u0435\u0440 \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u0432 \u043c\u0435\u043d\u044e                      if (role == \"driver\" &amp;&amp; dialogStatus == 1)                     {                         var getDialog = await DataBaseMethods.GetThreadByDriver(                             message.Chat.Id);                         var msgID = await DataBaseMethods.MsgCreateByDriverToTc(                             getDialog,                             message.Text,                             Time,                             \"3\");                         var reciever = await DataBaseMethods.MsgRecievierTc(msgID, getDialog, message.Chat.Id);                         var msgFrom = await DataBaseMethods.GetDriverData(message.Chat.Id);                         await botClient.SendTextMessageAsync(                             reciever,                             text: $\"{msgFrom.Name}:\" + \"\\n\" +                             $\"\u041c\u0430\u0440\u0448\u0440\u0443\u0442: {msgFrom.IdRoute}:\" + \"\\n\" +                             $\"{message.Text}\");                     }                     if (role == \"controller\" &amp;&amp; dialogStatus == 1)                     {                         var getAddress = await DataBaseMethods.GetAddress(message.Chat.Id);                         var getDialog = await DataBaseMethods.GetThreadByTc(                             message.Chat.Id,                             IdDriver: getAddress);                         var msgID = await DataBaseMethods.MsgCreateByTcToDriver(                             getDialog,                             message.Text,                             Time,                             \"3\");                         var reciever = await DataBaseMethods.MsgRecievierDriver(msgID, getDialog, message.Chat.Id);                         var msgFrom = await DataBaseMethods.GetTcData(message.Chat.Id);                         await botClient.SendTextMessageAsync(                             reciever,                             text: $\"{msgFrom.Name}:\" + \"\\n\" +                             $\"{message.Text}\");                     } \/\/ \u044d\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0438\u0447\u0430 \u043f\u043e\u0434 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0443 \u0432\u0441\u0435\u043c \u0412 \u043e\u0442 \u0414 \u0432 \u0431\u043e\u0442\u0435                     if (role == \"controller\" &amp;&amp; dialogStatus == 2)                     {                         var getAddress = DataBaseMethods.GetAllDriversId(\"driver\");                         foreach (var address in getAddress)                         {                             var getDialog = await DataBaseMethods.GetThreadByTc(                                 message.Chat.Id,                                 IdDriver: address);                             var msgID = await DataBaseMethods.MsgCreateByTcToDriver(                                 getDialog,                                 message.Text,                                 Time,                                 \"3\");                             var reciever = await DataBaseMethods.MsgRecievierDriver(msgID, getDialog, message.Chat.Id);                             var msgFrom = await DataBaseMethods.GetTcData(message.Chat.Id);                             await botClient.SendTextMessageAsync(                                 reciever,                                 text: $\"{msgFrom.Name}:\" + \"\\n\" +                                 $\"{message.Text}\");                         }                     }                     else                         return;                 }             }             if (update.Type == UpdateType.CallbackQuery)             { \/\/ \u0422\u0443\u0442 \u0438\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0441\u0435\u0445 \u043d\u0430\u0436\u0430\u0442\u0438\u0439 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0438, \u0442\u0443\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043e\u0441\u043e\u0431\u044b\u0445 \u0434\u043e\u043f \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u043d\u0435 \u043d\u0430\u0434\u043e, \u0442\u043a \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u0438 \u0441\u0432\u043e\u044f \u0441\u0441\u044b\u043b\u043a\u0430                 var callbackQuery = update.CallbackQuery;                 var userRole = await DataBaseMethods.GetUserRole(callbackQuery.Message.Chat.Id);                 long userTgId;                 try                 {                     userTgId = Convert.ToInt64(callbackQuery.Data);                 }                 catch                 {                     userTgId = 0;                 }                 var checkUserCallback = await DataBaseMethods.GetUserRole(userTgId); \/\/ \u0442\u0443\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043a \u043c\u0435\u0441\u0442\u043e \u0433\u0434\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \/\/ \u0437\u0434\u0435\u0441\u044c \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043c\u044b \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0438\u0434 \u043f\u043e\u043b\u044c\u0437\u0432\u043e\u0430\u0442\u0435\u043b\u044f \u0432 \u043e\u0442\u0434 \u0431\u0434, \u043e\u0442\u043a\u0443\u0434\u0430 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0435\u043c \u0440\u043b\u0434\u0433\u0440\u0443\u0437\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435               if (checkUserCallback != null)                 {                     if (callbackQuery.Data == checkUserCallback.TgId.ToString() != null &amp;&amp; userRole.Role == \"controller\")                     {                         await DataBaseMethods.DialogCreate(userTgId, callbackQuery.Message.Chat.Id);                         await DataBaseMethods.ToggleInDialogStatus(callbackQuery.Message.Chat.Id, 1, userTgId);                         await botClient.SendTextMessageAsync(                             callbackQuery.Message.Chat.Id,                             text: \"\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044e\",                             replyMarkup: kb.ToMenu);                     }                     if (callbackQuery.Data == checkUserCallback.TgId.ToString() &amp;&amp; userRole.Role == \"driver\")                     {                         await DataBaseMethods.DialogCreate(userTgId, callbackQuery.Message.Chat.Id);                         await DataBaseMethods.ToggleInDialogStatus(callbackQuery.Message.Chat.Id, 1, userTgId);                         await botClient.SendTextMessageAsync(                             callbackQuery.Message.Chat.Id,                             text: \"\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0443\",                             replyMarkup: kb.ToMenu);                     }                 }                 if (callbackQuery.Data == \"menu\")                 {                     await DataBaseMethods.ToggleInDialogStatus(callbackQuery.Message.Chat.Id, 0);                     await botClient.DeleteMessageAsync(                             callbackQuery.Message.Chat.Id,                             callbackQuery.Message.MessageId);                      await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u041c\u0435\u043d\u044e\",                         replyMarkup: kb.Menu);                 }                 if (callbackQuery.Data == \"register\")                 {                     await botClient.SendTextMessageAsync(                             callbackQuery.Message.Chat.Id,                             \"\/reg \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u043e\u0439\u0442\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e\");                  }                 if (callbackQuery.Data == \"profile\")                 {                     await botClient.DeleteMessageAsync(                             callbackQuery.Message.Chat.Id,                             callbackQuery.Message.MessageId);                      var driverData = await DataBaseMethods.GetDriverData(callbackQuery.Message.Chat.Id);                     var tcData = await DataBaseMethods.GetTcData(callbackQuery.Message.Chat.Id);                     if (userRole != null &amp;&amp; driverData != null)                     {                         var name = driverData.Name;                         var route = driverData.IdRoute;                         var vrn = driverData.VehichleRegNum;                         var dsn = driverData.DeviceSerialNum;                         var role = userRole.Role;                         await botClient.SendTextMessageAsync(                             callbackQuery.Message.Chat.Id,                             text: $\"\u0432\u0430\u0448\u0430 \u0434\u043e\u043b\u0436\u043d\u043e\u0441\u0442\u044c: {role}\");                         await botClient.SendTextMessageAsync(                             callbackQuery.Message.Chat.Id,                             text: $\"\u0412\u0430\u0448\u0435 \u0424\u0418\u041e: {name}\" + \"\\n\" +                             $\"\u041c\u0430\u0440\u0448\u0440\u0443\u0442 \u043d\u043e\u043c\u0435\u0440: {route}\" + \"\\n\" +                             $\"\u041d\u043e\u043c\u0435\u0440 \u0442\u0441: {vrn}\" + \"\\n\" +                             $\"\u041d\u043e\u043c\u0435\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430: {dsn}\");                     }                     if (userRole != null &amp;&amp; tcData != null)                     {                         var name = tcData.Name;                         var role = userRole.Role;                         await botClient.SendTextMessageAsync(                             callbackQuery.Message.Chat.Id,                             text: $\"\u0432\u0430\u0448\u0430 \u0434\u043e\u043b\u0436\u043d\u043e\u0441\u0442\u044c: {role}\");                         await botClient.SendTextMessageAsync(                             callbackQuery.Message.Chat.Id,                             text: $\"\u0412\u0430\u0448\u0435 \u0424\u0418\u041e: {name}\");                     }                     else                     {                         await botClient.SendTextMessageAsync(                             callbackQuery.Message.Chat.Id,                             text: \"\u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0436\u043c\u0438\u0442\u0435 \/reg\",                             replyMarkup: kb.Register);                     }                      await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u0425\u043e\u0442\u0438\u0442\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u0432 \u043c\u0435\u043d\u044e?\",                         replyMarkup: kb.ToMenu);                 }                 if (callbackQuery.Data == \"dialogs\")                 {                     var role = userRole.Role;                     if (role == \"controller\")                     {                         await botClient.DeleteMessageAsync(                             callbackQuery.Message.Chat.Id,                             callbackQuery.Message.MessageId);                          var driversList = DataBaseMethods.GetAllDriversId(\"driver\");                          await botClient.SendTextMessageAsync(                             callbackQuery.Message.Chat.Id,                             \"\u0412\u043e\u0434\u0438\u0442\u0435\u043b\u0438:\",                             replyMarkup: kb.TextAll);                          foreach (var driver in driversList)                         {                             var driverName = await DataBaseMethods.GetDriverData(driver);                             InlineKeyboardMarkup driverButton = new(new[]                             {                                     new []                                     {                                         InlineKeyboardButton.WithCallbackData(text: $\"{driver}\", callbackData: $\"{driver}\"),                                     },                                 });                             await botClient.SendTextMessageAsync(                                 callbackQuery.Message.Chat.Id,                                 $\"&lt;code>{driverName.Name}&lt;\/code> \",                                 ParseMode.Html,                                 replyMarkup: driverButton);                         }                     }                     else                     {                         await botClient.DeleteMessageAsync(                             callbackQuery.Message.Chat.Id,                             callbackQuery.Message.MessageId);                          var tcList = DataBaseMethods.GetAllDriversId(\"controller\");                          await botClient.SendTextMessageAsync(                             callbackQuery.Message.Chat.Id,                             \"\u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u044b:\");                          foreach (var tc in tcList)                         {                             var tcName = await DataBaseMethods.GetTcData(tc);                             InlineKeyboardMarkup tcButton = new(new[]                             {                                     new []                                     {                                         InlineKeyboardButton.WithCallbackData(text: $\"{tc}\", callbackData: $\"{tc}\"),                                     },                                 });                             await botClient.SendTextMessageAsync(                                 callbackQuery.Message.Chat.Id,                                 $\"&lt;code>{tcName.Name}&lt;\/code> \",                                 ParseMode.Html,                                 replyMarkup: tcButton);                         }                     }                 }                 if (callbackQuery.Data == \"textall\")                 {                     var allDrivers = DataBaseMethods.GetAllDriversId(\"driver\");                     foreach (long driver in allDrivers)                     {                         await DataBaseMethods.DialogCreate(callbackQuery.Message.Chat.Id, driver);                         await DataBaseMethods.ToggleInDialogStatus(callbackQuery.Message.Chat.Id, 2, driver);                     }                     await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439\",                         replyMarkup: kb.ToMenu);                 }                 if (callbackQuery.Data == \"driver\")                 {                     await botClient.DeleteMessageAsync(                             callbackQuery.Message.Chat.Id,                             callbackQuery.Message.MessageId);                      await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u041d\u0430\u0436\u043c\u0438\u0442\u0435 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445\",                         replyMarkup: kb.StartRegDriver);                      int StageRegDriver = 1;                     await DataBaseMethods.AddOrUpdateUser(                         callbackQuery.Message.Chat.Id,                         callbackQuery.Data.ToString(),                         callbackQuery.From.Username,                         callbackQuery.Message.From.Id,                         StageRegDriver);                      await DataBaseMethods.AddDriver(                         callbackQuery.Message.Chat.Id);                 } \/\/ \u043d\u0430\u0447\u0430\u043b\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0412\u043e\u0434\u0438\u0442\u0435\u043b\u044f                 if (callbackQuery.Data == \"DriverName\")                 {                     await DataBaseMethods.StageIncrement(callbackQuery.Message.Chat.Id, 1);                     await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0424\u0418\u041e:\");                 }                 if (callbackQuery.Data == \"IdRoute\")                 {                     await DataBaseMethods.StageIncrement(callbackQuery.Message.Chat.Id, 2);                     await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043d\u043e\u043c\u0435\u0440 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430:\");                 }                 if (callbackQuery.Data == \"VehichleRegNum\")                 {                     await DataBaseMethods.StageIncrement(callbackQuery.Message.Chat.Id, 3);                     await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043d\u043e\u043c\u0435\u0440 \u0442\u0441:\");                 }                 if (callbackQuery.Data == \"DeviceSerialNum\")                 {                     await DataBaseMethods.StageIncrement(callbackQuery.Message.Chat.Id, 4);                     await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043d\u043e\u043c\u0435\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430:\");                 }                 if (callbackQuery.Data == \"controller\")                 {                     await botClient.DeleteMessageAsync(                             callbackQuery.Message.Chat.Id,                             callbackQuery.Message.MessageId);                      await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u041d\u0430\u0436\u043c\u0438\u0442\u0435 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445\",                         replyMarkup: kb.StartRegTC);                      int StageRegTC = 1;                     await DataBaseMethods.AddOrUpdateUser(                         callbackQuery.Message.Chat.Id,                         callbackQuery.Data.ToString(),                         callbackQuery.From.Username,                         callbackQuery.Message.From.Id,                         StageRegTC);                      await DataBaseMethods.AddTc(                         callbackQuery.Message.Chat.Id);                 } \/\/ \u043d\u0430\u0447\u0430\u043b\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430                 if (callbackQuery.Data == \"TcName\")                 {                     await DataBaseMethods.StageIncrement(callbackQuery.Message.Chat.Id, 1);                     await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0424\u0418\u041e:\");                 }                 if (callbackQuery.Data == \"FinReg\")                 {                     await DataBaseMethods.StageIncrement(callbackQuery.Message.Chat.Id, 5);                     await botClient.SendTextMessageAsync(                         callbackQuery.Message.Chat.Id,                         text: \"\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043e\u043a\u043e\u043d\u0447\u0435\u043d\u0430\",                         replyMarkup: kb.ToMenu);                 } \/\/ \u043e\u0431\u0449\u0435\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438             }         }         public static async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)         {             \/\/ \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f             Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(exception));         }         static void Main(string[] args)         {              Console.WriteLine(\"\u0417\u0430\u043f\u0443\u0449\u0435\u043d \u0431\u043e\u0442 \" + bot.GetMeAsync().Result.FirstName);             var cts = new CancellationTokenSource();             var cancellationToken = cts.Token;             var receiverOptions = new ReceiverOptions             {                 AllowedUpdates = { }, \/\/ receive all update types             };             bot.StartReceiving(                 HandleUpdateAsync,                 HandleErrorAsync,                 receiverOptions,                 cancellationToken             );             Console.ReadLine();                      }     } } <\/code><\/pre>\n<p>\u0412\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0432 \u043a\u043e\u0434\u0435, \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u043a\u0440\u0438\u0442\u0438\u043a\u0430, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434.<\/p>\n<p>\u0412\u0441\u0435\u043c \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0434\u043d\u044f!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/699550\/\"> https:\/\/habr.com\/ru\/articles\/699550\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u0427\u0430\u0441\u0442\u044c 1<\/h2>\n<h2>\u041f\u043e\u0447\u0435\u043c\u0443?<\/h2>\n<p>\u0420\u0435\u0448\u0438\u043b \u044f \u043f\u043e\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u0448\u0430\u0440\u043f\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c EF. \u041f\u043e\u043a\u0430 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b\u0441\u044f \u0437\u0430\u043c\u0435\u0442\u0438\u043b, \u0447\u0442\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u043e\u0432 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u043d\u0430 C# \u043d\u0435\u043c\u043d\u043e\u0433\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c\u0438 \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u043a\u0430\u043c\u0438. <\/p>\n<h2>\u0427\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u043e\u0442:<\/h2>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0431\u043e\u0442\u0430 &#8212; \u0443\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043e\u0431\u043c\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u0438 \u043f\u043e\u0434\u0447\u0438\u043d\u0435\u043d\u043d\u044b\u043c\u0438 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0433\u043b\u0430\u0432\u043d\u044b\u0439(\u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440) \u043c\u043e\u0433 \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435\u043c \u0438\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0447\u0438\u043d\u0435\u043d\u043d\u043e\u043c\u0443(\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044e), \u0430 \u043f\u043e\u0434\u0447\u0438\u043d\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0433\u043b\u0430\u0432\u043d\u044b\u043c. WebHook \u043d\u0435 \u043d\u0443\u0436\u0435\u043d, \u0442.\u043a. \u0431\u043e\u0442 \u0441\u0443\u0433\u0443\u0431\u043e \u0434\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438.<\/p>\n<h2>\u041c\u043e\u0434\u0435\u043b\u044c \u0411\u0414<\/h2>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0448\u0438\u043b \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e \u0438\u0442\u043e\u0433\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c. <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 1:<\/h2>\n<p>\u0414\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b Postgre SQL 15, \u0430 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 PgAdmin 4. \u0421\u043e\u0437\u0434\u0430\u043b \u0431\u0434 Users \u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u043b \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e.<\/p>\n<details class=\"spoiler\">\n<summary>\u0441\u043a\u0430\u0447\u0430\u0442\u044c <\/summary>\n<div class=\"spoiler__content\">\n<p><a href=\"https:\/\/www.enterprisedb.com\/postgresql-tutorial-resources-training?uuid=7ce7e93f-e1eb-4e42-85fa-84c0c98859ee&amp;campaignId=7012J000001h3GiQAI\" rel=\"noopener noreferrer nofollow\">https:\/\/www.enterprisedb.com\/postgresql-tutorial-resources-training?uuid=7ce7e93f-e1eb-4e42-85fa-84c0c98859ee&amp;campaignId=7012J000001h3GiQAI<\/a><\/p>\n<p><a href=\"https:\/\/www.pgadmin.org\/download\/pgadmin-4-windows\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.pgadmin.org\/download\/pgadmin-4-windows\/<\/a><\/p>\n<\/div>\n<\/details>\n<h2>\u0428\u0430\u0433 2:<\/h2>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0432 VS \u0447\u0435\u0440\u0435\u0437 NuGET:<\/p>\n<ul>\n<li>\n<p>Microsoft.EntityFrameworkCore.Tools<\/p>\n<\/li>\n<li>\n<p>Newtonsoft.Json<\/p>\n<\/li>\n<li>\n<p>Npgsql.EntityFrameworkCore.PostgreSQL<\/p>\n<\/li>\n<li>\n<p>Telegram.Bot<\/p>\n<\/li>\n<li>\n<p>Telegram.Bot.Extensions.Polling<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 3:<\/h2>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d <a href=\"https:\/\/telegram.me\/BotFather\" rel=\"noopener noreferrer nofollow\">https:\/\/telegram.me\/BotFather<\/a> \u0438 \u043f\u043b\u0430\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043a\u043e\u0434\u0443.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 4:<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 Program.cs \u0438 \u0432\u043d\u0435\u0441\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u041c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<pre><code class=\"cs\">using Telegram.Bot; using Telegram.Bot.Extensions.Polling; using Telegram.Bot.Types.ReplyMarkups; using CETmsgr.keyboards; using CETmsgr.dbutils; using Update = Telegram.Bot.Types.Update; using Telegram.Bot.Types.Enums;  namespace CETmsgr {     class Program     {         static ITelegramBotClient bot = new TelegramBotClient(\"TOKEN\");         public static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)         {             Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(update));           if (update.Type == UpdateType.Message)           {           \/\/ \u0422\u0443\u0442 \u0431\u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f             \/\/ \u0414\u0430\u043b\u044c\u0448\u0435 \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0441\u0442\u0430\u0440\u0442, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 botfather             \/\/ \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 program.cs \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u044b\u0432\u0435\u0434\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0431\u043e\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d             \/\/ \u0430 \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0431\u043e\u0442 \u043d\u0430\u043f\u0438\u0448\u0435\u0442 \u041f\u0440\u0438\u0432\u0435\u0442             if (message.Text.ToLower() == \"\/start\")                 {                     await DataBaseMethods.ToggleInDialogStatus(update.Message.Chat.Id, 0);                     await botClient.SendTextMessageAsync(                         chatId: message.Chat,                         text: \"\u041f\u0440\u0438\u0432\u0435\u0442\");                      return;           }           if (update.Type == UpdateType.CallbackQuery)           {           \/\/ \u0422\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043d\u0430 inline \u043a\u043d\u043e\u043f\u043a\u0438           }           public static async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)         {             \/\/ \u0414\u0430\u043d\u043d\u044b\u0439 \u0425\u0435\u043d\u0434\u043b\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0438\u0445 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432 \u0432\u0438\u0434\u0435 JSON             Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(exception));         }         static void Main(string[] args)         {              Console.WriteLine(\"\u0417\u0430\u043f\u0443\u0449\u0435\u043d \u0431\u043e\u0442 \" + bot.GetMeAsync().Result.FirstName);             var cts = new CancellationTokenSource();             var cancellationToken = cts.Token;             var receiverOptions = new ReceiverOptions             {                 AllowedUpdates = { }, \/\/ \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u0438\u0434\u044b \u0430\u043f\u0434\u0435\u0439\u0442\u043e\u0432             };             bot.StartReceiving(                 HandleUpdateAsync,                 HandleErrorAsync,                 receiverOptions,                 cancellationToken             );             Console.ReadLine();                      }     } }<\/code><\/pre>\n<h2>\u0428\u0430\u0433 5:<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446, \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0430\u043f\u043a\u0443 dbutils \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u043d\u0443\u0436\u0434.<\/p>\n<p>UserRoles \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e \u0440\u043e\u043b\u044f\u043c.<\/p>\n<p>TrafficControllers \u0438 Drivers \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u044e\u0437\u0435\u0440\u0430\u043c.<\/p>\n<p>DialogMembers \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 id \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u043c\u0435\u0436\u0434\u0443 id 2\u0445 \u044e\u0437\u0435\u0440\u043e\u0432<\/p>\n<p>DialogMsgs \u044d\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 id \u0434\u0438\u0430\u043b\u043e\u0433\u0430 \u0438\u0437 DialogMembers <\/p>\n<p>DialogStatus \u0430 \u0432\u043e\u0442 \u044d\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u044e\u0437\u0435\u0440\u043e\u0432 \u0431\u043e\u0442\u0443. <\/p>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class UserRoles     {         [Key]         public long TgId { get; set; }         public string Role { get; set; }         public string? TgUsername { get; set; }         public long TgChatId { get; set; }         public int StageReg { get; set; }      } }<\/code><\/pre>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class Drivers     {         [Key]         public long IdDriver { get; set; }         public string Name { get; set; }         public string IdRoute { get; set; }         public string VehichleRegNum { get; set; }         public string DeviceSerialNum { get; set; }     } }<\/code><\/pre>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class TrafficControllers     {         [Key]         public long IdTc { get; set; }         public string Name { get; set; }     } }<\/code><\/pre>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class DialogMembers     {         [Key]         public int IdThread { get; set; }         public long IdTc { get; set; }         public long IdDriver { get; set; }     } }<\/code><\/pre>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class DialogMsgs     {         [Key]         public long IdUnique { get; set; }         public int IdThread { get; set; }         public string Created { get; set; }         public string UrgentLevel { get; set; }         public string Message { get; set; }     } }<\/code><\/pre>\n<pre><code class=\"cs\">using System.ComponentModel.DataAnnotations;  namespace CETmsgr.dbutils {     public partial class DialogStatus     {         [Key]         public long TgId { get; set; }         public int Status { get; set; }         public long CurrentDialog { get; set; }      } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0440\u0430 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0431\u0434 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0431\u0434:<\/p>\n<pre><code class=\"cs\">using Microsoft.EntityFrameworkCore;  namespace CETmsgr.dbutils {     public class ApplicationContext : DbContext     {         public DbSet&lt;UserRoles> UserRoles { get; set; }         public DbSet&lt;Drivers> Drivers { get; set; }         public DbSet&lt;TrafficControllers> TrafficControllers { get; set; }         public DbSet&lt;DialogMsgs> DialogMsgs { get; set; }         public DbSet&lt;DialogMembers> DialogMembers { get; set; }         public DbSet&lt;DialogStatus> DialogStatus { get; set; }          protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)         {             optionsBuilder.UseNpgsql(                 \"Host=localhost;\" +                 \"Port=5433;\" +                 \"Database=Users;\" +                 \"Username=postgres;\" +                 \"Password=zaqwsxzaq\");         }     } }      <\/code><\/pre>\n<p>\u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e:<\/p>\n<p>\u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0432\u0432\u043e\u0434\u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code>enable-migrations<\/code><\/pre>\n<pre><code>Add-migration *\u0418\u043c\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438*<\/code><\/pre>\n<pre><code>update-database<\/code><\/pre>\n<p>\u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<h2>\u0428\u0430\u0433 6:<\/h2>\n<p>\u0418\u0442\u0430\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c. \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0440\u0430\u043d\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0430\u043f\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b DataBaseMethods.cs. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u043e\u0439 \u0431\u043e\u0442 \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432 \u044f \u0432\u044b\u043b\u043e\u0436\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u0434\u0430\u0431\u044b \u043d\u0435 \u0437\u0430\u043f\u0443\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0430\u0441 \u0440\u0430\u0437\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<pre><code class=\"cs\">using Microsoft.EntityFrameworkCore; using System.Data;  namespace CETmsgr.dbutils {     internal class DataBaseMethods     {         \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c. \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043d\u0435 \u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0438\u0437\u043b\u0438\u0448\u043d\u0438\u043c\u0438, \u043d\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u0438\u0445 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043a \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442         public static async Task&lt;long> MsgCreateByDriverToTc(int IdThread, string Msg, string Crtd, string UL)         {             using (ApplicationContext db = new ApplicationContext())             {                 DialogMsgs newMSG = new DialogMsgs { IdThread = IdThread, Created = Crtd, UrgentLevel = UL, Message = Msg };                 await db.DialogMsgs.AddAsync(newMSG);                 await db.SaveChangesAsync();                 try                 {                     var getMSG = await db.DialogMsgs.OrderBy(x => x.Created).LastOrDefaultAsync(x => x.IdThread == IdThread);                     return getMSG.IdUnique;                 }                 catch(Exception ex)                 {                     return 123123;                 }                              }         }         \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u043e\u043c         public static async Task&lt;long> MsgCreateByTcToDriver(int IdThread, string Msg, string Crtd, string UL)         {             using (ApplicationContext db = new ApplicationContext())             {                 DialogMsgs newMSG = new DialogMsgs { IdThread = IdThread, Created = Crtd, UrgentLevel = UL, Message = Msg };                 await db.DialogMsgs.AddAsync(newMSG);                 await db.SaveChangesAsync();                 try                 {                     var getMSG = await db.DialogMsgs.OrderBy(x => x.IdUnique).LastOrDefaultAsync(x => x.IdThread == IdThread);                     return getMSG.IdUnique;                 }                 catch (Exception ex)                 {                     return 123123;                 }              }         }         \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u043e\u043c         public static async Task&lt;long> MsgRecievierTc(long IdUnique, int IdThread, long IdDriver)         {             using (ApplicationContext db = new ApplicationContext())             {                 var getMSG = await db.DialogMsgs.FirstOrDefaultAsync(x => x.IdUnique == IdUnique);                 var getId = await db.DialogMembers.FirstOrDefaultAsync(x => (x.IdThread == IdThread &amp;&amp; x.IdDriver == IdDriver));                 if (getMSG.IdThread == getId.IdThread)                 {                     return getId.IdTc;                 }          <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-389199","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/389199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=389199"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/389199\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=389199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=389199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=389199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}