Exemplo n.º 1
0
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            AdminLoginForm adminLoginForm = new AdminLoginForm();

            adminLoginForm.Show();
            this.Hide();
        }
        private async void btnCreate_Click(object sender, EventArgs e)
        {
            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync("https://localhost:44332/api/Users"))
                {
                    var apiResponse = await response.Content.ReadAsStringAsync();

                    //var result = JsonConvert.DeserializeObject(apiResponse);
                    List <Users> users  = JsonConvert.DeserializeObject <List <Users> >(apiResponse);
                    var          result = users.Where(u => u.Email == txtEmail.Text).ToList();
                    if (result.Count == 0)
                    {
                        MessageBox.Show("Mail Hatalı");
                    }
                    else
                    {
                        Users user = new Users();
                        foreach (var item in users)
                        {
                            user.UserId     = Convert.ToInt32(item.UserId);
                            user.FirstName  = item.FirstName;
                            user.LastName   = item.LastName;
                            user.UserName   = item.UserName;
                            user.Addres     = item.Addres;
                            user.RoleId     = Convert.ToInt32(item.RoleId);
                            user.DistrictId = Convert.ToInt32(item.DistrictId);
                        }
                        user.UserPassword = txtPassword.Text;
                        user.Email        = txtEmail.Text;

                        var convertModel = JsonConvert.SerializeObject(user);
                        var content      = new StringContent(convertModel, Encoding.UTF8, "application/json");
                        httpClient.DefaultRequestHeaders.Add("Accept", "application/json");


                        var resp = await httpClient.PutAsync("https://localhost:44332/api/Users", content);

                        AdminLoginForm adminLoginForm = new AdminLoginForm();
                        adminLoginForm.Show();
                        this.Hide();
                    }
                }
            }
        }