private void submit_btn(object sender, RoutedEventArgs e) { var user = new ABusers(); try { //check for user inpu........ if (user.check(UserName_T.Text, FirstName_T.Text, LastName_T.Text, Email_txt.Text, Password_T.Text, company_txt.Text, phone_txt.Text) == 1) { // End check for user inpu........ //set user input to object.......... user.setAll(UserName_T.Text, FirstName_T.Text, LastName_T.Text, Email_txt.Text, Password_T.Text, company_txt.Text, phone_txt.Text); //End setting user input to object.......... MessageBox.Show(user.Username + user.FirstName + user.LastName + user.Pass + user.Phone + user.AB_iD + user.Company); // Add New User..... user.Picture = getImageArraybyte(bm); user.adduser(user); //End Adding New User..... } } catch (Exception ex) { MessageBox.Show("some thing happend please try to fill your info again"); } }
//check for user input.................. public int check(string username, string firstname, string lastname, string Email, string pass, string company, string phone) { var user = new ABusers(); if (firstname == "" || lastname == "" || username == "" || pass == "" || Email == "" || phone == "" || company == "") { MessageBox.Show("Some information are missing ,please fill the form completely", "Information Message"); return(0); } if (firstname.Any(c => char.IsNumber(c))) { MessageBox.Show("Please enter your firstname in letters,numbers ae not allowed ", "Adminstrator Message"); return(0); } if (lastname.Any(c => char.IsNumber(c))) { MessageBox.Show("Please enter your lastname in letters,numbers ae not allowed ", "Adminstrator Message"); return(0); } if (pass.Length < 8) { MessageBox.Show("Password is at least 8 characters ", "Adminstrator Message"); return(0); } if (phone.Any(c => char.IsLetter(c)) && phone.Length < 11) { MessageBox.Show("Phone is only numeric digits and must be at least 11 number ", "Adminstrator Message"); return(0); } var email = new EmailAddressAttribute(); bool check = email.IsValid(Email); if (!check) { MessageBox.Show("Not the desired format of email ,please enter your email as the format shown beside email textbox", "Adminstrator Message"); return(0); } else { return(1); } }
//End check for user input.................. public void adduser(ABusers obj) { try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:62135/"); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var response = client.PostAsJsonAsync("api/journal", obj).Result; if (response.IsSuccessStatusCode) { MessageBox.Show("New User has been added Sucessfully"); } else { MessageBox.Show(response.StatusCode + " With Message " + response.ReasonPhrase + "User Name IS Already exist"); } } catch (Exception ex) { MessageBox.Show("some thing wrong had happend"); } }
private void update_btn(object sender, RoutedEventArgs e) { if (id_txt.Text == "" || password_txt.Text == "" || phone_txt.Text == "" || first_txt.Text == "" || last_txt.Text == "" || email_txt.Text == "" || username_txt.Text == "") { MessageBox.Show("There are some missing content"); } var email = new EmailAddressAttribute(); bool check = email.IsValid(email_txt.Text); if (!check) { MessageBox.Show("Not the desired format of email ,please enter your email as the format shown beside email textbox", "Adminstrator Message"); } else { try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:62135/"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var user = new ABusers(); user.Username = username_txt.Text; byte[] data = UTF8Encoding.UTF8.GetBytes(password_txt.Text); user.Pass = Convert.ToBase64String(data).ToString(); user.Email = email_txt.Text; user.FirstName = first_txt.Text; user.LastName = last_txt.Text; user.Company = company_txt.Text; user.Phone = phone_txt.Text; user.Picture = getImageArraybyte(bm); var id = id_txt.Text.Trim(); var url = "api/journal/" + id; var response = client.PutAsJsonAsync(url, user).Result; /*if (string.IsNullOrWhiteSpace(this.textBox.Text) && string.IsNullOrWhiteSpace(this.textBox1.Text) * && string.IsNullOrWhiteSpace(this.textBox6.Text) * && string.IsNullOrWhiteSpace(this.textBox4.Text)) * { * MessageBox.Show("Those cannot be left blank!"); * }*/ if (response.IsSuccessStatusCode) { MessageBox.Show("User has been updated successfully"); clear(); // RetrieveData(); } } catch (Exception ex) { MessageBox.Show("Please run the API project first \n" + "Exception Message : " + ex.Message); } } }
private void adduser_btn(object sender, RoutedEventArgs e) { try { var user = new ABusers(); if (firstname_txt.Text == "" || lastname_txt.Text == "" || password_txt.Text == "" || email_txt.Text == "" || phone_txt.Text == "" || company_txt.Text == "" || combobox.Text == "" || imagetext.Text == "") { MessageBox.Show("Some information are missing ,please fill the form completely", "Information Message"); } if (firstname_txt.Text.Any(c => char.IsNumber(c))) { MessageBox.Show("Please enter your firstname in letters,numbers ae not allowed ", "Adminstrator Message"); firstname_txt.Focus(); } if (lastname_txt.Text.Any(c => char.IsNumber(c))) { MessageBox.Show("Please enter your lastname in letters,numbers ae not allowed ", "Adminstrator Message"); firstname_txt.Focus(); } if (password_txt.Text.Length < 8) { MessageBox.Show("Password is at least 8 characters ", "Adminstrator Message"); password_txt.Focus(); } if (phone_txt.Text.Any(c => char.IsLetter(c)) && phone_txt.Text.Length < 11) { MessageBox.Show("Phone is only numeric digits and must be at least 11 number ", "Adminstrator Message"); password_txt.Focus(); } var email = new EmailAddressAttribute(); bool check = email.IsValid(email_txt.Text); if (!check) { MessageBox.Show("Not the desired format of email ,please enter your email as the format shown beside email textbox", "Adminstrator Message"); } else { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:62135/"); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); user.FirstName = firstname_txt.Text; user.LastName = lastname_txt.Text; user.Username = username_txt.Text; byte[] data = UTF8Encoding.UTF8.GetBytes(password_txt.Text); user.Pass = Convert.ToBase64String(data).ToString(); user.Email = email_txt.Text; user.Phone = phone_txt.Text; user.Company = company_txt.Text; user.Type_user = combobox.Text; user.Picture = getImageArraybyte(bm); var response = client.PostAsJsonAsync("api/journal", user).Result; if (response.IsSuccessStatusCode) { MessageBox.Show("New User has been added Sucessfully"); clearTexts(); retrieveData(); } else { MessageBox.Show(response.StatusCode + " With Message " + response.ReasonPhrase); } } } catch (Exception ex) { MessageBox.Show("Username is already exist"); } }