示例#1
0
        private async void Create()
        {
            if (Command["objectName"] != string.Empty)
            {
                ChatControl    chatControl    = new ChatControl(ChatsControl);
                MainWindow     mainWindow     = new MainWindow();
                SignalRManager signalRManager = new SignalRManager();
                string         chatName       = Command["objectName"];
                string         userName       = User.Name;

                bool isChatExists = Convert.ToBoolean(await ApiManager.Read($"api/chat/isChatExists/{chatName}"));
                if (!isChatExists)
                {
                    await ApiManager.Create("api/chat/create", $"{{'Name':'{chatName}', 'Creator':'{userName}'}}");

                    await ApiManager.Create("api/chat/user", $"{{ 'Chat':{{'Name':'{chatName}'}}, 'User':{{'Name':'{userName}'}} }}");

                    chatControl.AddTabItem(chatName);
                    mainWindow.UpdateUsersBox();

                    signalRManager.AddUserToChat(chatName, userName);
                }
                else
                {
                    MessageBox.Show("Чат с таким названием уже существует.");
                }
            }
            else
            {
                MessageBox.Show("Некорректное имя.");
            }
        }
示例#2
0
        private async void LoadPreviouslyOpenedChatsItems()
        {
            ChatControl   chatControl = new ChatControl(ChatsControl);
            List <string> chatsNames  = new List <string>();

            string chatsJson = await ApiManager.Read($"api/chat/getChats/{User.Name}");

            chatsNames = GetListValuesFromJson(chatsJson, "name");

            foreach (string chatName in chatsNames)
            {
                chatControl.AddTabItem(chatName);
                await UpdateUsersBox();
            }
        }