private void Button_Click(object sender, RoutedEventArgs e) { ChatModelAdd chatModel = new ChatModelAdd() { Name = NameChat.Text, idUsers = idUsers }; HttpWebRequest myRequest = WebRequest.CreateHttp($"https://localhost:44359/api/message/PostChat"); myRequest.Method = "POST"; myRequest.ContentType = "application/json"; using (StreamWriter writer = new StreamWriter(myRequest.GetRequestStream())) { writer.Write(JsonConvert.SerializeObject(chatModel)); } WebResponse wr = myRequest.GetResponse(); }
public IActionResult PostChat([FromBody] ChatModelAdd model) { var chat = new Chat() { Name = model.Name }; _context.Chats.Add(chat); foreach (var item in model.idUsers) { var chatUser = new ChatUser() { IdChat = chat.Id, IdUser = item }; _context.ChatUsers.Add(chatUser); } _context.SaveChanges(); return(Ok()); }