private async void Delete() { var answer = await Application.Current.MainPage.DisplayAlert("Desea eliminar", "confirmar", "si", "no"); if (!answer) { return; } this.IsRunning = true; this.IsEnabled = false; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept); return; } var url = Application.Current.Resources["UrlAPI"].ToString(); var prefix = Application.Current.Resources["UrlPrefix"].ToString(); var controller = Application.Current.Resources["UrlUsuarios"].ToString(); var response = await this.apiService.Delete(url, prefix, controller, this.Usuario.idUsuario); if (!response.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept); return; } var usuarioViewModel = UsuariosViewModel.GetInstance(); //buscar el producto y borrarlode lalsita var borrarUsuario = usuarioViewModel.MyUsuarios.Where(p => p.idUsuario == this.Usuario.idUsuario).FirstOrDefault(); if (borrarUsuario != null) { usuarioViewModel.MyUsuarios.Remove(borrarUsuario); } usuarioViewModel.RefreshList(); this.IsRunning = false; this.IsEnabled = true; // await Application.Current.MainPage.Navigation.PopAsync(); await App.Navigator.PopAsync(); }
private async void Save() { if (string.IsNullOrEmpty(this.Usuario.nombre)) { await Application.Current.MainPage.DisplayAlert("Error", "Introduce el nombre", "ok"); return; } if (string.IsNullOrEmpty(this.Usuario.usuario)) { await Application.Current.MainPage.DisplayAlert("Error", "Introduce el usaurio", "ok"); return; } if (string.IsNullOrEmpty(this.Usuario.password)) { await Application.Current.MainPage.DisplayAlert("Error", "Introduce el password", "ok"); return; } if (string.IsNullOrEmpty(this.Usuario.curp)) { await Application.Current.MainPage.DisplayAlert("Error", "Introduce la curp", "ok"); return; } if (string.IsNullOrEmpty(this.Usuario.rfc)) { await Application.Current.MainPage.DisplayAlert("Error", "Introduce el rfc", "ok"); return; } this.IsRunning = true; this.isEnabled = false; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept); return; } byte[] imageArray = null; if (this.file != null) { imageArray = FilesHelper.ReadFully(this.file.GetStream()); this.Usuario.ImageArray = imageArray; } var url = Application.Current.Resources["UrlAPI"].ToString(); var prefix = Application.Current.Resources["UrlPrefix"].ToString(); var controller = Application.Current.Resources["UrlUsuarios"].ToString(); var response = await this.apiService.Put(url, prefix, controller, this.usuario, this.Usuario.idUsuario); if (!response.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept); } var newUser = (Usuario)response.Result; var usuariosViewModel = UsuariosViewModel.GetInstance(); //borramos el usuario y lo volvemos a adicionar var oldUsuario = usuariosViewModel.MyUsuarios.Where(p => p.idUsuario == this.Usuario.idUsuario).FirstOrDefault(); if (oldUsuario != null) { usuariosViewModel.MyUsuarios.Remove(oldUsuario); } usuariosViewModel.MyUsuarios.Add(newUser); usuariosViewModel.RefreshList(); this.IsRunning = false; this.IsEnabled = true; //back por codigo await App.Navigator.PopAsync(); }