Enter hinzugefügt

Enter in Chatleiste hinzugefügt und Button entfernt
This commit is contained in:
BlackViron 2024-06-10 16:49:14 +02:00
parent 696e4eeb03
commit 5197504128
2 changed files with 54 additions and 52 deletions

View File

@ -112,8 +112,7 @@
Margin="244,642,154,10" Margin="244,642,154,10"
Background="#FF323134" Background="#FF323134"
Foreground="White" Foreground="White"
SelectionBrush="#FF6332A0"/> SelectionBrush="#FF6332A0" KeyDown="messageBOX_KeyDown"/>
<Button x:Name="weiterbutton" Click="send_Click" Content="Weiter" Foreground="White" Background="#FF6332A0" BorderThickness="0" Margin="831,642,44,10" BorderBrush="{x:Null}" Style="{StaticResource NoHoverButtonStyle}" RenderTransformOrigin="0.279,0.633"/>
</Grid> </Grid>

View File

@ -82,32 +82,6 @@ namespace bib_talk
} }
} }
} }
private async void send_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(messageBOX.Text))
{
var message = new MessageDto
{
Username = loggedinUser,
Message = messageBOX.Text,
Timestamp = DateTime.Now,
};
using (var client = new HttpClient())
{
var json = JsonConvert.SerializeObject(message);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("http://daddypig.dns.navy:5114/api/messages/send", content);
if (response.IsSuccessStatusCode)
{
messageBOX.Clear();
LoadMessages(); // Reload messages after sending
}
}
}
}
private async void LogoutUser() private async void LogoutUser()
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
@ -120,7 +94,7 @@ namespace bib_talk
var responseContent = await response.Content.ReadAsStringAsync(); var responseContent = await response.Content.ReadAsStringAsync();
this.Close(); this.Close();
} }
} }
private async void LoadOnlineUsers() private async void LoadOnlineUsers()
@ -136,31 +110,60 @@ namespace bib_talk
} }
} }
} }
}
public class Message private async void messageBOX_KeyDown(object sender, KeyEventArgs e)
{ {
public int Id { get; set; } if (e.Key == Key.Enter)
public string Username { get; set; } {
public string Text { get; set; } if (!string.IsNullOrEmpty(messageBOX.Text))
public DateTime Timestamp { get; set; } {
} var message = new MessageDto
{
Username = loggedinUser,
Message = messageBOX.Text,
Timestamp = DateTime.Now,
};
public class MessageDto using (var client = new HttpClient())
{ {
public string Username { get; set; } var json = JsonConvert.SerializeObject(message);
public string Message { get; set; } var content = new StringContent(json, Encoding.UTF8, "application/json");
public DateTime Timestamp { get; set; } var response = await client.PostAsync("http://daddypig.dns.navy:5114/api/messages/send", content);
}
public class User if (response.IsSuccessStatusCode)
{ {
public int Id { get; set; } messageBOX.Clear();
public string Username { get; set; } LoadMessages(); // Reload messages after sending
public string Password { get; set; } }
public string Email { get; set; } }
public string Birthday { get; set; } }
public string IsOnline { get; set; } }
} }
public class Message
{
public int Id { get; set; }
public string Username { get; set; }
public string Text { get; set; }
public DateTime Timestamp { get; set; }
}
public class MessageDto
{
public string Username { get; set; }
public string Message { get; set; }
public DateTime Timestamp { get; set; }
}
public class User
{
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string Birthday { get; set; }
public string IsOnline { get; set; }
}
}
} }