private async void Try_Login() { if (CheckConnectionToServer()) { BackendConnect.Post_message_class data = new BackendConnect.Post_message_class() { Username = text_username.Text, Password = text_password.Password }; string request = BackendConnect.server + "auth/login"; var content = await Backend.Post(data, request); if (content != null) { if (content[0].Id != null) { var user_id = content[0].Id; Properties.Settings.Default.id = Int32.Parse(user_id); Properties.Settings.Default.Save(); mainWindow.LoggedIn(); mainWindow.Show(); dontclose = false; this.Close(); } else { login_error.Text = "Username or Password is wrong"; } } else { login_error.Text = "Username or Password is wrong"; } } }
private async void Try_Register() { if (CheckConnectionToServer()) { var Username = text_username.Text; var Password = text_password.Password; if (Username == "" || Password == "") { login_error.Text = "Please fill out both fields"; return; } if (Password.Length < 6) { login_error.Text = "Please Make your password more than 6 characters"; return; } BackendConnect.Post_message_class data = new BackendConnect.Post_message_class() { Username = Username, Password = Password }; string request = BackendConnect.server + "auth/Register"; var content = await Backend.Post(data, request); if (content != null) { if (content[0].Id != null) { var user_id = content[0].Id; Properties.Settings.Default.id = Int32.Parse(user_id); Properties.Settings.Default.Save(); mainWindow.LoggedIn(); mainWindow.Show(); dontclose = false; this.Close(); } else { login_error.Text = "Username or Password is wrong"; } } else { login_error.Text = "Username or Password is wrong"; } } }
/// <summary> /// The Message_Click /// </summary> /// <param name="sender">The sender<see cref="object"/></param> /// <param name="e">The e<see cref="RoutedEventArgs"/></param> internal async void Message_Click(object sender, RoutedEventArgs e) { Button b = (Button)sender; BackendConnect.Post_message_class data = new BackendConnect.Post_message_class() { Chat_id = current_User.Chat_id, User_id = current_User.User_id, Message_id = Int32.Parse(b.Tag.ToString()), }; String request = BackendConnect.server + "delete"; await Task.Run(async() => await Backend.Post(data, request)); Chat_ListBox.Items.Clear(); current_User.Lastest_message = 0; GetMessages(); }
private async void create_chat(object sender, RoutedEventArgs e) { var User_id = Properties.Settings.Default.id; DateTime time = DateTime.UtcNow; BackendConnect.Post_message_class data = new BackendConnect.Post_message_class() { User_id = User_id, Chat_name = NameChat.Text, }; String request = BackendConnect.server + "new/chat"; await Task.Run(async() => await Backend.Post(data, request)); this.Close(); mainWindow.GetChats(User_id); }
internal async void Add_User_action(object sender, RoutedEventArgs e) { Button b = (Button)sender; Console.WriteLine(Chat_id); Console.WriteLine(b.Tag); BackendConnect.Post_message_class data = new BackendConnect.Post_message_class() { Chat_id = Chat_id, User_id = Int32.Parse(b.Tag.ToString()), }; String request = BackendConnect.server + "chat/user/add"; await Task.Run(async() => await Backend.Post(data, request)); ///Chat_ListBox.Items.Clear(); ///current_User.Lastest_message = 0; ///GetMessages(); }
/// <summary> /// The ImagePanel_Drop /// </summary> /// <param name="sender">The sender<see cref="object"/></param> /// <param name="e">The e<see cref="DragEventArgs"/></param> private async void ImagePanel_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { if (current_User.Chat_id != 0) { DateTime time = DateTime.UtcNow; BackendConnect.Post_message_class data = new BackendConnect.Post_message_class() { Chat_id = current_User.Chat_id, User_id = current_User.User_id, Current_time = ((DateTimeOffset)time).ToUnixTimeSeconds(), }; string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); for (int i = 0; i < files.Length; i++) { await Task.Run(async() => await Backend.UploadFile(data, files[i])); } } } }
/// <summary> /// The SendMessage /// </summary> public async void SendMessage() { if (current_User.Chat_id != 0) { DateTime time = DateTime.UtcNow; BackendConnect.Post_message_class data = new BackendConnect.Post_message_class() { Chat_id = current_User.Chat_id, User_id = current_User.User_id, Message = Message_TextBox.Text, Current_time = ((DateTimeOffset)time).ToUnixTimeSeconds() }; String request = BackendConnect.server + "message"; //var post = await Backend.Post(data, request); await Task.Run(async() => await Backend.Post(data, request)); Message_TextBox.Text = String.Empty; GetMessages(); Scroll(); } ; }