public async void UpdateCommandExecute() { bool updateCredentials = false; RestServiceConsumer service; SetActivity(true); //Conexion service = new RestServiceConsumer(); var response = await service.CheckConnection(); if (!response.IsSuccesFull) { SetActivity(false); //No hay conexion CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, response.Message, iconResource: "error64", textSize: 16); return; } try { //Chequeo de vacios if (!AllDataChecker()) { //Faltan datos SetActivity(false); CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, Languages.AllDataNeeded, iconResource: "error64", textSize: 16); return; } if (!NameChecker(this.Nombres.TrimEnd(' ')) || !NameChecker(this.Apellidos.TrimEnd(' '))) { SetActivity(false); //Los nombres o apellidos no han sido bien escritos} if (!NameChecker(this.Nombres.TrimEnd(' '))) { CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, Languages.WronWGNames, iconResource: "error64", textSize: 16); } else { CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, Languages.WronWGivenNames, iconResource: "error64", textSize: 16); } return; } //Chequeo de password correcto if (Settings.SuccesfullPassword != this.OldPassword) { SetActivity(false); //No coinciden las contraseñas CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, Languages.PasswordsDontMatch, iconResource: "error64", textSize: 16); return; } //Se quiere actualizar algo de la seccion de credenciales? if (!this.NewPassword.Equals(string.Empty) || !this.RepeatPassword.Equals(string.Empty)) { //Todos los datos fueron proporcionados? if (NewPassword.Equals(string.Empty) || RepeatPassword.Equals(string.Empty)) { SetActivity(false); CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, Languages.AllDataNeeded, iconResource: "error64", textSize: 16); return; } //Chequeo de repeticion de nueva contraseña if (this.NewPassword != this.RepeatPassword) { SetActivity(false); //No coinciden las contraseñas CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, Languages.PasswordsShouldMatch, iconResource: "error64", textSize: 16); return; } else { updateCredentials = true; } } //Creacion del modelo a enviar Stream streamedImage = GetImageSourceStream(this.Profile.ProfileImage); this.ProfileImageBytes = StreamToByteArray(streamedImage); var token = Settings.SerializedToken; var posted = new ApiPlainClientProfile() { ID = Settings.ClientUID, PrimerNombre = this.Nombres.Split(' ')[0], SegundoNombre = this.Nombres.Split(' ')[1], Apellido = this.Apellidos.Split(' ')[0], SegundoApellido = this.Apellidos.Split(' ')[1], Email = this.Profile.Email, PP = this.ProfileImageBytes, Afiliado = DateTime.Now }; var posted2 = new ApiClientCredentials() { IdClient = -1, IdPersona = posted.ID, Password = this.NewPassword, UserName = "******" }; Response result2 = null; var result = await service.Put <ApiPlainClientProfile>(Constantes.BASEURL, Constantes.CLIENTPREFIX, Constantes.CLIENTUPDATEPROFILE, posted, token); if (updateCredentials) { result2 = await service.Put <ApiClientCredentials>(Constantes.BASEURL, Constantes.CLIENTPREFIX, Constantes.CLIENTUPDATECREDENTIALS, posted2, token); } if (updateCredentials) { if (!result.IsSuccesFull || !result2.IsSuccesFull) { SetActivity(false); //Error en la peticion if (!result.IsSuccesFull) { CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, result.Message, iconResource: "error64", textSize: 16); SetActivity(false); return; } else { CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, result2.Message, iconResource: "error64", textSize: 16); } SetActivity(false); return; } Settings.SuccesfullPassword = this.NewPassword; } else { if (!result.IsSuccesFull) { CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, result.Message, iconResource: "error64", textSize: 16); SetActivity(false); return; } } SetActivity(false); CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, Languages.UpdatedProfile, iconResource: "ok96", textSize: 16); UpdateLocalProfileInfo(posted); } catch (Exception ex) { CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black, ex.Message, iconResource: "error64", textSize: 16); SetActivity(false); throw ex; } }
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; }); }