Beispiel #1
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            SendUser.Auto       = Auto.Text;
            SendUser.AutoNumber = GosNum.Text;
            SendUser.Email      = Email.Text;
            SendUser.FIO        = FIO.Text;
            SendUser.RoleId     = Role.SelectedIndex;
            string site = "http://localhost:11821/";

            try
            {
                var request = (HttpWebRequest)WebRequest.Create(site + "api/Admin/EditUser");
                request.ContentType = "application/json";
                request.Headers.Add("Authorization: Bearer " + Parent.GetToken());
                request.Method = "POST";

                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    string json = JsonConvert.SerializeObject(SendUser);
                    streamWriter.Write(json);
                }

                var httpResponse = (HttpWebResponse)request.GetResponse();
            }catch { }

            Parent.UpdateGrid();
            this.Close();
        }
Beispiel #2
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            UserModel newUser = new UserModel
            {
                Phone      = Phone.Text,
                FIO        = FIO.Text,
                Auto       = Auto.Text,
                AutoNumber = GosNum.Text,
                Email      = Email.Text,
                Password   = Password.Text
            };

            string site = "http://localhost:11821/";

            try
            {
                var request = (HttpWebRequest)WebRequest.Create(site + "api/Admin/NewUser");
                request.ContentType = "application/json";
                request.Headers.Add("Authorization: Bearer " + Parent.GetToken());
                request.Method = "POST";

                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    string json = JsonConvert.SerializeObject(newUser);
                    streamWriter.Write(json);
                }

                var httpResponse = (HttpWebResponse)request.GetResponse();
            }
            catch { }

            Parent.UpdateGrid();
            this.Close();
        }