189 lines
5.7 KiB
C#
189 lines
5.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using Valheim_Mod_Sync_Desktop.ViewModels;
|
|
|
|
namespace Valheim_Mod_Sync_Desktop.Views
|
|
{
|
|
/// <summary>
|
|
/// Interaktionslogik für BugSuggestion.xaml
|
|
/// </summary>
|
|
public partial class Kontakt : UserControl
|
|
{
|
|
public Kontakt()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
|
|
private async void Send_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var Betreff = "";
|
|
if (Bug.IsChecked == true)
|
|
{
|
|
Betreff = "Fehler";
|
|
}else
|
|
{
|
|
Betreff = "Vorschlag";
|
|
}
|
|
|
|
bool name = false;
|
|
bool email = false;
|
|
bool message = false;
|
|
bool send = false;
|
|
bool keininternet = false;
|
|
bool error = false;
|
|
|
|
if (Name.Text == "")
|
|
{
|
|
name = true;
|
|
}
|
|
|
|
if (Email.Text == "" | !Email.Text.Contains('@') | !Email.Text.Contains('.'))
|
|
{
|
|
email = true;
|
|
}
|
|
|
|
if (Message.Text == "")
|
|
{
|
|
message = true;
|
|
}
|
|
|
|
if (!SyncControl.IsConnectionAvailable())
|
|
|
|
{
|
|
keininternet = true;
|
|
|
|
var mailcomplete = new MailComplete
|
|
{
|
|
Name = Name.Text,
|
|
Email = Email.Text,
|
|
Betreff = Betreff,
|
|
Message = Message.Text
|
|
};
|
|
|
|
string fileName = "Message.json";
|
|
string jsonString = JsonSerializer.Serialize(mailcomplete);
|
|
File.WriteAllText(fileName, jsonString);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (Name.Text != "" && Email.Text != "" && Email.Text.Contains('@') && Email.Text.Contains('.') && Message.Text != "" && !keininternet)
|
|
{
|
|
send = true;
|
|
}
|
|
|
|
|
|
if (send)
|
|
{
|
|
|
|
var values = new Dictionary<string, string>
|
|
{
|
|
{ "Betreff", "VMS : "+ Betreff},
|
|
{ "Message", Message.Text },
|
|
{ "Name", Name.Text },
|
|
{ "Email", Email.Text }
|
|
};
|
|
try {
|
|
|
|
HttpClient client = new HttpClient();
|
|
//var content = new FormUrlEncodedContent(values);
|
|
|
|
var jsonDictionary = JsonSerializer.Serialize(values);
|
|
var content = new StringContent(jsonDictionary, Encoding.UTF8, "application/json");
|
|
var response = await client.PostAsync("https://vms.tbs-server.de/", content);
|
|
|
|
var responseString = await response.Content.ReadAsStringAsync();
|
|
Debug.WriteLine(responseString);
|
|
}catch
|
|
{
|
|
error = true;
|
|
var mailcomplete = new MailComplete
|
|
{
|
|
Name = Name.Text,
|
|
Email = Email.Text,
|
|
Betreff = Betreff,
|
|
Message = Message.Text
|
|
};
|
|
|
|
string fileName = "Message.json";
|
|
string jsonString = JsonSerializer.Serialize(mailcomplete);
|
|
File.WriteAllText(fileName, jsonString);
|
|
}
|
|
}
|
|
|
|
if (name | email | message | send | keininternet | error )
|
|
{
|
|
//DataContext = new MainViewModel();
|
|
//MainWindow mainWindow = new MainWindow();
|
|
//mainWindow.contentControl.Content = new SyncControl();
|
|
|
|
|
|
Benachrichtigung modalWindow = new Benachrichtigung(name, email, message, send, keininternet, error, false, false);
|
|
modalWindow.ShowDialog();
|
|
}
|
|
}
|
|
|
|
public static async Task MessageSend()
|
|
{
|
|
bool error = false;
|
|
|
|
string fileName = "Message.json";
|
|
MailComplete mail_read = JsonSerializer.Deserialize<MailComplete>(File.ReadAllText(fileName));
|
|
|
|
|
|
var values = new Dictionary<string, string>
|
|
{
|
|
{ "Betreff", "VMS : "+ mail_read.Betreff},
|
|
{ "Message", mail_read.Message},
|
|
{ "Name", mail_read.Name},
|
|
{ "Email", mail_read.Email}
|
|
};
|
|
|
|
try {
|
|
|
|
HttpClient client = new HttpClient();
|
|
//var content = new FormUrlEncodedContent(values);
|
|
var jsonDictionary = JsonSerializer.Serialize(values);
|
|
var content = new StringContent(jsonDictionary, Encoding.UTF8, "application/json");
|
|
|
|
var response = await client.PostAsync("https://vms.tbs-server.de/", content);
|
|
|
|
var responseString = await response.Content.ReadAsStringAsync();
|
|
|
|
}catch
|
|
{
|
|
error = true;
|
|
}
|
|
|
|
bool send = false;
|
|
|
|
if (!error)
|
|
{
|
|
send = true;
|
|
File.Delete("Message.json");
|
|
}
|
|
|
|
Benachrichtigung modalWindow = new Benachrichtigung(false, false, false, send, false, error, false, false);
|
|
modalWindow.ShowDialog();
|
|
|
|
}
|
|
|
|
public class MailComplete
|
|
{
|
|
public string Name { get; set; }
|
|
public string Email { get; set; }
|
|
public string Betreff { get; set; }
|
|
public string Message { get; set; }
|
|
}
|
|
}
|
|
}
|