using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;


namespace QuintoCaminoV2.Data_objects
{
    public class DataLayer
    {
        public List<Charlas> get_Charlas(Charlas ObjCharlas)
        {
            
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_get_Charlas";

            List<Charlas> lstCharlas = new List<Charlas>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;

            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
             {
                 Charlas oReturn = new Charlas();
                 oReturn.intCharlaId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                 oReturn.vchTitulo = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                 oReturn.vchFecha = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                 oReturn.vchDescripcionCorta = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                 oReturn.vchUrl = oReader[4] is DBNull ? "" : Convert.ToString(oReader[4]);
                 oReturn.datFalta = oReader[5] is DBNull ? "" : Convert.ToString(oReader[5]);
                 oReturn.bitActivo = oReader[6] is DBNull ? false : Convert.ToBoolean(oReader[6]);
                 lstCharlas.Add(oReturn);
            }
            oCon.Close();
           
            return lstCharlas;
        }
        public Errores insertCharla(List<Charlas> lstCharlas)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Insert_Charla";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

                oCommand.Parameters.Add("@vchTitulo", SqlDbType.VarChar);
                oCommand.Parameters.Add("@vchFecha", SqlDbType.DateTime);
                oCommand.Parameters.Add("@vchDescripcionCorta", SqlDbType.VarChar);
                oCommand.Parameters.Add("@vchUrl", SqlDbType.VarChar);
                oCommand.Parameters.Add("@bitActivo", SqlDbType.Bit);

                foreach (Charlas oCharla in lstCharlas)
                {
                    oCommand.Parameters["@vchTitulo"].Value = oCharla.vchTitulo;
                    oCommand.Parameters["@vchFecha"].Value = Convert.ToDateTime(oCharla.vchFecha);
                    oCommand.Parameters["@vchDescripcionCorta"].Value = oCharla.vchDescripcionCorta;
                    oCommand.Parameters["@vchUrl"].Value = oCharla.vchUrl;
                    oCommand.Parameters["@bitActivo"].Value = oCharla.bitActivo;
                                    }

                oCon.Open();
                if (oCommand.ExecuteNonQuery() > 0)
                {
                    oErrores.bitError = false;

                }
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }
        public List<Cursos> get_Cursos(Cursos objCursos)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_get_Cursos";

            List<Cursos> lstCursos = new List<Cursos>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;

            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Cursos oReturn = new Cursos();
                oReturn.intCursoId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchTitulo = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.vchDescripcionCorta = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.vchDescripcion = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                oReturn.decCosto = oReader[4] is DBNull ? 0 : Convert.ToInt32(oReader[4]);
                oReturn.decIva = oReader[5] is DBNull ? 0 : Convert.ToInt32(oReader[5]);
                oReturn.decCostoTotal = oReader[6] is DBNull ? 0 : Convert.ToInt32(oReader[6]);
                oReturn.datFalta = oReader[7] is DBNull ? "" : Convert.ToString(oReader[7]);
                oReturn.bitActivo = oReader[8] is DBNull ? false : Convert.ToBoolean(oReader[8]);
                lstCursos.Add(oReturn);
            }
            oCon.Close();

            return lstCursos;
        }
        public List<Charlas> get_Charlas_by_Id(Charlas ObjCharlas)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_getCharlaBy_Id";

            List<Charlas> lstCharlas = new List<Charlas>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;
            oCommand.Parameters.Add("@intCharlaId", SqlDbType.Int);

            oCommand.Parameters["@intCharlaId"].Value = ObjCharlas.intCharlaId;
            

            oCon.Open();
            oReader = oCommand.ExecuteReader();           

            while (oReader.Read())
            {
                Charlas oReturn = new Charlas();
                oReturn.intCharlaId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchTitulo = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.vchFecha = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.vchDescripcionCorta = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                oReturn.vchUrl = oReader[4] is DBNull ? "" : Convert.ToString(oReader[4]);
                oReturn.datFalta = oReader[5] is DBNull ? "" : Convert.ToString(oReader[5]);
                oReturn.bitActivo = oReader[6] is DBNull ? false : Convert.ToBoolean(oReader[6]);
                lstCharlas.Add(oReturn);
            }
            oCon.Close();

            return lstCharlas;
        }
        public List<Cursos> get_Cursos_by_Id(Cursos ObjCharlas)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_getCursoBy_Id";

            List<Cursos> lstCursos = new List<Cursos>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;
            oCommand.Parameters.Add("@intCursoId", SqlDbType.Int);

            oCommand.Parameters["@intCursoId"].Value = ObjCharlas.intCursoId;


            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Cursos oReturn = new Cursos();
                oReturn.intCursoId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchTitulo = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.vchDescripcionCorta = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.vchDescripcion = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);                
                oReturn.decCosto = oReader[4] is DBNull ? 0 : Convert.ToInt32(oReader[4]);
                oReturn.bitActivo = oReader[8] is DBNull ? false : Convert.ToBoolean(oReader[8]);
                lstCursos.Add(oReturn);
            }
            oCon.Close();

            return lstCursos;
        }
        public Errores DeleteCharla(List<Charlas> lstCharlas)
        {
            Errores oErrores = new Errores();

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_delete_Charla";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

                oCommand.Parameters.Add("@intCharlaId", SqlDbType.Int);
         
                foreach (Charlas oCharla in lstCharlas)
                {
                    oCommand.Parameters["@intCharlaId"].Value = oCharla.intCharlaId;
   
                }

                oCon.Open();
                oCommand.ExecuteNonQuery();
                oErrores.bitError = false;
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;

         }     
        public Errores UpdateCharla(List<Charlas> lstCharlas)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Update_Charla";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

                oCommand.Parameters.Add("@intCharlaId", SqlDbType.Int);
                oCommand.Parameters.Add("@vchTitulo", SqlDbType.VarChar);
                oCommand.Parameters.Add("@vchFecha", SqlDbType.DateTime);
                oCommand.Parameters.Add("@vchDescripcionCorta", SqlDbType.VarChar);
                oCommand.Parameters.Add("@vchUrl", SqlDbType.VarChar);
                oCommand.Parameters.Add("@bitActivo", SqlDbType.Bit);

                foreach (Charlas oCharla in lstCharlas)
                {
                    oCommand.Parameters["@intCharlaId"].Value = oCharla.intCharlaId;
                    oCommand.Parameters["@vchTitulo"].Value = oCharla.vchTitulo;
                    oCommand.Parameters["@vchFecha"].Value = Convert.ToDateTime(oCharla.vchFecha);
                    oCommand.Parameters["@vchDescripcionCorta"].Value = oCharla.vchDescripcionCorta;
                    oCommand.Parameters["@vchUrl"].Value = oCharla.vchUrl;
                    oCommand.Parameters["@bitActivo"].Value = oCharla.bitActivo;
                }

                oCon.Open();
                oCommand.ExecuteNonQuery();                
                oErrores.bitError = false;
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }
        public Errores DeleteCursos(List<Cursos> lstCursos)
        {
            Errores oErrores = new Errores();

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_delete_Cursos";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

                oCommand.Parameters.Add("@intCursoId", SqlDbType.Int);

                foreach (Cursos oCursos in lstCursos)
                {
                    oCommand.Parameters["@intCursoId"].Value = oCursos.intCursoId;

                }

                oCon.Open();
                oCommand.ExecuteNonQuery();
                oErrores.bitError = false;
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;

        }

        public Errores DeleteClase(List<Clases> lstCursos)
        {
            Errores oErrores = new Errores();

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_delete_Clase";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

                oCommand.Parameters.Add("@intClaseID", SqlDbType.Int);

                foreach (Clases oClases in lstCursos)
                {
                    oCommand.Parameters["@intClaseID"].Value = oClases.intClaseID;

                }

                oCon.Open();
                oCommand.ExecuteNonQuery();
                oErrores.bitError = false;
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;

        }


        public Errores UpdateCursos(List<Cursos> lstCursos)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Update_Curso";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

                oCommand.Parameters.Add("@intCursoId", SqlDbType.Int);
                oCommand.Parameters.Add("@vchTitulo", SqlDbType.VarChar);
                oCommand.Parameters.Add("@vchDescripcionCorta", SqlDbType.VarChar);
                oCommand.Parameters.Add("@vchDescripcion", SqlDbType.VarChar);
                oCommand.Parameters.Add("@decCosto", SqlDbType.Decimal);
                oCommand.Parameters.Add("@bitActivo", SqlDbType.Bit);

                foreach (Cursos oCurso in lstCursos)
                {
                    oCommand.Parameters["@intCursoId"].Value = oCurso.intCursoId;
                    oCommand.Parameters["@vchTitulo"].Value = oCurso.vchTitulo;
                    oCommand.Parameters["@vchDescripcionCorta"].Value = oCurso.vchDescripcionCorta;
                    oCommand.Parameters["@vchDescripcion"].Value = oCurso.vchDescripcion;
                    oCommand.Parameters["@decCosto"].Value = oCurso.decCosto;
                    oCommand.Parameters["@bitActivo"].Value = oCurso.bitActivo;
                }

                oCon.Open();
                oCommand.ExecuteNonQuery();
                oErrores.bitError = false;
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }
        public Errores insertCurso(List<Cursos> lstCursos)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Insert_Curso";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

              
                oCommand.Parameters.Add("@vchTitulo", SqlDbType.VarChar);
                oCommand.Parameters.Add("@vchDescripcionCorta", SqlDbType.VarChar);
                oCommand.Parameters.Add("@vchDescripcion", SqlDbType.VarChar);
                oCommand.Parameters.Add("@decCosto", SqlDbType.Decimal);
                oCommand.Parameters.Add("@bitActivo", SqlDbType.Bit);

                foreach (Cursos oCurso in lstCursos)
                {
                    oCommand.Parameters["@vchTitulo"].Value = oCurso.vchTitulo;
                    oCommand.Parameters["@vchDescripcionCorta"].Value = oCurso.vchDescripcionCorta;
                    oCommand.Parameters["@vchDescripcion"].Value = oCurso.vchDescripcion;
                    oCommand.Parameters["@decCosto"].Value = oCurso.decCosto;
                    oCommand.Parameters["@bitActivo"].Value = oCurso.bitActivo;
                }

                oCon.Open();
                if (oCommand.ExecuteNonQuery() > 0)
                {
                    oErrores.bitError = false;

                }
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }
        //public List<Usuarios> get_Usuarios()
        //{

        //    string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
        //    string strProcedure = "stp_get_Users";

        //    List<Usuarios> lstUsuarios = new List<Usuarios>();

        //    SqlConnection oCon = new SqlConnection(strConn);
        //    SqlCommand oCommand = new SqlCommand();
        //    SqlDataReader oReader;

        //    oCommand.CommandText = strProcedure;
        //    oCommand.CommandType = CommandType.StoredProcedure;
        //    oCommand.Connection = oCon;

        //    oCon.Open();
        //    oReader = oCommand.ExecuteReader();

        //    while (oReader.Read())
        //    {
        //        Usuarios oReturn = new Usuarios();
        //        oReturn.UserId = oReader[0] is DBNull ? "" : Convert.ToString(oReader[0]);
        //        oReturn.UserName = oReader[1] is DBNull ?"" : Convert.ToString(oReader[1]);
        //        oReturn.IsAnonymous = oReader[2] is DBNull ? false : Convert.ToBoolean(oReader[2]);
        //        oReturn.LastActivityDate = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
        //        oReturn.Password = oReader[4] is DBNull ? "" : Convert.ToString(oReader[4]);
        //        oReturn.Email = oReader[5] is DBNull ? "" : Convert.ToString(oReader[5]);
        //        oReturn.PasswordQuestion = oReader[6] is DBNull ? "" : Convert.ToString(oReader[6]);
        //        oReturn.PasswordAnswer = oReader[7] is DBNull ? "" : Convert.ToString(oReader[7]);
        //        oReturn.IsApproved = oReader[8] is DBNull ? false : Convert.ToBoolean(oReader[8]);
        //        oReturn.IsLockedOut  = oReader[9] is DBNull ? false : Convert.ToBoolean(oReader[9]);
        //        oReturn.CreateDate = oReader[10] is DBNull ? "" : Convert.ToString(oReader[10]);
        //        oReturn.LastLoginDate = oReader[11] is DBNull ? "" : Convert.ToString(oReader[11]);
        //        oReturn.LastPasswordChangedDate = oReader[12] is DBNull ? "" : Convert.ToString(oReader[12]);
        //        oReturn.LastLockoutDate = oReader[13] is DBNull ? "" : Convert.ToString(oReader[13]);
        //        oReturn.Comment = oReader[14] is DBNull ? "" : Convert.ToString(oReader[14]);                
        //        lstUsuarios.Add(oReturn);
        //    }
        //    oCon.Close();

        //    return lstUsuarios;
        //}
        public Errores insertClase(List<Clases> lstClases)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_insert_Clase";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;


                oCommand.Parameters.Add("@intCursoId", SqlDbType.Int);
                oCommand.Parameters.Add("@vchTituloClase", SqlDbType.VarChar);
                oCommand.Parameters.Add("@vchDescClase", SqlDbType.VarChar);
                oCommand.Parameters.Add("@vchURLClase", SqlDbType.VarChar);
                oCommand.Parameters.Add("@bitActivo", SqlDbType.Bit);

                foreach (Clases oClase in lstClases)
                {
                    oCommand.Parameters["@intCursoId"].Value = oClase.intCursoId;
                    oCommand.Parameters["@vchTituloClase"].Value = oClase.vchTituloClase;
                    oCommand.Parameters["@vchDescClase"].Value = oClase.vchDescClase;
                    oCommand.Parameters["@vchURLClase"].Value = oClase.vchURLClase;
                    oCommand.Parameters["@bitActivo"].Value = oClase.bitActivo;
                }

                oCon.Open();
                if (oCommand.ExecuteNonQuery() > 0)
                {
                    oErrores.bitError = false;

                }
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }
        public Errores UpdateClases(List<Clases> lstClases)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_update_Clase";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

                //oCommand.Parameters.Add("@intCharlaId", SqlDbType.Int);
                //oCommand.Parameters.Add("@vchTitulo", SqlDbType.VarChar);
                //oCommand.Parameters.Add("@vchFecha", SqlDbType.DateTime);
                //oCommand.Parameters.Add("@vchDescripcionCorta", SqlDbType.VarChar);
                //oCommand.Parameters.Add("@vchUrl", SqlDbType.VarChar);
                //oCommand.Parameters.Add("@bitActivo", SqlDbType.Bit);

                foreach (Clases oClases in lstClases)
                {

                    oCommand.Parameters.Add("@intClaseID", SqlDbType.Int).Value = oClases.intClaseID;
                    oCommand.Parameters.Add("@vchTituloClase", SqlDbType.VarChar).Value = oClases.vchTituloClase;
                    oCommand.Parameters.Add("@vchDescClase", SqlDbType.VarChar).Value = oClases.vchDescClase;
                    oCommand.Parameters.Add("@vchURLClase", SqlDbType.VarChar).Value = oClases.vchURLClase;                    
                    oCommand.Parameters.Add("@bitActivo", SqlDbType.Bit).Value = oClases.bitActivo;

                    
                }

                oCon.Open();
                oCommand.ExecuteNonQuery();
                oErrores.bitError = false;
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }
        public List<Clases> get_ClasesByIdCurso(Cursos objCursos)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_get_ClasesbyCurso";

            List<Clases> lstClases = new List<Clases>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;

            oCommand.Parameters.Add("@intCursoId", SqlDbType.Int).Value = objCursos.intCursoId;

            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Clases oReturn = new Clases();
                oReturn.intClaseID = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.intCursoId = oReader[1] is DBNull ? 0 : Convert.ToInt32(oReader[1]);
                oReturn.vchTituloClase = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.vchDescClase = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                oReturn.vchURLClase = oReader[4] is DBNull ? "" : Convert.ToString(oReader[4]);
                oReturn.bitActivo = oReader[5] is DBNull ? false : Convert.ToBoolean(oReader[5]);
                oReturn.datFalta = oReader[6] is DBNull ? "" : Convert.ToString(oReader[6]);
                lstClases.Add(oReturn);
            }
            oCon.Close();

            return lstClases;
        }
        public List<Clases> get_Clases(Clases objClases)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_get_Clases";

            List<Clases> lstClases = new List<Clases>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;

            oCommand.Parameters.Add("@intCursoId", SqlDbType.Int).Value = objClases.intCursoId;
                                 
            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Clases oReturn = new Clases();
                oReturn.intClaseID = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.intCursoId = oReader[1] is DBNull ? 0 : Convert.ToInt32(oReader[1]);
                oReturn.vchTituloClase = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.vchDescClase = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                oReturn.vchURLClase = oReader[4] is DBNull ? "" : Convert.ToString(oReader[4]);
                oReturn.bitActivo = oReader[5] is DBNull ? false : Convert.ToBoolean(oReader[5]);
                oReturn.datFalta = oReader[6] is DBNull ? "" : Convert.ToString(oReader[6]);
                
                lstClases.Add(oReturn);
            }
            oCon.Close();

            return lstClases;
        }

        public Errores insertPago(List<Pagos> lstPagos)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Insert_Pago_Detalle";

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

                foreach (Pagos oPago in lstPagos)
                {
                    oCommand.Parameters.Add("@vchUsuario", SqlDbType.VarChar).Value = oPago.vchUsuario;
                    oCommand.Parameters.Add("@intUsuarioId", SqlDbType.Int).Value = oPago.intUsuarioId;
                    oCommand.Parameters.Add("@vchFolioPayPal", SqlDbType.VarChar).Value = oPago.vchFolioPayPal;
                    oCommand.Parameters.Add("@decMontoPago", SqlDbType.Decimal).Value = oPago.decMontoPago;
                    oCommand.Parameters.Add("@intCursoId", SqlDbType.Int).Value = oPago.intCursoId;
                    oCommand.Parameters.Add("@bitConfirmado", SqlDbType.Bit).Value = oPago.bitConfirmado;
                    oCommand.Parameters.Add("@datFechaPago", SqlDbType.Date).Value = Convert.ToDateTime(oPago.datFechaPago);
                    oCommand.Parameters.Add("@datFechaAlta", SqlDbType.Date).Value = Convert.ToDateTime(oPago.datFechaAlta);
                    oCommand.Parameters.Add("@vchEstatusPago", SqlDbType.VarChar).Value = oPago.vchEstatusPago;
                    oCommand.Parameters.Add("@vchMetodoPago", SqlDbType.VarChar).Value = oPago.vchMetodoPago;
                    oCommand.Parameters.Add("@vchCurso", SqlDbType.VarChar).Value = oPago.vchCurso;
                }

                oCon.Open();
                if (oCommand.ExecuteNonQuery() > 0)
                {
                    oErrores.bitError = false;

                }
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }

        public List<Pagos> get_AllPagos()
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_get_Pagos_Detalle";

            List<Pagos> lstPagos = new List<Pagos>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;


            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Pagos oReturn = new Pagos();
                oReturn.intPagoID = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchUsuario = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.intUsuarioId = oReader[2] is DBNull ? 0 : Convert.ToInt32(oReader[2]);
                oReturn.vchFolioPayPal = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                oReturn.decMontoPago = oReader[4] is DBNull ? 0 : Convert.ToDecimal(oReader[4]);
                oReturn.intCursoId = oReader[5] is DBNull ? 0 : Convert.ToInt32(oReader[5]);
                oReturn.bitConfirmado= oReader[6] is DBNull ? false : Convert.ToBoolean(oReader[6]);
                oReturn.datFechaPago = oReader[7] is DBNull ? "" : Convert.ToString(oReader[7]);
                oReturn.datFechaAlta = oReader[8] is DBNull ? "" : Convert.ToString(oReader[8]);
                oReturn.vchEstatusPago = oReader[9] is DBNull ? "" : Convert.ToString(oReader[9]);
                oReturn.vchMetodoPago = oReader[10] is DBNull ? "" : Convert.ToString(oReader[10]);
                oReturn.vchCurso = oReader[11] is DBNull ? "" : Convert.ToString(oReader[11]);  
                lstPagos.Add(oReturn);
            }
            oCon.Close();

            return lstPagos;
        }


        public List<Pagos> get_AllPagos_bypagoId(Pagos pago)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_get_Pagos_Detalle_By_PagoId";

            List<Pagos> lstPagos = new List<Pagos>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;

            oCommand.Parameters.Add("@intPagoID", SqlDbType.Int).Value = pago.intPagoID;

            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Pagos oReturn = new Pagos();
                oReturn.intUsuarioId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchUsuario = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.vchFolioPayPal = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.decMontoPago = oReader[3] is DBNull ? 0 : Convert.ToDecimal(oReader[3]);
                oReturn.intCursoId = oReader[4] is DBNull ? 0 : Convert.ToInt32(oReader[4]);
                oReturn.bitConfirmado = oReader[5] is DBNull ? false : Convert.ToBoolean(oReader[5]);
                oReturn.datFechaPago = oReader[6] is DBNull ? "" : Convert.ToString(oReader[6]);
                oReturn.datFechaAlta = oReader[7] is DBNull ? "" : Convert.ToString(oReader[7]);
                oReturn.vchEstatusPago = oReader[8] is DBNull ? "" : Convert.ToString(oReader[8]);
                oReturn.vchMetodoPago = oReader[9] is DBNull ? "" : Convert.ToString(oReader[9]);
                oReturn.vchCurso = oReader[10] is DBNull ? "" : Convert.ToString(oReader[10]);  
                lstPagos.Add(oReturn);
            }
            oCon.Close();

            return lstPagos;
        }


        public List<Pagos> get_AllPagos_byUsusario(Pagos pago)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_get_Pagos_Detalle_By_User";

            List<Pagos> lstPagos = new List<Pagos>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;

            oCommand.Parameters.Add("@intUsuarioId", SqlDbType.Int).Value = pago.intUsuarioId;

            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Pagos oReturn = new Pagos();
                oReturn.intUsuarioId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchUsuario = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.vchFolioPayPal = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.decMontoPago = oReader[3] is DBNull ? 0 : Convert.ToDecimal(oReader[3]);
                oReturn.intCursoId = oReader[4] is DBNull ? 0 : Convert.ToInt32(oReader[4]);
                oReturn.bitConfirmado = oReader[5] is DBNull ? false : Convert.ToBoolean(oReader[5]);
                oReturn.datFechaPago = oReader[6] is DBNull ? "" : Convert.ToString(oReader[6]);
                oReturn.datFechaAlta = oReader[7] is DBNull ? "" : Convert.ToString(oReader[7]);
                oReturn.vchEstatusPago = oReader[8] is DBNull ? "" : Convert.ToString(oReader[8]);
                oReturn.vchMetodoPago = oReader[9] is DBNull ? "" : Convert.ToString(oReader[9]);
                oReturn.vchCurso = oReader[10] is DBNull ? "" : Convert.ToString(oReader[10]);  
                lstPagos.Add(oReturn);
            }
            oCon.Close();

            return lstPagos;
        }


        public Errores DeletePago(List<Pagos> lstPagos)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_delete_Pagos_Detalle_By_User";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;


                foreach (Pagos Pago in lstPagos)
                {
                    oCommand.Parameters.Add("@intPagoID", SqlDbType.VarChar).Value = Pago.intPagoID;
                }

                oCon.Open();
                oCommand.ExecuteNonQuery();
                oErrores.bitError = false;
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }


        public Errores ConfirmPago(List<Pagos> lstPagos)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Confirm_Pagos";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;


                foreach (Pagos Pago in lstPagos)
                {
                    oCommand.Parameters.Add("@intPagoID", SqlDbType.VarChar).Value = Pago.intPagoID;
                    oCommand.Parameters.Add("@intUsuario", SqlDbType.VarChar).Value = Pago.intUsuarioId;
                    oCommand.Parameters.Add("@intCursoID", SqlDbType.VarChar).Value = Pago.intCursoId;
                
                }

                oCon.Open();
                oCommand.ExecuteNonQuery();
                oErrores.bitError = false;
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }




        public Errores insertUsuario(List<Usuarios> lstUsuarios)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Insert_Usuario";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

                foreach (Usuarios oUsuario in lstUsuarios)
                {
                    oCommand.Parameters.Add("@vchUsuario", SqlDbType.VarChar).Value = oUsuario.vchUsuario;
                    oCommand.Parameters.Add("@vchEmail", SqlDbType.VarChar).Value = oUsuario.vchEmail;
                    oCommand.Parameters.Add("@vchContrasena", SqlDbType.VarChar).Value = oUsuario.vchContrasena;
                    oCommand.Parameters.Add("@vchTelefono", SqlDbType.VarChar).Value = oUsuario.vchTelefono;
                    oCommand.Parameters.Add("@vchMovil", SqlDbType.VarChar).Value = oUsuario.vchMovil;
                    oCommand.Parameters.Add("@bitActivo", SqlDbType.Bit).Value = true;
                }

                oCon.Open();
                if (oCommand.ExecuteNonQuery() > 0)
                {
                    oErrores.bitError = false;

                }
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }


    



        public Errores UpdateUsuario(List<Usuarios> lstUsuarios)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Update_Usuario";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;

                //oCommand.Parameters.Add("@intCharlaId", SqlDbType.Int);
                //oCommand.Parameters.Add("@vchTitulo", SqlDbType.VarChar);
                //oCommand.Parameters.Add("@vchFecha", SqlDbType.DateTime);
                //oCommand.Parameters.Add("@vchDescripcionCorta", SqlDbType.VarChar);
                //oCommand.Parameters.Add("@vchUrl", SqlDbType.VarChar);
                //oCommand.Parameters.Add("@bitActivo", SqlDbType.Bit);

                foreach (Usuarios oUsuario in lstUsuarios)
                {
                    oCommand.Parameters.Add("@vchUsuario", SqlDbType.VarChar).Value = oUsuario.vchUsuario;
                    oCommand.Parameters.Add("@intUsuarioId", SqlDbType.Int).Value = oUsuario.intUsuarioId;
                    oCommand.Parameters.Add("@vchEmail", SqlDbType.VarChar).Value = oUsuario.vchEmail;
                    oCommand.Parameters.Add("@vchContrasena", SqlDbType.VarChar).Value = oUsuario.vchContrasena;
                    oCommand.Parameters.Add("@vchTelefono", SqlDbType.VarChar).Value = oUsuario.vchTelefono;
                    oCommand.Parameters.Add("@vchMovil", SqlDbType.VarChar).Value = oUsuario.vchMovil;
                    oCommand.Parameters.Add("@bitActivo", SqlDbType.Bit).Value = oUsuario.bitActivo;


                }

                oCon.Open();
                oCommand.ExecuteNonQuery();
                oErrores.bitError = false;
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }


        public List<Usuarios> get_UsuarioByEmail(Usuarios objUsuario)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Select_Usuario_byEmail";

            List<Usuarios> lstUsuario = new List<Usuarios>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;

            oCommand.Parameters.Add("@vchEmail", SqlDbType.VarChar).Value = objUsuario.vchEmail;

            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Usuarios oReturn = new Usuarios();
                oReturn.intUsuarioId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchUsuario = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.vchEmail = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.vchContrasena = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                oReturn.vchTelefono = oReader[4] is DBNull ? "" : Convert.ToString(oReader[4]);
                oReturn.vchMovil = oReader[5] is DBNull ? "" : Convert.ToString(oReader[5]);
                oReturn.bitActivo = oReader[6] is DBNull ? false : Convert.ToBoolean(oReader[6]);
                oReturn.datFalta = oReader[7] is DBNull ? "" : Convert.ToString(oReader[7]);
                oReturn.bitAdministrador = oReader[8] is DBNull ? false : Convert.ToBoolean(oReader[8]);
                lstUsuario.Add(oReturn);
            }
            oCon.Close();

            return lstUsuario;
        }        



        public List<Usuarios> get_UsuarioByUser(Usuarios objUsuario)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Select_Usuario_byUser";

            List<Usuarios> lstUsuario = new List<Usuarios>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;

            oCommand.Parameters.Add("@vchUser", SqlDbType.VarChar).Value = objUsuario.vchUsuario;

            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Usuarios oReturn = new Usuarios();
                oReturn.intUsuarioId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchUsuario = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.vchEmail = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.vchContrasena = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                oReturn.vchTelefono = oReader[4] is DBNull ? "" : Convert.ToString(oReader[4]);
                oReturn.vchMovil = oReader[5] is DBNull ? "" : Convert.ToString(oReader[5]);
                oReturn.bitActivo = oReader[6] is DBNull ? false : Convert.ToBoolean(oReader[6]);
                oReturn.datFalta = oReader[7] is DBNull ? "" : Convert.ToString(oReader[7]);
                oReturn.bitAdministrador = oReader[8] is DBNull ? false : Convert.ToBoolean(oReader[8]);

                oReturn.vchNombre           = oReader[9] is DBNull ? "" : Convert.ToString(oReader[9]);                
		       oReturn.vchApellidoPaterno	= oReader[10] is DBNull ? "" : Convert.ToString(oReader[10]);                
		       oReturn.vchApellidoMaterno	= oReader[11] is DBNull ? "" : Convert.ToString(oReader[11]);                
		       oReturn.vchFechaNacimiento	= oReader[12] is DBNull ? "" : Convert.ToString(oReader[12]);                
		       oReturn.vchSexo			    = oReader[13] is DBNull ? "" : Convert.ToString(oReader[13]);                
		       oReturn.vchCodigoPostal	    = oReader[14] is DBNull ? "" : Convert.ToString(oReader[14]);                
		       oReturn.vchDireccion		    = oReader[15] is DBNull ? "" : Convert.ToString(oReader[15]);                
		       oReturn.vchColonia			= oReader[16] is DBNull ? "" : Convert.ToString(oReader[16]);                
		       oReturn.vchCiudad			= oReader[17] is DBNull ? "" : Convert.ToString(oReader[17]);                
		       oReturn.vchEstado		    = oReader[18] is DBNull ? "" : Convert.ToString(oReader[18]);
               oReturn.vchPais              = oReader[19] is DBNull ? "" : Convert.ToString(oReader[19]);                

                lstUsuario.Add(oReturn);
            }
            oCon.Close();

            return lstUsuario;
        }
        public List<Usuarios> get_AllUsers()
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Select_Usuarios";

            List<Usuarios> lstUsuario = new List<Usuarios>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;
            

            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Usuarios oReturn = new Usuarios();
                oReturn.intUsuarioId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchUsuario = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.vchEmail = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.vchContrasena = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                oReturn.vchTelefono = oReader[4] is DBNull ? "" : Convert.ToString(oReader[4]);
                oReturn.vchMovil = oReader[5] is DBNull ? "" : Convert.ToString(oReader[5]);
                oReturn.bitActivo = oReader[6] is DBNull ? false : Convert.ToBoolean(oReader[6]);
                oReturn.datFalta = oReader[7] is DBNull ? "" : Convert.ToString(oReader[7]);
                oReturn.bitAdministrador = oReader[8] is DBNull ? false : Convert.ToBoolean(oReader[8]);
                lstUsuario.Add(oReturn);
            }
            oCon.Close();

            return lstUsuario;
        }
        public List<Cursos> get_Cursos_by_User(Usuarios objUsuario)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Select_RelUsuCur";

            List<Cursos> lstCursos = new List<Cursos>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;
            oCommand.Parameters.Add("@intUsuario", SqlDbType.Int);

            oCommand.Parameters["@intUsuario"].Value = objUsuario.intUsuarioId;


            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Cursos oReturn = new Cursos();
                oReturn.intCursoId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchTitulo = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.vchDescripcionCorta = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.vchDescripcion = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                oReturn.datFalta = oReader[7] is DBNull ? "" : Convert.ToString(oReader[7]);
                oReturn.bitActivo = oReader[8] is DBNull ? false : Convert.ToBoolean(oReader[8]);
                lstCursos.Add(oReturn);
            }
            oCon.Close();

            return lstCursos;
        }
        public List<Cursos> get_Cursos_CurNotUsu(Usuarios objUsuario)
        {

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Select_CurNotUsu";

            List<Cursos> lstCursos = new List<Cursos>();

            SqlConnection oCon = new SqlConnection(strConn);
            SqlCommand oCommand = new SqlCommand();
            SqlDataReader oReader;

            oCommand.CommandText = strProcedure;
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Connection = oCon;
            oCommand.Parameters.Add("@intUsuario", SqlDbType.Int);

            oCommand.Parameters["@intUsuario"].Value = objUsuario.intUsuarioId;


            oCon.Open();
            oReader = oCommand.ExecuteReader();

            while (oReader.Read())
            {
                Cursos oReturn = new Cursos();
                oReturn.intCursoId = oReader[0] is DBNull ? 0 : Convert.ToInt32(oReader[0]);
                oReturn.vchTitulo = oReader[1] is DBNull ? "" : Convert.ToString(oReader[1]);
                oReturn.vchDescripcionCorta = oReader[2] is DBNull ? "" : Convert.ToString(oReader[2]);
                oReturn.vchDescripcion = oReader[3] is DBNull ? "" : Convert.ToString(oReader[3]);
                oReturn.datFalta = oReader[7] is DBNull ? "" : Convert.ToString(oReader[7]);
                oReturn.bitActivo = oReader[8] is DBNull ? false : Convert.ToBoolean(oReader[8]);
                lstCursos.Add(oReturn);
            }
            oCon.Close();

            return lstCursos;
        }
        public Errores insertRelCurUsu(Usuarios oUsu, Cursos oCur)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_insert_RelUsuCur";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;


                oCommand.Parameters.Add("@intUsuario", SqlDbType.Int);
                oCommand.Parameters.Add("@intCursoId", SqlDbType.Int);


                oCommand.Parameters["@intUsuario"].Value = oUsu.intUsuarioId;
                oCommand.Parameters["@intCursoId"].Value = oCur.intCursoId;
              

                oCon.Open();
                if (oCommand.ExecuteNonQuery() > 0)
                {
                    oErrores.bitError = false;

                }
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;
        }
        public Errores DeleteRelCurUsu(Usuarios oUsu, Cursos oCur)
        {
            Errores oErrores = new Errores();
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["QuintoCamino"].ConnectionString;
            string strProcedure = "stp_Delete_RelUsuCur";

            //List<Charlas> lstCharlas = new List<Charlas>();

            try
            {
                SqlConnection oCon = new SqlConnection(strConn);
                SqlCommand oCommand = new SqlCommand();
                oCommand.CommandText = strProcedure;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Connection = oCon;


                oCommand.Parameters.Add("@intUsuario", SqlDbType.Int);
                oCommand.Parameters.Add("@intCursoId", SqlDbType.Int);


                oCommand.Parameters["@intUsuario"].Value = oUsu.intUsuarioId;
                oCommand.Parameters["@intCursoId"].Value = oCur.intCursoId;


                oCon.Open();
                if (oCommand.ExecuteNonQuery() > 0)
                {
                    oErrores.bitError = false;

                }
                oCon.Close();


            }
            catch (Exception exx)
            {
                oErrores.vchError = exx.InnerException.ToString();
                oErrores.bitError = true;
            }


            return oErrores;

        }
    }
}