///<summary>
        ///Insertar registro en tblMesaTrabParticipante
        /// </summary>
        public bool agregarMesaParticipante(int folio, int idmesaEvento)
        {
            bool agrego = false;

            try
            {
                using (var db = new SeguimientoPermanenciaEntities())
                {
                    tblMesaTrabParticipante newMesaTPart = new tblMesaTrabParticipante()
                    {
                        folioParticipante = folio,
                        idMesaTrab        = idmesaEvento,
                    };
                    db.tblMesaTrabParticipante.Add(newMesaTPart);
                    db.SaveChanges();
                }
                agrego = true;
            }
            catch (Exception)
            {
                agrego = false;
            }

            return(agrego);
        }
        /// <summary>
        /// Inscripción a una mesa de trabajo a través de la carga masiva
        /// Utilizando una lista con id de mesas de trabajo a las cual se inscribe
        /// </summary>
        /// <returns></returns>
        public bool agregarMesaParticipanteMasivo(int folio, List <int> listaIDmesa)
        {
            bool agrego                = true;
            int  idEvento              = 0;
            RegistroEventoDAL dalReg   = new RegistroEventoDAL();
            MesaEventoDAL     dalMesaE = new MesaEventoDAL();

            try
            {
                using (var db = new SeguimientoPermanenciaEntities())
                {
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            tblMesaTrabParticipante newMesaTPart = new tblMesaTrabParticipante();
                            foreach (var itemL in listaIDmesa)
                            {
                                newMesaTPart.folioParticipante = folio;
                                newMesaTPart.idMesaTrab        = itemL;
                                db.tblMesaTrabParticipante.Add(newMesaTPart);
                                db.SaveChanges();

                                //validar cantidad permitida de participantes en la mesa de trabajo
                                foreach (var item in dalReg.getRegistroEXfolio(folio))
                                {
                                    idEvento = item.idEvento;
                                }
                                if (validarRegistroMesaT(idEvento, itemL) == false)
                                {
                                    agrego = false;
                                    transaction.Rollback();
                                    break;
                                }
                            }
                            if (agrego == true)
                            {
                                transaction.Commit();
                            }
                        }
                        catch
                        {
                            agrego = false;
                            transaction.Rollback();
                        }
                    }
                }
            }
            catch (Exception)
            {
                agrego = false;
            }

            return(agrego);
        }
Beispiel #3
0
        ///<summary>
        ///Insertar Registro en tblRegistroEvento para Registro INDIVIDUAL
        /// </summary>
        public string agregarUserEnalceEve(int idEvento, string idTR, string cct, string nomplantel, string municipio, string regSEG, string nivel, string instisub, string curp, string nom, string ap1, string ap2, string email, string tel, string sexo, string funcion, List <int> listaIDmesa)
        {
            string              agrego        = "";
            bool                error         = false;
            bool                MT            = false;
            CampoEventoDAL      cEventoDAL    = new CampoEventoDAL();
            MesaParticipanteDAL mpDAL         = new MesaParticipanteDAL();
            MesaParticipanteML  modelMesaPart = new MesaParticipanteML();

            try
            {
                using (var db = new SeguimientoPermanenciaEntities())
                {
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        tblRegistroEvento newRegEvento = new tblRegistroEvento();
                        newRegEvento.idEvento       = idEvento;
                        newRegEvento.idTipoRegistro = idTR;
                        List <string> listaCampos = cEventoDAL.camposEvento(idEvento);
                        foreach (var item in listaCampos)
                        {
                            model.listaRegistroEvento = (from re in db.tblRegistroEvento where re.idEvento == idEvento && re.CCT == cct select re).ToList();
                            int cant = model.listaRegistroEvento.Count;
                            int cantidadRegistrada = cant + 1;

                            switch (item)
                            {
                            case "CCT":
                                if (cantidadRegEscuelaCCT(idEvento, cct, cantidadRegistrada) == true)
                                {
                                    newRegEvento.CCT = cct;    //Si aun acepta la cantidad se agrega
                                }
                                else
                                {
                                    error  = true;
                                    agrego = "Falla en el registro. No hay lugares disponiles para la CCT elegida.";
                                }
                                break;

                            case "nombrePlantel":
                                newRegEvento.nombrePlantel = nomplantel;
                                break;

                            case "municipio":
                                newRegEvento.municipio = municipio;
                                break;

                            case "regionSEG":
                                newRegEvento.regionSEG = regSEG;
                                break;

                            case "nivel":
                                newRegEvento.nivel = nivel;
                                break;

                            case "instiSubsis":
                                if (cantidadRegSubsis(idEvento, instisub, cantidadRegistrada) == true)
                                {
                                    newRegEvento.instiSubsis = instisub;
                                }
                                else
                                {
                                    error  = true;
                                    agrego = "Falla en el registro. No hay lugares disponiles para la Institución/Subsistema elegido.";
                                }
                                break;

                            case "CURP":
                                newRegEvento.CURP = curp;
                                break;

                            case "nombre":
                                newRegEvento.nombre = nom;
                                break;

                            case "apellidoPat":
                                newRegEvento.apellidoPat = ap1;
                                break;

                            case "apellidoMat":
                                newRegEvento.apellidoMat = ap2;
                                break;

                            case "correoElectronico":
                                newRegEvento.correoElectronico = email;
                                break;

                            case "telefono":
                                newRegEvento.telefono = tel;
                                break;

                            case "sexo":
                                newRegEvento.sexo = sexo;
                                break;

                            case "funcion":
                                newRegEvento.funcion = funcion;
                                break;

                            case "MT":
                                MT = true;    //Existe Mesa de trabajo
                                break;
                            }
                        }


                        db.tblRegistroEvento.Add(newRegEvento);
                        db.SaveChanges();

                        int f = newRegEvento.folio;
                        if (MT == true)
                        {
                            //transaction.Commit();
                            if (listaIDmesa.Count > 0)
                            {
                                foreach (var item in listaIDmesa)
                                {
                                    //f = item;
                                    tblMesaTrabParticipante newMesaTPart = new tblMesaTrabParticipante
                                    {
                                        folioParticipante = f,
                                        idMesaTrab        = item
                                    };
                                    db.tblMesaTrabParticipante.Add(newMesaTPart);
                                    db.SaveChanges();

                                    int cantidadRegistrada = 0;
                                    modelMesaPart.listaMesaParticipante = (from mtp in db.tblMesaTrabParticipante join r in db.tblRegistroEvento on mtp.folioParticipante equals r.folio where mtp.idMesaTrab == item && r.idEvento == idEvento select mtp).ToList();
                                    cantidadRegistrada = modelMesaPart.listaMesaParticipante.Count;
                                    MesaEventoDAL mesaEdal         = new MesaEventoDAL();
                                    int           cantidadAceptada = mesaEdal.cantidadAceptadaMesaT(idEvento, item);
                                    if ((cantidadRegistrada <= cantidadAceptada) == false)
                                    {
                                        error  = true;
                                        agrego = "No fue posible realizar el registro a la mesa de trabajo, no hay espacio.";
                                        break;
                                    }
                                }
                            }
                        }

                        if (error == true)
                        {
                            transaction.Rollback();
                        }
                        else
                        {
                            agrego = f.ToString();
                            transaction.Commit();
                        }
                    }
                }
            }
            catch (Exception)
            {
                agrego = "false";
            }

            return(agrego);
        }
        //Para registrar la mesa de trabajo del participante
        /// <summary>
        /// Nuevo registro en tblMesaTrabParticipante
        /// Es una transacción utilizada para el registro masivo
        /// Obtiene el folio y el idMesa de la lista 'listaFolioIdMT'
        /// Valida las cantidades aceptadas por registro a cada mesa de trabajo, en caso de no
        /// haber lugar para registrar a la mesa de trabajo se realiza un RollBack
        /// </summary>
        /// <param name="listaFolioIdMT"></param>
        /// <param name="idEvento"></param>
        /// <returns>true=Registro Exitoso || false=Error en el registro</returns>
        public bool agregarMesaParticipanteMasivo(List <string[, ]> listaFolioIdMT, int idEvento)//int folio, string listaIDmesa
        {
            bool agrego = true;
            //string retorno = "";
            //int idEvento = 1;
            RegistroEventoDAL dalReg   = new RegistroEventoDAL();
            MesaEventoDAL     dalMesaE = new MesaEventoDAL();

            //MesaEventoDAL mesaEdal = new MesaEventoDAL();

            //split para obtener del string listaIDmesa los id de la mesa de trabajo

            try
            {
                using (var db = new SeguimientoPermanenciaEntities())
                {
                    using (DbContextTransaction transaction = db.Database.BeginTransaction()) //Comienza Transacción
                    {
                        foreach (var listaItem in listaFolioIdMT)                             //Ciclo, en la lista se encuentras los folios y las mesas de trabajo en las cuales participaran
                        {
                            string listaIDmesa = listaItem[0, 1];
                            int    folio       = int.Parse(listaItem[0, 0]);

                            string[] splitIdMT = listaIDmesa.Split(',');

                            if (splitIdMT[0] != "")
                            {
                                try
                                {
                                    for (int i = 0; i < splitIdMT.Length; i++)
                                    {
                                        int           MT = int.Parse(splitIdMT[i]);
                                        int           cantidadRegistrada = (from mtp in db.tblMesaTrabParticipante where mtp.idMesaTrab == MT select mtp).Count();//Obtiene la cantidad registrada, el dato será utilizado para validar si se pueden realizar o no más registros a la MT
                                        MesaEventoDAL mesaEdal           = new MesaEventoDAL();
                                        int           cantidadAceptada   = mesaEdal.cantidadAceptadaMesaT(idEvento, MT);


                                        tblMesaTrabParticipante newMesaTPart = new tblMesaTrabParticipante();
                                        newMesaTPart.folioParticipante = folio;
                                        newMesaTPart.idMesaTrab        = MT;
                                        db.tblMesaTrabParticipante.Add(newMesaTPart);
                                        db.SaveChanges();

                                        //agrego = "CR "+cantidadRegistrada.ToString() + " CA" + cantidadAceptada.ToString()+" "+idEvento.ToString()+" "+MT.ToString();
                                        if ((cantidadRegistrada + i + 1 <= cantidadAceptada) == false)//En caso de no aceptar mas participantes para la mesa de trabajo se realiza un RollBack
                                        {
                                            agrego = false;
                                            transaction.Rollback();
                                            break;
                                        }
                                    }
                                }
                                catch
                                {
                                    agrego = false;
                                    transaction.Rollback();
                                }
                            }
                            if (agrego == false)
                            {
                                break;
                            }
                        }
                        if (agrego == true)
                        {
                            transaction.Commit();
                        }
                    }
                }
            }
            catch (Exception)
            {
                agrego = false;
            }

            return(agrego);
        }