/// <summary>
        /// Inserta un registro en GEN_Valores
        /// </summary>
        /// <param name="oValor"></param>
        /// <returns></returns>
        public GrupoPersona Insert(SqlConnection oConn, SqlTransaction oTran, GrupoPersona oGrupoPersona)
        {
            using (SqlCommand oComm = new SqlCommand())
            {
                oComm.Connection  = (oTran != null) ? oTran.Connection : oConn;
                oComm.Transaction = oTran;

                oComm.CommandType = CommandType.StoredProcedure;
                oComm.CommandText = ObjectName + "_Insert";

                oComm.Parameters.Add(new SqlParameter("@IdGrupo", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Original, oGrupoPersona.IdGrupo));
                oComm.Parameters.Add(new SqlParameter("@IdPersona", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Original, oGrupoPersona.IdPersona));

                oComm.Parameters.Add(new SqlParameter("@UsuarioAlta", SqlDbType.VarChar, 0, ParameterDirection.Input, true, 0, 0, null, DataRowVersion.Original, oGrupoPersona.UsuarioAlta));
                oComm.Parameters.Add(new SqlParameter("@RowId", SqlDbType.Timestamp, 8, ParameterDirection.InputOutput, false, 0, 0, null, DataRowVersion.Original, oGrupoPersona.RowId));

                int rowsAffected = oComm.ExecuteNonQuery();

                if (rowsAffected == 0)
                {
                    throw new Exception("No se insertó ningún registro. Por favor, reintente la operación.");
                }

                oGrupoPersona.RowId = (Byte[])oComm.Parameters["@Rowid"].Value;
            }

            return(oGrupoPersona);
        }
 public GrupoPersonaViewModel(GrupoPersona gp)
 {
     GrupoId    = gp.Grupo.Id;
     MateriaId  = gp.Materia.Id;
     CicloId    = gp.Ciclo.Id;
     PersonaId  = gp.Persona.Id;
     ProfesorId = gp.Profesor.Id;
 }
예제 #3
0
 public GrupoPersona GetGrupoPersonaById(GrupoPersona oGrupoPersona)
 {
     using (GrupoPersonaDataAccess tDataAccess = new GrupoPersonaDataAccess())
     {
         DataSet ds = tDataAccess.GetByID(oGrupoPersona);
         if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
         {
             return(GrupoPersona.GetFromDataRow(ds.Tables[0].Rows[0]));
         }
     }
     return(null);
 }
예제 #4
0
        public List <GrupoPersona> GetListByFilter(GrupoPersona oGrupoPersona)
        {
            using (GrupoPersonaDataAccess tDataAccess = new GrupoPersonaDataAccess())
            {
                DataSet ds = tDataAccess.GetListByFilter(oGrupoPersona);

                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    return(GrupoPersona.GetFromDS(ds));
                }
            }

            return(null);
        }
        /// <summary>
        /// Inserta un registro en GEN_Valores
        /// </summary>
        /// <param name="oValor"></param>
        /// <returns></returns>
        public GrupoPersona Insert(GrupoPersona oGrupoPersona)
        {
            SqlConnection oConn = new SqlConnection(ConfigurationManager.ConnectionStrings["CONEXION"].ConnectionString);

            oConn.Open();
            SqlTransaction oTran = oConn.BeginTransaction();

            try
            {
                using (SqlCommand oComm = new SqlCommand())
                {
                    oComm.Connection  = (oTran != null) ? oTran.Connection : oConn;
                    oComm.Transaction = oTran;

                    oComm.CommandType = CommandType.StoredProcedure;
                    oComm.CommandText = ObjectName + "_Insert";

                    oComm.Parameters.Add(new SqlParameter("@IdGrupo", SqlDbType.Int, 0, ParameterDirection.InputOutput, false, 0, 0, null, DataRowVersion.Original, oGrupoPersona.IdGrupo));
                    oComm.Parameters.Add(new SqlParameter("@IdPersona", SqlDbType.Int, 0, ParameterDirection.InputOutput, false, 0, 0, null, DataRowVersion.Original, oGrupoPersona.IdPersona));

                    oComm.Parameters.Add(new SqlParameter("@UsuarioAlta", SqlDbType.VarChar, 0, ParameterDirection.Input, true, 0, 0, null, DataRowVersion.Original, oGrupoPersona.UsuarioAlta));
                    oComm.Parameters.Add(new SqlParameter("@RowId", SqlDbType.Timestamp, 8, ParameterDirection.InputOutput, false, 0, 0, null, DataRowVersion.Original, oGrupoPersona.RowId));

                    int rowsAffected = oComm.ExecuteNonQuery();

                    if (rowsAffected == 0)
                    {
                        throw new Exception("No se insertó ningún registro. Por favor, reintente la operación.");
                    }

                    oGrupoPersona.IdGrupo   = (int)oComm.Parameters["@IdGrupo"].Value;
                    oGrupoPersona.IdPersona = (int)oComm.Parameters["@IdPersona"].Value;
                    oGrupoPersona.RowId     = (Byte[])oComm.Parameters["@Rowid"].Value;

                    oTran.Commit();
                }
            }
            catch (Exception e)
            {
                oTran.Rollback();
                throw new Exception("Hubo un error al insertar una Persona a un grupo en la base de datos.");
            }
            finally
            {
                oConn.Close();
                oTran.Dispose();
            }

            return(oGrupoPersona);
        }
        /// <summary>
        /// Inserta un registro en GEN_Valores
        /// </summary>
        /// <param name="oValor"></param>
        /// <returns></returns>
        public void Delete(SqlConnection oConn, SqlTransaction oTran, GrupoPersona oGrupoPersona)
        {
            using (SqlCommand oComm = new SqlCommand())
            {
                oComm.Connection  = (oTran != null) ? oTran.Connection : oConn;
                oComm.Transaction = oTran;

                oComm.CommandType = CommandType.StoredProcedure;
                oComm.CommandText = ObjectName + "_Delete";

                oComm.Parameters.Add(new SqlParameter("@IdGrupo", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Original, oGrupoPersona.IdGrupo));
                oComm.Parameters.Add(new SqlParameter("@IdPersona", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Original, oGrupoPersona.IdPersona));

                oComm.ExecuteNonQuery();
            }
        }
        /// <summary>
        /// Obtiene un registro de GEN_Valores por un id
        /// </summary>
        /// <param name="oTipoValor"></param>
        /// <returns></returns>
        public DataSet GetByID(GrupoPersona oGrupoPersona)
        {
            // Creo la conexión y la transacción
            SqlConnection oConn = new SqlConnection(ConfigurationManager.ConnectionStrings["CONEXION"].ConnectionString);

            oConn.Open();
            SqlTransaction oTran = oConn.BeginTransaction();

            DataSet ds = new DataSet();

            try
            {
                using (SqlDataAdapter adapter = new SqlDataAdapter())
                {
                    using (SqlCommand oComm = new SqlCommand())
                    {
                        oComm.Connection  = oTran != null ? oTran.Connection : oConn;
                        oComm.Transaction = oTran;

                        oComm.CommandType = CommandType.StoredProcedure;
                        oComm.CommandText = ObjectName + "_GetByID";

                        oComm.Parameters.Add(new SqlParameter("@IdGrupo", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Original, oGrupoPersona.IdGrupo));
                        oComm.Parameters.Add(new SqlParameter("@IdPersona", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Original, oGrupoPersona.IdPersona));
                        oComm.Parameters.Add(new SqlParameter("@RowId", SqlDbType.Timestamp, 0, ParameterDirection.Input, true, 0, 0, null, DataRowVersion.Original, oGrupoPersona.RowId));

                        adapter.SelectCommand = oComm;
                        adapter.Fill(ds);

                        oTran.Commit();
                    }
                }
            }
            catch (Exception e)
            {
                oTran.Rollback();
                throw e;
            }
            finally
            {
                oConn.Close();
                oTran.Dispose();
            }

            return(ds);
        }
예제 #8
0
        private List <GrupoPersona> GetGrupoPersonas(List <int> personas, int?idGrupo, string usuario)
        {
            List <GrupoPersona> result = new List <GrupoPersona>();

            foreach (int p in personas)
            {
                GrupoPersona oGrupo = new GrupoPersona()
                {
                    IdPersona   = p,
                    IdGrupo     = idGrupo,
                    UsuarioAlta = usuario
                };

                result.Add(oGrupo);
            }

            return(result);
        }
예제 #9
0
        //Crear
        public ActionResult Crear(GrupoPersonaViewModel gpvm)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    //Algo salio mal, de modo que volvemos a la lista, pero
                    //se tienen que llenar los dropdown de nuevo
                    gpvm.grupoList    = _ctx.Grupos.ToList();
                    gpvm.materiaList  = _ctx.Materias.ToList();
                    gpvm.cicloList    = _ctx.Ciclos.ToList();
                    gpvm.personaList  = _ctx.Personas.Where(x => x.TipoPersonaId == TipoPersona.Alumno).ToList();
                    gpvm.profesorList = _ctx.Personas.Where(x => x.TipoPersonaId == TipoPersona.Profesor).ToList();

                    //
                    return(View("FormGrupoPersonas", gpvm));
                }
                GrupoPersona gp = null;
                if (gpvm.Id == 0)
                {
                    gp = new GrupoPersona();
                    //llenamos la informacion
                    gp.GrupoId    = gpvm.GrupoId;
                    gp.MateriaId  = gpvm.MateriaId;
                    gp.CicloId    = gpvm.CicloId;
                    gp.PersonaId  = gpvm.PersonaId;
                    gp.ProfesorId = gpvm.ProfesorId;

                    _ctx.GrupoPersonas.Add(gp);
                }
                else
                {
                    //Estan editando
                    gp = _ctx.GrupoPersonas.SingleOrDefault(x => x.Id == gpvm.Id);

                    if (gp != null)
                    {
                        //es que quieren editar y realmente existe, parseamos valores
                        gp.GrupoId    = gpvm.GrupoId;
                        gp.MateriaId  = gpvm.MateriaId;
                        gp.CicloId    = gpvm.CicloId;
                        gp.PersonaId  = gpvm.PersonaId;
                        gp.ProfesorId = gpvm.ProfesorId;
                    }
                }


                _ctx.SaveChanges();
                //aqui validamos que fue un registro nuevo
                if (gpvm.Id == 0)
                {
                    //es un registro nuevo
                    int id_gp = gp.Id;
                    // comentado por que daba nulo .
                    //int periodos = gp.Ciclo.Modalidad.n_periodos;
                    var ciclo    = _ctx.Ciclos.Include(x => x.Modalidad).SingleOrDefault(x => x.Id == gp.CicloId);
                    int periodos = ciclo.Modalidad.n_periodos;
                    for (int i = 1; i <= periodos; i++)
                    {
                        //realiamos un insert
                        GpPeriodo gpp = new GpPeriodo();

                        gpp.GrupoPersonaId = id_gp;
                        gpp.periodo        = i;
                        _ctx.GpPeriodos.Add(gpp);
                    }
                    _ctx.SaveChanges();
                }
            }
            catch (Exception e)
            {
                return(View("FormGrupoPersona", e));
            }

            return(RedirectToAction("Index"));
        }
예제 #10
0
        public ActionResult SubirExcel(GrupoPersonaExcelViewModel gpevm)
        {
            if (!ModelState.IsValid)
            {
                return(View("FormExcel", gpevm));
            }
            //En este punto tenemos el View model con informacion.
            //generamos un path.
            String path = Server.MapPath(Constantes.RUTA_TEMPORAL_EXCEL_GRUPOPERSONAS + gpevm.file.FileName);

            //revisamos si existe el archivo, al final de todo esto se elimina, es decir, no debe de existir el archivo.
            if (!System.IO.File.Exists(path))
            {
                gpevm.file.SaveAs(path);
                FileInfo fi = new FileInfo(path);
                if (fi.Exists)
                {
                    using (ExcelPackage ep = new ExcelPackage(fi)) {
                        //Implícitamente solo existe 1 worksheet, de modo que tomamos el primero
                        ExcelWorksheet exw = ep.Workbook.Worksheets[1];

                        //obtenemos las columnas y filas.
                        int columCount = exw.Dimension.End.Column;
                        int rowCount   = exw.Dimension.End.Row;
                        //generamos una lista vacia
                        List <GrupoPersona> lgp = new List <GrupoPersona>();

                        for (int row = 2; row < rowCount; row++)
                        {
                            if (exw.Cells[row, 1].Value != null &&
                                exw.Cells[row, 2].Value != null &&
                                exw.Cells[row, 3].Value != null &&
                                exw.Cells[row, 4].Value != null &&
                                exw.Cells[row, 5].Value != null)
                            {
                                GrupoPersona gp          = new GrupoPersona();
                                char         delimitador = '.';
                                string[]     PersonaId   = exw.Cells[row, 1].Text.Split(delimitador);
                                string[]     GrupoId     = exw.Cells[row, 3].Text.Split(delimitador);
                                string[]     MateriaId   = exw.Cells[row, 2].Text.Split(delimitador);
                                string[]     CicloId     = exw.Cells[row, 4].Text.Split(delimitador);
                                string[]     ProfesorId  = exw.Cells[row, 5].Text.Split(delimitador);

                                gp.PersonaId  = int.Parse(PersonaId[0]);
                                gp.GrupoId    = int.Parse(GrupoId[0]);
                                gp.MateriaId  = int.Parse(MateriaId[0]);
                                gp.CicloId    = int.Parse(CicloId[0]);
                                gp.ProfesorId = int.Parse(ProfesorId[0]);

                                lgp.Add(gp);
                            }
                            int x = 4;
                        }
                        //ahora guardamos
                        for (int i = 0; i < lgp.Count; i++)
                        {
                            _ctx.GrupoPersonas.Add(lgp[i]);
                        }
                        _ctx.SaveChanges();
                    }
                }
            }
            return(View("FormExcel", gpevm));
        }