public void LoadMessages(AccountSet Client) { this.Client = Client; ForumContainer container = new ForumContainer(); // Где мы получатели foreach (var converstation in container.ConversationSet.Where(x => x.RecipientId == Client.AccountId).ToList()) { void handlerClickerChat(object sender, EventArgs args) { MessageSendForm messageForm = new MessageSendForm(Client, converstation.AccountSet_Sender); messageForm.Show(); }; Chat.Chat newChat = new Chat.Chat(converstation.AccountSet_Sender.Login, handlerClickerChat); pmFlowLoyoutPanel.Controls.Add(newChat); } // Где мы отправители foreach (var converstation in container.ConversationSet.Where(x => x.SenderId == Client.AccountId).ToList()) { void handlerClickerChat(object sender, EventArgs args) { MessageSendForm messageForm = new MessageSendForm(Client, converstation.AccountSet_Recipient); messageForm.Show(); }; Chat.Chat newChat = new Chat.Chat(converstation.AccountSet_Recipient.Login, handlerClickerChat); pmFlowLoyoutPanel.Controls.Add(newChat); } }
private void SendMessageButton_Click(object sender, EventArgs e) { if (selectedUser == null) { MessageBox.Show("Вы не выбрали получателя"); return; } ForumContainer Scontainer = new ForumContainer(); var converstation = new ConversationSet() { SenderId = Client.AccountId, RecipientId = selectedUser.AccountId, AccountSet_Recipient = Scontainer.AccountSet.SingleOrDefault(x => x.AccountId == selectedUser.AccountId), AccountSet_Sender = Scontainer.AccountSet.SingleOrDefault(x => x.AccountId == Client.AccountId) }; void handlerClickerChat(object SenderK, EventArgs args) { MessageSendForm messageForm = new MessageSendForm(Client, converstation.AccountSet_Recipient); messageForm.Show(); }; Scontainer.ConversationSet.Add(converstation); Scontainer.SaveChanges(); Chat.Chat newChat = new Chat.Chat(converstation.AccountSet_Recipient.Login, handlerClickerChat); // с кем беседа pmFlowLoyoutPanel.Controls.Add(newChat); if (Message.Text != string.Empty || Message.Text.Length < 5) { MessageSet message = new MessageSet() { Date = DateTime.Now, MessageText = Message.Text, ConversationId = converstation.ConversationId, SenderId = Client.AccountId }; Scontainer.MessageSet.Add(message); Scontainer.SaveChanges(); Message.Text = ""; // this code post query in server and get await } else { MessageBox.Show("Вы не ввели сообщение, либо оно слишком короткое!"); return; } Close(); }