public void GuardarTest() { AsistenciasRepositorio repositorio = new AsistenciasRepositorio(); Asistencias asistencias = new Asistencias(); List <EstudiantesAsistenciasDetalles> detalle = new List <EstudiantesAsistenciasDetalles>(); detalle.Add( new EstudiantesAsistenciasDetalles( estudianteId: 0, asistenciaId: 0, matricula: 20170611, nombre: "Martinsito Brito", presente: false, ausente: true, excusa: false ) ); asistencias.AsistenciaId = 0; asistencias.SemestreId = 1; asistencias.UsuarioId = 1; asistencias.Usuario = "Jose"; asistencias.Total = 1; asistencias.EstudiantesAsistenciasDetalle = detalle; Assert.IsTrue(repositorio.Guardar(asistencias)); }
private void GuardarButton_Click(object sender, EventArgs e) { AsistenciasRepositorio repositorio = new AsistenciasRepositorio(); bool paso = false; int indice = 0; if (!Validar()) { return; } foreach (var item in this.Detalle) { var checkPresente = EstudiantesDataGridView.Rows[indice].Cells[1].Value; var checkAusente = EstudiantesDataGridView.Rows[indice].Cells[2].Value; var checkExcusa = EstudiantesDataGridView.Rows[indice].Cells[3].Value; if ((bool)checkPresente == false && (bool)checkExcusa == false) { checkAusente = true; } var objeto = this.Detalle.FirstOrDefault(x => x.Matricula == item.Matricula); if (objeto != null) { objeto.Presente = (bool)checkPresente; objeto.Ausente = (bool)checkAusente; objeto.Excusa = (bool)checkExcusa; } indice += 1; } Asistencias asistencia = LlenaClase(); if (AsistenciaIdNumericUpDown.Value == 0) { paso = repositorio.Guardar(asistencia); } else { if (!ExisteEnLaBaseDeDatos()) { MessageBox.Show("No se encuentra la asistencia en la base de datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } paso = repositorio.Modificar(asistencia); } if (paso) { Limpiar(); MessageBox.Show("Guardado exitosamente", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("No se pudo guardar la asistencia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }