/// <summary> /// Metodo que sirve devolver los datos del usuario /// </summary> /// <param name="urlBase"> Objeto para pasarle la url del servicio</param> /// <param name="solicitud">Objeto con los datos del usuario</param> /// <returns></returns> public async Task <InfoUserResponse> GetInfoUser( string urlBase, SolicitudInfoUser solicitud) { try { var Client = new HttpClient(); string url = urlBase; var data = JsonConvert.SerializeObject(solicitud); var content = new StringContent(data, Encoding.UTF8, "application/json"); var response = await Client.PostAsync(url, content); if (response.IsSuccessStatusCode) { var json = await response.Content.ReadAsStringAsync(); if (json.Substring(0, 5) != "Error") { var resultado = (InfoUserResponse)JsonConvert.DeserializeObject(json, typeof(InfoUserResponse)); return(resultado); } } return(null); } catch { return(null); } }
public void CallServiceGet() { bool success = false; string msg = ""; try { Device.BeginInvokeOnMainThread(() => UserDialogs.Instance.ShowLoading("Obteniendo datos...", MaskType.Black)); Task.Run(async() => { solicitudinfo = new SolicitudInfoUser(); solicitudinfo.id = Idusuario; solicitudinfo.rol = TipoUsuario; var res = await this.apiService.GetInfoUser( "http://www.creativasoftlineapps.com/ScriptAppTuxmandados/frmACUsuario.aspx", solicitudinfo); if (res != null) { success = true; } else { msg = res.ToString(); } }).ContinueWith(res => Device.BeginInvokeOnMainThread(async() => { if (success == false) { await App.Current.MainPage.DisplayAlert("Ocurrió un error", msg, "Aceptar"); UserDialogs.Instance.HideLoading(); } else { UserDialogs.Instance.HideLoading(); await App.Current.MainPage.Navigation.PopAsync(); } })); } catch (Exception ex) { App.Current.MainPage.DisplayAlert("Ocurrió un error", ex.ToString(), "Aceptar"); } }
private async void SaveClientMethod() { if (string.IsNullOrEmpty(this.Usuario)) { await Application.Current.MainPage.DisplayAlert( "Error", "El campo usuario está vacío!", "Ok"); return; } if (string.IsNullOrEmpty(this.Nombre)) { await Application.Current.MainPage.DisplayAlert( "Error", "El campo nombre está vacío!", "Ok"); return; } if (string.IsNullOrEmpty(this.ApePat)) { await Application.Current.MainPage.DisplayAlert( "Error", "El apellido paterno esta vacio", "Ok"); return; } if (string.IsNullOrEmpty(this.ApeMat)) { await Application.Current.MainPage.DisplayAlert( "Error", "El apellido materno esta vacìo", "Ok"); return; } if (string.IsNullOrEmpty(this.Email)) { await Application.Current.MainPage.DisplayAlert( "Error", "El campo email está vacío!", "Ok"); return; } // Valida if (this.Fecha.Year >= 1960) { await Application.Current.MainPage.DisplayAlert( "Error", "El seleccione una fecha", "Ok"); return; } if (!RegexUtilities.IsValidEmail(this.Email)) { await Application.Current.MainPage.DisplayAlert( "Error", "¡¡Ingresa un correo valido !!", "Ok"); return; } if (string.IsNullOrEmpty(this.Telefono)) { await Application.Current.MainPage.DisplayAlert( "Error", "El campo telefono está vacío!", "Ok"); return; } if (string.IsNullOrEmpty(this.Password)) { await Application.Current.MainPage.DisplayAlert( "Error", "El campo contraseña está vacío!", "Ok"); return; } if (this.Password.Length < 6) { await Application.Current.MainPage.DisplayAlert( "Error", "El campo contraseña debe tener almenos 6 caracteres!", "Ok"); return; } if (string.IsNullOrEmpty(this.PasswordConfirm)) { await Application.Current.MainPage.DisplayAlert( "Error", "¡¡Confirma tu contraseña!!", "Ok"); return; } if (this.Password != this.PasswordConfirm) { await Application.Current.MainPage.DisplayAlert( "Error", "¡¡ Las contraseñas no coinciden!!", "Ok"); return; } var checkConnetion = await this.apiService.CheckConnection(); if (!checkConnetion.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", "Checa tu conexion a internet!", "Ok"); return; } /* * byte[] imageArray = null; * if (this.file != null) * { * imageArray = FilesHelper.ReadFully(this.file.GetStream()); * } * //Crear la var de user de acuerdo a los campos que tiene la base de datos! * var user = new User * { * Email = this.Email, * Nombre = this.Nombre, * Apellidos = this.Apellidos, * Telefono = this.Telefono, * ImageArray = imageArray, * Password = this.Password * };*/ solicitudinfo = new SolicitudInfoUser(); // Poner las asignaciones correspondientes //solicitud.idusu = Idusuario; //Cambiar la implementacion con async var res = await this.apiService.GetInfoUser( "http://www.creativasoftlineapps.com/ScriptAppTuxmandados/frmACUsuario.aspx", solicitudinfo); if (res == null) { await App.Current.MainPage.DisplayAlert( "Error", "Ocurrió algun problema!", "Ok"); return; } await App.Current.MainPage.DisplayAlert( "Èxito", "¡¡Registro correcto!!", "Ingresar"); await App.Current.MainPage.Navigation.PopAsync(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) //if (true) { if (Page.Request.HttpMethod == "POST") //if (true) { SolicitudInfoUser solicitudUser = null; string Valor = ""; //Leer JSON try { using (var streamReader = new System.IO.StreamReader(Request.GetBufferedInputStream())) { Valor = streamReader.ReadToEnd(); } System.Web.Script.Serialization.JavaScriptSerializer jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); solicitudUser = jsonSerializer.Deserialize <SolicitudInfoUser>(Valor); } catch (Exception) { Valor = ""; } //if (true) if (Valor != "") { InfoUser info = new InfoUser(); AppDatos appDatos = new AppDatos(); info.conexion = ConfigurationManager.ConnectionStrings["Conexion_App"].ConnectionString; info.id = solicitudUser.id; info.usuario = solicitudUser.usuario; info.token = solicitudUser.token; info.rol = solicitudUser.rol; /*info.id = 3; * info.usuario = "eacr77"; * info.token = "C39555B0-86C2-48CE-A0C5-25BF301A1A7E"; * info.rol = 1;*/ try { appDatos.InfoUser(info); } catch (Exception ex) { info.resultado = ex.Message; info.DatosJson = "No se encontró."; } Response.Clear(); Response.ContentType = "application/text;"; if (info.resultado == "REGOK") { Response.Write(info.DatosJson); } else { Response.Write("Error " + info.resultado); } Response.End(); } else { Response.Clear(); Response.ContentType = "application/text;"; Response.Write("Error ID:000: Valores Incorrectos"); Response.End(); } } else { Response.Clear(); Response.ContentType = "application/text;"; Response.Write("Error ID:002 Tipo Incorrecto"); Response.End(); } } }