private void Set <T>(ref T storage, T value, [CallerMemberName] string propertyName = null) { if (Equals(storage, value)) { return; } storage = value; if (_selected != null) { Iniciativa consulta = iniciativaBL.Consultar(Selected.ID); _selected.Comentarios = consulta.Comentarios; lvComentarios.ItemsSource = _selected.Comentarios; switch (_selected.GetType().Name) { case "Asistire": ((Asistire)_selected).Opciones = ((Asistire)consulta).Opciones; break; case "DoDont": ((DoDont)_selected).Opciones = ((DoDont)consulta).Opciones; break; case "Regla": ((Regla)_selected).Opciones = ((Regla)consulta).Opciones; break; case "Votacion": ((Votacion)_selected).Opciones = ((Votacion)consulta).Opciones; break; case "VotacionMultiple": ((VotacionMultiple)_selected).Opciones = ((VotacionMultiple)consulta).Opciones; break; default: break; } } DetailsMode(); OnPropertyChanged(propertyName); }
private void btnGuardar_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { try { crudIniciativa.Tema = new Tema() { ID = Tema.ID }; crudIniciativa.FechaCreacion = DateTime.Now.Date; if (String.IsNullOrWhiteSpace(txtTitulo.Text) || String.IsNullOrWhiteSpace(txtDescripcion.Text)) { throw new Exception("El título y la descripción no deben estas vacíos."); } else { crudIniciativa.Titulo = txtTitulo.Text; crudIniciativa.Descripcion = txtDescripcion.Text; } if (dpFechaCierre.SelectedDate.Value.Date < DateTime.Now.Date) { throw new Exception("La fecha de cierre debe ser mayor o igual a hoy."); } else { crudIniciativa.FechaCierre = dpFechaCierre.SelectedDate.Value.Date; } switch (crudIniciativa.GetType().Name) { case "Asistire": if (String.IsNullOrWhiteSpace(txtLugar.Text)) { throw new Exception("El campo lugar debe estar completo."); } if (dpFechaLimiteConfirmacion.SelectedDate.Value.Date < DateTime.Now.Date || dpFechaEvento.SelectedDate.Value.Date < DateTime.Now.Date) { throw new Exception("Las fechas deben ser mayores o iguales a hoy."); } else { ((Asistire)crudIniciativa).Lugar = txtLugar.Text; ((Asistire)crudIniciativa).FechaLimiteConfirmacion = dpFechaLimiteConfirmacion.SelectedDate.Value.Date; ((Asistire)crudIniciativa).FechaEvento = dpFechaEvento.SelectedDate.Value.Date; } break; case "DoDont": ((DoDont)crudIniciativa).Tipo = ((KeyValuePair <string, string>)cbTipoIniciativa.SelectedItem).Value; break; case "PropuestaGenerica": break; case "Regla": ((Regla)crudIniciativa).Relevancia = Convert.ToInt32(slFormularioRelevancia.Value); break; case "Votacion": if (lvFormularioOpciones.Items.Count > 0) { foreach (Opcion item in lvFormularioOpciones.Items) { ((Votacion)crudIniciativa).Opciones.Add(item); } } else { throw new Exception("Debe crear al menos una opción"); } break; case "VotacionMultiple": ((VotacionMultiple)crudIniciativa).MaxOpcionesSeleccionables = Convert.ToInt32(slFormularioMaxOpcionesSeleccionables.Value); if (((VotacionMultiple)crudIniciativa).MaxOpcionesSeleccionables > lvFormularioOpciones.Items.Count) { throw new Exception("La cantidad de opciones debe ser mayor o igual al máximo de opciones seleccionables"); } else { if (lvFormularioOpciones.Items.Count > 0) { foreach (Opcion item in lvFormularioOpciones.Items) { ((VotacionMultiple)crudIniciativa).Opciones.Add(item); } } else { throw new Exception("Debe crear al menos una opción"); } } break; default: break; } iniciativaBL.Insertar(crudIniciativa); RefreshIniciativasListView(); DetailsMode(); } catch (Exception ex) { DisplayError(ex.Message); } }