private void LoginButton_Click(object sender, EventArgs e) { string userName = textBoxUserName.Text; string password = sha256(textBoxPassword.Text); try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://localhost:56028/api/users/Login/" + userName + "/" + password); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { string content = new StreamReader(response.GetResponseStream()).ReadToEnd(); user = JsonConvert.DeserializeObject <User>(content); } MessageBox.Show(user.UserName); textBoxUserName.Text = string.Empty; textBoxPassword.Text = string.Empty; checkState(); ip = GetLocalIPAddress(); user.UserIP = ip; UserRequsts.UpdateUser(user); } catch (Exception) { MessageBox.Show("the user is not exists"); } }
private void buttonUpdate_Click(object sender, EventArgs e) { user = new User() { UserEmail = textBoxEmailEdit.Text, UserName = textBoxUserNameEdit.Text, TeamLeaderId = (int)comboBoxTeamLeaderEdit.SelectedValue, UserKindId = (int)comboBoxUserKindEdit.SelectedValue }; user.UserId = (int)comboBoxAllUsers.SelectedValue; var validationContext = new ValidationContext(user, null, null); var results = new List <ValidationResult>(); if (Validator.TryValidateObject(user, validationContext, results, true)) { if (UserRequsts.UpdateUser(user)) { MessageBox.Show("update success"); } else { MessageBox.Show("update filed"); } } else { MessageBox.Show(string.Join(",\n", results.Select(p => p.ErrorMessage))); } }