public async void LoginCommandExecute() { await Device.InvokeOnMainThreadAsync(() => { this.IsBusy = true; this.IsEnabled = false; }); await Task.Delay(10000); /*Logueandome y obteniendo un token*/ if (userLogin.password != null && userLogin.userName != null) { proc = new RestServiceConsumer(); var controllerString = $"{Constantes.LOGINAUTH}{Constantes.LOGINAUTHUSERPAR}={userLogin.userName}&{Constantes.LOGINAUTHPASSPAR}={userLogin.password}"; var response = await proc.Get <string>(Constantes.BASEURL, Constantes.LOGINPREFIX, controllerString); if (!response.IsSuccesFull) { //Errores en la respuesta if (response.Result == null) { await Application.Current.MainPage.DisplayAlert("Error!", "Credenciales incorrectas", "OK"); return; } //Manejo de otros errores await Application.Current.MainPage.DisplayAlert("Error!", response.Message, "OK"); return; } Settings.SerializedToken = Convert.ToString(response.Result); Settings.IsRemembered = RememberMe; var profileControllerString = $"{Constantes.CLIENTPROFILE}{Constantes.LOGINAUTHUSERPAR}={userLogin.userName}&{Constantes.LOGINAUTHPASSPAR}={userLogin.password}"; var profileResponse = await proc.Get <ApiClientProfile>(Constantes.BASEURL, Constantes.CLIENTPREFIX, profileControllerString, Settings.SerializedToken); if (!profileResponse.IsSuccesFull) { await Application.Current.MainPage.DisplayAlert("Error!", response.Message, "OK"); return; } ApiClientProfile profileInfo = (ApiClientProfile)profileResponse.Result; this.ClientProfile = profileInfo; Settings.FullName = $"{profileInfo.PrimerNombre} {profileInfo.SegundoNombre} {profileInfo.Apellido} {profileInfo.SegundoApellido}"; //Navegacion a la pagina Root bloqueando el regreso al Login Application.Current.MainPage = new RootHomePage(); } else { await Application.Current.MainPage.DisplayAlert("Error!", "Todos los datos son obligatorios", "OK"); } await Device.InvokeOnMainThreadAsync(() => { this.IsBusy = false; this.IsEnabled = true; }); }
public async void LoginCommandExecute() { await Device.InvokeOnMainThreadAsync(() => { this.IsBusy = true; this.IsEnabled = false; }); /*Logueandome y obteniendo un token*/ if (userLogin.password != null && userLogin.userName != null) { proc = new RestServiceConsumer(); var controllerString = $"{Constantes.LOGINAUTH}{Constantes.LOGINAUTHUSERPAR}={userLogin.userName}&{Constantes.LOGINAUTHPASSPAR}={userLogin.password}"; var response = await proc.Get <string>(Constantes.BASEURL, Constantes.LOGINPREFIX, controllerString); if (!response.IsSuccesFull) { //Errores en la respuesta if (response.Result == null) { await Device.InvokeOnMainThreadAsync(() => { this.IsBusy = false; this.IsEnabled = true; }); await Application.Current.MainPage.DisplayAlert("Error!", "Credenciales incorrectas", "OK"); return; } //Manejo de otros errores await Device.InvokeOnMainThreadAsync(() => { this.IsBusy = false; this.IsEnabled = true; }); await Application.Current.MainPage.DisplayAlert("Error!", response.Message, "OK"); return; } //Settings Settings.SerializedToken = Convert.ToString(response.Result); Settings.IsRemembered = RememberMe; //Informacion de perfil var profileControllerString = $"{Constantes.CLIENTPROFILE}{Constantes.LOGINAUTHUSERPAR}={userLogin.userName}&{Constantes.LOGINAUTHPASSPAR}={userLogin.password}"; var profileResponse = await proc.Get <ApiPlainClientProfile>(Constantes.BASEURL, Constantes.CLIENTPREFIX, profileControllerString, Settings.SerializedToken); if (!profileResponse.IsSuccesFull) { await Device.InvokeOnMainThreadAsync(() => { this.IsBusy = false; this.IsEnabled = true; }); await Application.Current.MainPage.DisplayAlert("Error!", response.Message, "OK"); return; } ApiPlainClientProfile profileInfo = (ApiPlainClientProfile)profileResponse.Result; this.ClientProfile = profileInfo; #region Carga de datos a otros ViewModels var profileImageBytes = Convert.FromBase64String(profileInfo.PP.ToString()); ImageSource profileImage; if (profileImageBytes.Length != 0) { profileImage = ImageSource.FromStream(() => new MemoryStream(profileImageBytes)); } else { profileImage = ImageSource.FromFile("userF.png"); } #endregion //Control de recuerdos if (Settings.IsRemembered) { //Cargar perfil a BD local var r = Realm.GetInstance(); try { r.Write(() => { r.Add(new RmbClientProfile() { ID = profileInfo.ID, ProfilePhoto = profileImageBytes, Afiliado = profileInfo.Afiliado, Apellido = profileInfo.Apellido, SegundoApellido = profileInfo.SegundoApellido, Email = profileInfo.Email, PrimerNombre = profileInfo.PrimerNombre, SegundoNombre = profileInfo.SegundoNombre, }); }); } catch (Exception ex) { UpdateProfileViewModel.CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, ex.Message, ToastLength.Long, iconResource: "error64", textSize: 16); } } //Settings Settings.FullName = $"{profileInfo.PrimerNombre} {profileInfo.SegundoNombre} {profileInfo.Apellido} {profileInfo.SegundoApellido}"; Settings.ClientUID = profileInfo.ID; Settings.SuccesfullPassword = userLogin.password; await Device.InvokeOnMainThreadAsync(() => { this.IsBusy = false; this.IsEnabled = true; }); //Navegacion a la pagina Root bloqueando el regreso al Login Application.Current.MainPage = new RootHomePage(); } else { await Device.InvokeOnMainThreadAsync(() => { this.IsBusy = false; this.IsEnabled = true; }); await Application.Current.MainPage.DisplayAlert("Error!", "Todos los datos son obligatorios", "OK"); } }
public async Task loadProducts(int commer) { Device.BeginInvokeOnMainThread(() => { this.IsRefreshing = true; }); service = new RestServiceConsumer(); var connection = await service.CheckConnection(); if (!connection.IsSuccesFull) { //Conexion no establecida Device.BeginInvokeOnMainThread(() => { this.IsRefreshing = false; }); this.IsVisibleMessage = true; this.Message = connection.Message; return; } this.IsVisibleMessage = false; var products = await service.Get <List <ApiProducto> >(Constantes.BASEURL, Constantes.PRODUCTSPREFIX, $"{Constantes.PRODUCTGETBYCOMME}{commer}"); var sucs = await service.Get <List <ApiSucursal> >(Constantes.BASEURL, Constantes.COMMEPREFIX, $"{Constantes.COMMEGETSUCBYCOMME}{commer}"); if (!products.IsSuccesFull || !sucs.IsSuccesFull) { //Error en la extraccion de datos return; } List <ApiProducto> productos = (List <ApiProducto>)products.Result; List <ApiSucursal> sucursales = (List <ApiSucursal>)sucs.Result; List <ApiInventarioSucursal> inventarioSucursals = new List <ApiInventarioSucursal>(); foreach (var suc in sucursales) { ApiInventarioSucursal tempIn = new ApiInventarioSucursal(); tempIn.Sucursal = suc; foreach (var prods in productos) { if (prods.sucursal == suc.idSucursal) { tempIn.Productos.Add(prods); } } inventarioSucursals.Add(tempIn); } foreach (var item in inventarioSucursals) { List <Producto> tempPro = new List <Producto>(); foreach (var temItem in item.Productos) { ImageSource imgSource; var byteArray = Convert.FromBase64String(Convert.ToString(temItem.ilustracion)); if (byteArray.Length != 0) { imgSource = ImageSource.FromStream(() => new MemoryStream(byteArray)); } else { imgSource = ImageSource.FromFile("inven.png"); } tempPro.Add(new Producto() { Sucursal = item.Sucursal, ID = temItem.idProducto, IdSucursal = temItem.sucursal, Descripcion = temItem.descripcion, FechaVencimiento = temItem.fechaVencimiento, Existencias = temItem.existencias, NombreProducto = temItem.nombreProducto, Precio = Convert.ToDouble(temItem.precio), Ilustracion = imgSource }); } this.GroupedProducts.Add(new Models.GroupedProducts(item.Sucursal, tempPro)); } this.UnfilteredGroupedProducts = GroupedProducts; Device.BeginInvokeOnMainThread(() => { this.IsRefreshing = false; }); }