private async void Delete() { var answer = await Application.Current.MainPage.DisplayAlert("Confirmacion", "¿Esta seguro de eliminar esta incidencia?", "Aceptar", "Cancelar"); if (!answer) { return; } this.isEnable = false; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.isEnable = true; await Application.Current.MainPage.DisplayAlert("Error", connection.Message, "Aceptar"); return; } var url = Application.Current.Resources["UrlAPI"].ToString(); var prefix = Application.Current.Resources["Prefix"].ToString(); var controller = Application.Current.Resources["Controller"].ToString(); var response = await this.apiService.Delete(url, prefix, controller, this.Incidencia.Id); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert("Error", response.Message, "Aceptar"); return; } var incidenciasViewModel = IncidenciasViewModel.GetInstance(); var deletedIncidencia = incidenciasViewModel.Incidencias.Where(P => P.Id == this.Incidencia.Id).FirstOrDefault(); if (deletedIncidencia != null) { incidenciasViewModel.Incidencias.Remove(deletedIncidencia); } this.IsEnable = true; await Application.Current.MainPage.Navigation.PopAsync(); }
private async void Save() { if (string.IsNullOrEmpty(this.Responsable)) { await Application.Current.MainPage.DisplayAlert("Error", "Debe ingresar un responsable", "Aceptar"); return; } if (this.TipoIncidenciaSelect == null) { await Application.Current.MainPage.DisplayAlert("Error", "Debe seleccionar un tipo de incidencte", "Aceptar"); return; } if (string.IsNullOrEmpty(this.FechaIncidencia.ToString())) { await Application.Current.MainPage.DisplayAlert("Error", "Debe ingresar una fecha", "Aceptar"); return; } if (string.IsNullOrEmpty(this.Motivo)) { await Application.Current.MainPage.DisplayAlert("Error", "Debe ingresar un motivo", "Aceptar"); return; } this.IsEnable = false; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsEnable = true; await Application.Current.MainPage.DisplayAlert("Error", connection.Message, "Aceptar"); return; } var incidencia = new Incidencia() { Responsable = this.Responsable, TipoIncidencia = Convert.ToString(this.TipoIncidenciaSelect.Key), FechaIncidencia = this.FechaIncidencia, Estado = this.Estado, Motivo = this.Motivo }; var url = Application.Current.Resources["UrlAPI"].ToString(); var prefix = Application.Current.Resources["Prefix"].ToString(); var controller = Application.Current.Resources["Controller"].ToString(); var response = await this.apiService.Post(url, prefix, controller, incidencia); if (!response.IsSuccess) { this.IsEnable = true; await Application.Current.MainPage.DisplayAlert("Error", response.Message, "Aceptar"); return; } var newIncidencia = (Incidencia)response.Result; var ViewModel = IncidenciasViewModel.GetInstance(); ViewModel.Incidencias.Add(new IncidenciaItemViewModel { Id = newIncidencia.Id, Responsable = newIncidencia.Responsable, TipoIncidencia = newIncidencia.TipoIncidencia, FechaIncidencia = newIncidencia.FechaIncidencia, Estado = newIncidencia.Estado, Motivo = newIncidencia.Motivo }); this.IsEnable = true; await Application.Current.MainPage.Navigation.PopAsync(); }