private void mbtNuevo_Click(object sender, EventArgs e)
        {
            FrmProfesorAE frm = new FrmProfesorAE();

            frm.Text = "Nuevo profesor...";
            DialogResult dr = frm.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                try
                {
                    ProfesorEditDto profesorEditDto = frm.GetProfesor();

                    servicio.Guardar(profesorEditDto);
                    DataGridViewRow r = ConstruirFila();
                    ProfesorListDto profesorListDto = Mapeador.CrearMapper().Map <ProfesorListDto>(profesorEditDto);
                    SetearFila(r, profesorListDto);
                    AgregarFila(r);
                    MetroMessageBox.Show(this, "Registro agregado", "Mensaje",
                                         MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exception)
                {
                    MetroMessageBox.Show(this, exception.Message, "Error",
                                         MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #2
0
        public static void CargarDatosComboProfesores(ref MetroComboBox cbo)
        {
            IServicioProfesor servicioProfesor = new ServicioProfesores();
            var             listaProfesores    = servicioProfesor.GetProfesores();
            ProfesorListDto profesorDto        = new ProfesorListDto
            {
                ProfesorId     = 0,
                NombreCompleto = "<Seleccione un Profesor>"
            };

            listaProfesores.Insert(0, profesorDto);
            cbo.DataSource    = listaProfesores;
            cbo.DisplayMember = "NombreCompleto";
            cbo.ValueMember   = "ProfesorId";
            cbo.SelectedIndex = 0;
        }
        private void mgDatos_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow r = mgDatos.SelectedRows[0];
            ProfesorListDto profesorListDto = (ProfesorListDto)r.Tag;

            if (e.ColumnIndex == 1)
            {
                DialogResult dr = MetroMessageBox.Show(this,
                                                       $"¿Desea dar de baja al profesor {profesorListDto.NombreCompleto}?",
                                                       "Confirmar Baja",
                                                       MessageBoxButtons.YesNo,
                                                       MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (dr == DialogResult.Yes)
                {
                    try
                    {
                        if (!servicio.EstaRelacionado(profesorListDto))
                        {
                            servicio.Borrar(profesorListDto.ProfesorId);
                            mgDatos.Rows.Remove(r);
                            MetroMessageBox.Show(this, "Registro borrado",
                                                 "Mensaje",
                                                 MessageBoxButtons.OK,
                                                 MessageBoxIcon.Information);
                        }
                    }
                    catch (Exception exception)
                    {
                        MetroMessageBox.Show(this, exception.Message,
                                             "Error",
                                             MessageBoxButtons.OK,
                                             MessageBoxIcon.Error);
                    }
                }
            }
            else if (e.ColumnIndex == 2)
            {
                ProfesorEditDto profesorEditDto = servicio.GetProfesorPorId(profesorListDto.ProfesorId);
                FrmProfesorAE   frm             = new FrmProfesorAE();
                frm.Text = "Editar Profesor";
                frm.SetProfesor(profesorEditDto);
                DialogResult dr = frm.ShowDialog(this);
                if (dr == DialogResult.OK)
                {
                    try
                    {
                        profesorEditDto = frm.GetProfesor();
                        servicio.Guardar(profesorEditDto);
                        profesorListDto = Mapeador.CrearMapper().Map <ProfesorListDto>(profesorEditDto);
                        SetearFila(r, profesorListDto);
                        MetroMessageBox.Show(this, "Registro Editado", "Mensaje",
                                             MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception exception)
                    {
                        MetroMessageBox.Show(this, exception.Message, "Error",
                                             MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        private void SetearFila(DataGridViewRow r, ProfesorListDto profesor)
        {
            r.Cells[cmnProfesor.Index].Value = profesor.NombreCompleto;

            r.Tag = profesor;
        }
 public bool EstaRelacionado(ProfesorListDto profesor)
 {
     return(_dbContext.Cursos.Any(c => c.ProfesorId == profesor.ProfesorId));
 }
 public bool EstaRelacionado(ProfesorListDto alumnoListDto)
 {
     //Profesor alumno = Mapeador.CrearMapper().Map<Profesor>(alumnoListDto);
     //return _repositorio.EstaRelacionado(alumnoListDto);
     return(false);
 }