} // Int64Field #endregion #region Methods /// <summary> /// Método encargado de recuperar los datos de una entidad mediante su identificador. /// </summary> /// <param name="identifier"> /// Parámetro que indica el identificador de la entidad que se va a recuperar. /// </param> /// <returns> /// Devuelve el objeto Dto <see cref="PersonaDto"/> correspondiente. /// </returns> public override PersonaDto GetById(Int32 identifier) { PersonaServiceClient serviceClient = new PersonaServiceClient(); // Consumimos el servicio y obtenemos los datos. var personaDto = serviceClient.GetById(identifier); // Devolvemos la respuesta. return(personaDto); } // GetById
} // GetById /// <summary> /// Método encargado de crear o actualizar una entidad de tipo Persona. /// </summary> /// <param name="parameter"> /// Parámetro con información adicional. /// </param> public override void OnSaveRecord(object parameter) { if (this.IsActive && (this.ObjectElement != null)) { PersonaServiceClient serviceClient = new PersonaServiceClient(); if (this.ObjectElement.Id == default(Int32)) { serviceClient.Create(this.ObjectElement); this.MessageBoxService.Show("Entidad agregada"); } else { bool response = serviceClient.Update(this.ObjectElement); this.MessageBoxService.Show("Entidad actualizada"); } } } // OnSaveRecord
/// <summary> /// Método público encargado del borrado de una entidad . /// </summary> /// <param name="parameter"> /// Parámetro con información adicional. /// </param> public override void OnDeleteRecord(object parameter) { try { if (this.IsActive && this.SelectedItem != null) { // Instanciamos el proxy. PersonaServiceClient serviceClient = new PersonaServiceClient(); // Ejecutamos el servicio. bool result = serviceClient.Delete(this.SelectedItem.Id); if (result) { this.MessageBoxService.Show( "El registro se ha borrado correctamente.", /* TODO pass to resources borrar/ deshabilitar */ Application.Current.MainWindow.Title, MessageBoxButton.OK, MessageBoxImage.Information); this.RefreshCommands(); } else { this.MessageBoxService.Show( "¡Ha sido imposible borrar el registro!", /* TODO pass to resources borrar / deshabilitar*/ Application.Current.MainWindow.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation); } } } catch (System.Exception ex) { this.MessageBoxService.Show( string.Format( "¡Se ha producido un error al intentar borrar el registro!\r\n\r\n{0}", ex.Message), Application.Current.MainWindow.Title, MessageBoxButton.OK, MessageBoxImage.Error); } } // OnDeleteRecord
} // OnDeleteRecord /// <summary> /// Método encargado de obtener todos los registros de Persona. /// </summary> /// <param name="parameter"> /// Parámetro con información adicional. /// </param> public override void OnGetRecords(object parameter) { if (!this.IsBusy) { this.IsBusy = true; // Instanciamos el proxy. PersonaServiceClient serviceClient = new PersonaServiceClient(); //Ejecutamos el servicio de forma asíncrona. serviceClient.BeginGetPaged(this.Specification, (asyncResult) => { // Obtenemos el resultado. PagedElements <PersonaDto> result = serviceClient.EndGetPaged(asyncResult); this.Items = new ObservableCollection <PersonaViewModel>(result.Select(i => new PersonaViewModel(i))); this.TotalRecordCount = result.TotalElements; this.IsBusy = false; this.RefreshPagingCommands(); }, null); } } // OnGetRecords