public async Task <ActionResult <MOD_UserTable> > PostUserTable([FromBody] MOD_UserTable usr) { _context.usr_user.Add(usr); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUserTable", new { id = usr.id_usr }, usr)); }
/// <summary> /// Método que hace el POST para crear un nuevo usuario en la tabla usr_user. /// </summary> /// <param name="NewUser">Instancia de la clase MOD_UserTable</param> /// <returns></returns> public static string AddNewUser(MOD_UserTable NewUser) { string Response = string.Empty; string json = Newtonsoft.Json.JsonConvert.SerializeObject(NewUser); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url_UserTable); request.Method = "POST"; if (json != string.Empty) { request.ContentType = "application/json;charset=utf-8"; using (StreamWriter swJSONPayload = new StreamWriter(request.GetRequestStream())) { swJSONPayload.Write(json); swJSONPayload.Close(); } } HttpWebResponse response = null; try { response = (HttpWebResponse)request.GetResponse(); using (Stream responseStream = response.GetResponseStream()) { if (responseStream != null) { using (StreamReader reader = new StreamReader(responseStream)) { Response = reader.ReadToEnd(); } } } } catch (Exception ex) { Response = ex.Message.ToString(); } finally { if (response != null) { ((IDisposable)response).Dispose(); } } return(Response); }
public void AddNewUser() { MOD_UserTable NewUser = new MOD_UserTable() { first_names_usr = mtb_names.Text, last_names_usr = mtb_lastname.Text, phone_usr = mtb_phone.Text, address_usr = mtb_address.Text, city_usr = Convert.ToInt32(cmb_cities.SelectedValue) }; var r = BLL_UserRegistration.AddNewUser(NewUser); MessageBox.Show(r); Clean(); LoadDefaultSettings(); }