private void cargaCombosListados(HORARIO hAux)
 {
     ViewBag.idGrupo     = obtenListadoGrupos(hAux);
     ViewBag.idMateria   = obtenListadoMaterias(hAux);
     ViewBag.idProfesor  = obtenListadoProfesores(hAux);
     ViewBag.idHoraClase = obtenListadoHorasClase(hAux);
 }
        // GET: Horarios/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            HORARIO hAux = db.HORARIO.Find(id);

            if (hAux == null)
            {
                return(HttpNotFound());
            }

            HorarioModel horario = new HorarioModel();

            horario.idHorario   = Convert.ToInt32(hAux.ID_HORARIO);
            horario.idGrupo     = Convert.ToInt32(hAux.ID_GRUPO);
            horario.idMateria   = Convert.ToInt32(hAux.ID_MATERIA);
            horario.idProfesor  = Convert.ToInt32(hAux.ID_PROFESOR);
            horario.idHoraClase = Convert.ToInt32(hAux.ID_HORA_CLASE);

            this.cargaDiasSemana(ref horario, hAux);
            this.cargaCombosListados();
            return(View(horario));
        }
        public ActionResult GuardarCoachHorario(HORARIO horario, string daterange, string hora)
        {
            if (!horario.DESCRIPCION.Equals("") && !daterange.Equals(""))
            {
                //split de la fecha
                string[] fechas = daterange.Split('-');
                horario.FECHA_INICIO = Convert.ToDateTime(fechas[0]);
                horario.FECHA_FIN    = Convert.ToDateTime(fechas[1]);

                // aumentar 2 horas a la hora
                DateTime dateTime = new DateTime();
                string[] horas    = hora.Split(':');
                horas[0] = (Convert.ToInt32(horas[0]) + 2).ToString();

                dateTime            = DateTime.Parse(hora);
                horario.HORA_INICIO = dateTime.TimeOfDay;

                dateTime         = DateTime.Parse(horas[0] + ":" + horas[1]);
                horario.HORA_FIN = dateTime.TimeOfDay;

                horario.RegistrarHorario();
                return(Redirect("~/Usuario/CoachHorario"));
            }
            else
            {
                return(View("/Usuario/CoachHorario"));
            }
        }
Exemple #4
0
        public async Task <IHttpActionResult> PutHORARIO(int id, HORARIO hORARIO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != hORARIO.ID)
            {
                return(BadRequest());
            }

            db.Entry(hORARIO).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HORARIOExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        private SelectList obtenListadoProfesores(HORARIO hAux)
        {
            SelectList           listado;
            List <ProfesorModel> listaProfes = new List <ProfesorModel>();

            foreach (PROFESOR pAux in db.PROFESOR)
            {
                ProfesorModel prof = new ProfesorModel();
                prof.idProfesor  = Convert.ToInt32(pAux.ID_PROFESOR);
                prof.displayText = pAux.NOMBRE1 + " ";
                if (!String.IsNullOrEmpty(pAux.NOMBRE2) && !String.IsNullOrWhiteSpace(pAux.NOMBRE2))
                {
                    prof.displayText += pAux.NOMBRE2 + " ";
                }
                prof.displayText += pAux.APELLIDO1;
                if (!String.IsNullOrEmpty(pAux.APELLIDO2) && !String.IsNullOrWhiteSpace(pAux.APELLIDO2))
                {
                    prof.displayText += " " + pAux.APELLIDO2;
                }

                listaProfes.Add(prof);
            }

            listado = new SelectList(listaProfes, "idProfesor", "displayText", hAux.ID_PROFESOR);

            return(listado);
        }
Exemple #6
0
        public ActionResult DeleteConfirmed(long id)
        {
            HORARIO hORARIO = db.HORARIO.Find(id);

            db.HORARIO.Remove(hORARIO);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #7
0
 public ActionResult Edit([Bind(Include = "ID_Horario,Tipo_Horario,Hora_Trabajo")] HORARIO hORARIO)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hORARIO).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(hORARIO));
 }
Exemple #8
0
        public ActionResult Create([Bind(Include = "ID_Horario,Tipo_Horario,Hora_Trabajo")] HORARIO hORARIO)
        {
            if (ModelState.IsValid)
            {
                db.HORARIO.Add(hORARIO);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hORARIO));
        }
Exemple #9
0
        public async Task <IHttpActionResult> GetHORARIO(int id)
        {
            HORARIO hORARIO = await db.HORARIO.FindAsync(id);

            if (hORARIO == null)
            {
                return(NotFound());
            }

            return(Ok(hORARIO));
        }
Exemple #10
0
        public async Task <IHttpActionResult> PostHORARIO(HORARIO hORARIO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.HORARIO.Add(hORARIO);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = hORARIO.ID }, hORARIO));
        }
        private HorarioModel cargaDatosHorario(HORARIO hAux)
        {
            HorarioModel h = new HorarioModel();

            h.idHorario  = Convert.ToInt32(hAux.ID_HORARIO);
            h.txtGrupo   = hAux.GRUPO.CICLO_ESCOLAR + "-" + hAux.GRUPO.SEMESTRE.ToString() + hAux.GRUPO.GRUPO1.ToString();
            h.txtMateria = hAux.MATERIA.NOMBRE;
            this.cargaNombreProfesor(ref h, hAux);
            h.txtHoraClase = hAux.HORA_CLASE.HORA_INICIO.ToString() + " - " + hAux.HORA_CLASE.HORA_FIN.ToString();
            h.diasSemana   = hAux.DIA_SEMANA;

            return(h);
        }
 private void cargaNombreProfesor(ref HorarioModel h, HORARIO hAux)
 {
     h.txtProfesor = hAux.PROFESOR.NOMBRE1 + " ";
     if (!String.IsNullOrEmpty(hAux.PROFESOR.NOMBRE2) && !String.IsNullOrWhiteSpace(hAux.PROFESOR.NOMBRE2))
     {
         h.txtProfesor += hAux.PROFESOR.NOMBRE2 + " ";
     }
     h.txtProfesor += hAux.PROFESOR.APELLIDO1;
     if (!String.IsNullOrEmpty(hAux.PROFESOR.APELLIDO2) && !String.IsNullOrWhiteSpace(hAux.PROFESOR.APELLIDO2))
     {
         h.txtProfesor += " " + hAux.PROFESOR.APELLIDO2;
     }
 }
Exemple #13
0
        // GET: HORARIOs1/Details/5
        public ActionResult Details(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HORARIO hORARIO = db.HORARIO.Find(id);

            if (hORARIO == null)
            {
                return(HttpNotFound());
            }
            return(View(hORARIO));
        }
Exemple #14
0
 public ActionResult Edit([Bind(Include = "ID_HORARIO,ID_HORA_CLASE,ID_GRUPO,ID_MATERIA,ID_PROFESOR,DIA_SEMANA")] HORARIO hORARIO)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hORARIO).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ID_GRUPO      = new SelectList(db.GRUPO, "ID_GRUPO", "CICLO_ESCOLAR", hORARIO.ID_GRUPO);
     ViewBag.ID_HORA_CLASE = new SelectList(db.HORA_CLASE, "ID_HORA_CLASE", "ID_HORA_CLASE", hORARIO.ID_HORA_CLASE);
     ViewBag.ID_MATERIA    = new SelectList(db.MATERIA, "ID_MATERIA", "NOMBRE", hORARIO.ID_MATERIA);
     ViewBag.ID_PROFESOR   = new SelectList(db.PROFESOR, "ID_PROFESOR", "NOMBRE1", hORARIO.ID_PROFESOR);
     return(View(hORARIO));
 }
Exemple #15
0
        public async Task <IHttpActionResult> DeleteHORARIO(int id)
        {
            HORARIO hORARIO = await db.HORARIO.FindAsync(id);

            if (hORARIO == null)
            {
                return(NotFound());
            }

            db.HORARIO.Remove(hORARIO);
            await db.SaveChangesAsync();

            return(Ok(hORARIO));
        }
        // GET: Horarios/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HORARIO hAux = db.HORARIO.Find(id);

            if (hAux == null)
            {
                return(HttpNotFound());
            }
            HorarioModel horario = cargaDatosHorario(hAux);

            return(View(horario));
        }
        private SelectList obtenListadoHorasClase(HORARIO hAux)
        {
            SelectList            listado;
            List <HoraClaseModel> listaHorasClase = new List <HoraClaseModel>();

            foreach (HORA_CLASE hcAux in db.HORA_CLASE)
            {
                HoraClaseModel hc = new HoraClaseModel();
                hc.idHoraClase = Convert.ToInt32(hcAux.ID_HORA_CLASE);
                hc.displayText = hcAux.HORA_INICIO.ToString("HH:mm") + " - " + hcAux.HORA_FIN.ToString("HH:mm");
                listaHorasClase.Add(hc);
            }

            listado = new SelectList(listaHorasClase, "idHoraClase", "displayText", hAux.ID_HORA_CLASE);

            return(listado);
        }
        public JsonResult DeleteHorario(int ID_HORARIO)
        {
            bool result  = false;
            var  horario = new HORARIO {
                ID_HORARIO = ID_HORARIO
            };

            if (horario != null)
            {
                db.HORARIO.Attach(horario);
                db.Entry(horario).State = EntityState.Deleted;
                db.SaveChanges();
                result = true;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        private SelectList obtenListadoMaterias(HORARIO hAux)
        {
            SelectList          listado;
            List <MateriaModel> listaMaterias = new List <MateriaModel>();

            foreach (MATERIA mAux in db.MATERIA)
            {
                MateriaModel mat = new MateriaModel();
                mat.idMateria   = Convert.ToInt32(mAux.ID_MATERIA);
                mat.displayText = mAux.NOMBRE;
                listaMaterias.Add(mat);
            }

            listado = new SelectList(listaMaterias, "idMateria", "displayText", hAux.ID_MATERIA);

            return(listado);
        }
        private SelectList obtenListadoGrupos(HORARIO hAux)
        {
            SelectList        listado;
            List <GrupoModel> listaGrupos = new List <GrupoModel>();

            foreach (GRUPO gAux in db.GRUPO)
            {
                GrupoModel gpo = new GrupoModel();
                gpo.idGrupo      = Convert.ToInt32(gAux.ID_GRUPO);
                gpo.textoDisplay = gAux.CICLO_ESCOLAR + " - " + gAux.SEMESTRE.ToString() + gAux.GRUPO1.ToString();
                listaGrupos.Add(gpo);
            }

            listado = new SelectList(listaGrupos, "idGrupo", "textoDisplay", hAux.ID_GRUPO);

            return(listado);
        }
Exemple #21
0
        // GET: HORARIOs1/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HORARIO hORARIO = db.HORARIO.Find(id);

            if (hORARIO == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ID_GRUPO      = new SelectList(db.GRUPO, "ID_GRUPO", "CICLO_ESCOLAR", hORARIO.ID_GRUPO);
            ViewBag.ID_HORA_CLASE = new SelectList(db.HORA_CLASE, "ID_HORA_CLASE", "ID_HORA_CLASE", hORARIO.ID_HORA_CLASE);
            ViewBag.ID_MATERIA    = new SelectList(db.MATERIA, "ID_MATERIA", "NOMBRE", hORARIO.ID_MATERIA);
            ViewBag.ID_PROFESOR   = new SelectList(db.PROFESOR, "ID_PROFESOR", "NOMBRE1", hORARIO.ID_PROFESOR);
            return(View(hORARIO));
        }
        private bool validaDatosUnicosGrupo(HorarioModel horario, ref String msjError)
        {
            bool valido = true;

            HORARIO hBuscar      = db.HORARIO.FirstOrDefault(h => h.ID_GRUPO == horario.idGrupo && h.ID_MATERIA == horario.idMateria && h.ID_HORARIO != horario.idHorario);
            MATERIA mBuscar      = db.MATERIA.FirstOrDefault(m => m.ID_MATERIA == horario.idMateria);
            int     horasAsignar = cuentaDiasSemana(horario);
            int     numHoras     = Convert.ToInt32(mBuscar.NUM_HORAS_CLASE);

            if (hBuscar != null)
            {
                int auxHoras = cuentaDiasSemana(hBuscar.DIA_SEMANA);

                if ((auxHoras + horasAsignar) > numHoras)
                {
                    valido = false;
                    if (auxHoras == numHoras)
                    {
                        msjError = "El grupo ya tiene asignadas todas las horas de la materia";
                    }
                    else
                    {
                        msjError = "El grupo se pasa con " + ((auxHoras + horasAsignar) - numHoras) + " horas para esta materia";
                    }
                }
                else
                {
                    if (!comparaDiasHoraClase(hBuscar.DIA_SEMANA, horario, true, ref msjError))
                    {
                        valido = false;
                    }
                }
            }
            else
            {
                if (horasAsignar > numHoras)
                {
                    valido   = false;
                    msjError = "El grupo se pasa con " + (horasAsignar - numHoras) + " horas para esta materia";
                }
            }

            return(valido);
        }
        public ActionResult Create([Bind(Include = "idGrupo,idMateria,idProfesor,idHoraClase,Lunes,Martes,Miercoles,Jueves,Viernes")] HorarioModel horario)
        {
            if (ModelState.IsValid)
            {
                try {
                    String msjError = "";
                    if (horario.Lunes || horario.Martes || horario.Miercoles || horario.Jueves || horario.Viernes)
                    {
                        if (validaDatosUnicosGrupo(horario, ref msjError))
                        {
                            if (validaDatosUnicosProfesor(horario, ref msjError))
                            {
                                HORARIO hAlta = new HORARIO();
                                hAlta.ID_GRUPO      = horario.idGrupo;
                                hAlta.ID_MATERIA    = horario.idMateria;
                                hAlta.ID_PROFESOR   = horario.idProfesor;
                                hAlta.ID_HORA_CLASE = horario.idHoraClase;
                                hAlta.DIA_SEMANA    = this.generaCadenaDias(horario);

                                db.HORARIO.Add(hAlta);
                                db.SaveChanges();
                                db.INCREMENTOHORASPROFESOR(hAlta.ID_PROFESOR, hAlta.DIA_SEMANA);
                                db.SaveChanges();
                                return(RedirectToAction("Index"));
                            }
                        }

                        ModelState.AddModelError("", msjError);
                    }
                    else
                    {
                        ModelState.AddModelError("", "Debe seleccionar al menos un día de la semana");
                    }
                }
                catch (Exception ex)
                {
                    return(RedirectToAction("NoConect", "Home"));
                }
            }

            this.cargaCombosListados();
            return(View());
        }
        public ActionResult Edit([Bind(Include = "idHorario,idGrupo,idMateria,idProfesor,idHoraClase,Lunes,Martes,Miercoles,Jueves,Viernes")] HorarioModel horario)
        {
            if (ModelState.IsValid)
            {
                try {
                    if (horario.Lunes || horario.Martes || horario.Miercoles || horario.Jueves || horario.Viernes)
                    {
                        String msjError = "";
                        if (validaDatosUnicosGrupo(horario, ref msjError))
                        {
                            if (validaDatosUnicosProfesor(horario, ref msjError))
                            {
                                HORARIO hEditado = db.HORARIO.Find(horario.idHorario);
                                String  diasAnt  = hEditado.DIA_SEMANA;
                                hEditado.ID_GRUPO        = horario.idGrupo;
                                hEditado.ID_MATERIA      = horario.idMateria;
                                hEditado.ID_PROFESOR     = horario.idProfesor;
                                hEditado.ID_HORA_CLASE   = horario.idHoraClase;
                                hEditado.DIA_SEMANA      = generaCadenaDias(horario);
                                db.Entry(hEditado).State = System.Data.Entity.EntityState.Modified;
                                db.SaveChanges();
                                db.INCDECHORASPROFESOR(hEditado.ID_PROFESOR, hEditado.DIA_SEMANA, diasAnt);
                                db.SaveChanges();
                                return(RedirectToAction("Index"));
                            }
                        }

                        ModelState.AddModelError("", msjError);
                    }
                    else
                    {
                        ModelState.AddModelError("", "Debe seleccionar al menos un día de la semana");
                    }
                }
                catch (Exception ex)
                {
                    return(RedirectToAction("NoConect", "Home"));
                }
            }

            return(View());
        }
Exemple #25
0
 public ActionResult DeleteConfirmed(long id)
 {
     try {
         HORARIO hAux = db.HORARIO.FirstOrDefault(h => h.ID_HORA_CLASE == id);
         if (hAux == null)
         {
             HORA_CLASE hORA_CLASE = db.HORA_CLASE.Find(id);
             db.HORA_CLASE.Remove(hORA_CLASE);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             return(RedirectToAction("Error", "Home"));
         }
     }
     catch (Exception ex)
     {
         return(RedirectToAction("NoConect", "Home"));
     }
 }
 public ActionResult Delete(int id)
 {
     try {
         REGISTRO_ASISTENCIA raAux = db.REGISTRO_ASISTENCIA.FirstOrDefault(ra => ra.ID_HORARIO == id);
         if (raAux == null)
         {
             HORARIO horario = db.HORARIO.Find(id);
             String  diasAnt = horario.DIA_SEMANA;
             db.HORARIO.Remove(horario);
             db.SaveChanges();
             db.DECHORASPROFESOR(id, diasAnt);
             return(RedirectToAction("Index"));
         }
         else
         {
             return(RedirectToAction("Error", "Home"));
         }
     }
     catch (Exception ex)
     {
         return(RedirectToAction("NoConect", "Home"));
     }
 }
 private void cargaDiasSemana(ref HorarioModel h, HORARIO hAux)
 {
     if (hAux.DIA_SEMANA.Contains("L"))
     {
         h.Lunes = true;
     }
     if (hAux.DIA_SEMANA.Contains("Ma"))
     {
         h.Martes = true;
     }
     if (hAux.DIA_SEMANA.Contains("Mi"))
     {
         h.Miercoles = true;
     }
     if (hAux.DIA_SEMANA.Contains("J"))
     {
         h.Jueves = true;
     }
     if (hAux.DIA_SEMANA.Contains("V"))
     {
         h.Viernes = true;
     }
 }
        public JsonResult AddHorario(ActividadVM actividadVM)
        {
            var result = false;

            try
            {
                var horario = db.HORARIO.Find(actividadVM.horario.ID_HORARIO);
                if (horario == null)
                {
                    horario = new HORARIO();
                    db.HORARIO.Add(horario);
                }
                horario.ID_ACTIVIDAD = actividadVM.ID_ACTIVIDAD;
                horario.ID_LOCACION  = actividadVM.horario.ID_LOCACION;
                horario.HORA_INICIO  = actividadVM.horario.HORA_INICIO;
                horario.HORA_FIN     = actividadVM.horario.HORA_FIN;
                horario.DIA          = (short)(Enumeradores.DIAS)Enum.Parse(typeof(Enumeradores.DIAS), actividadVM.horario.DIA, true).GetHashCode();

                if (horario.HORA_INICIO > horario.HORA_FIN)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                //si el horario esta disponible en esa locacion
                //profesor disponible en ese horario



                //// overlaps de fechas
                var query = db.HORARIO.Where(e => (DbFunctions.CreateDateTime(e.ACTIVIDAD.FECHA_INICIO.Year, e.ACTIVIDAD.FECHA_INICIO.Month, e.ACTIVIDAD.FECHA_INICIO.Day, 0, 0, 0)
                                                   <= DbFunctions.CreateDateTime(actividadVM.FECHA_FIN.Year, actividadVM.FECHA_FIN.Month, actividadVM.FECHA_FIN.Day, 0, 0, 0)) &&
                                             (DbFunctions.CreateDateTime(actividadVM.FECHA_INICIO.Year, actividadVM.FECHA_INICIO.Month, actividadVM.FECHA_INICIO.Day, 0, 0, 0)
                                              <= DbFunctions.CreateDateTime(e.ACTIVIDAD.FECHA_FIN.Year, e.ACTIVIDAD.FECHA_FIN.Month, e.ACTIVIDAD.FECHA_FIN.Day, 0, 0, 0)) && e.ACTIVIDAD.ESTADO == true);

                var t = query.Count();
                //// overlaps de horarios
                if (query.Count() > 0)
                {
                    query = query.Where(e => (DbFunctions.CreateTime(e.HORA_INICIO.Hour, e.HORA_INICIO.Minute, e.HORA_INICIO.Second)
                                              < DbFunctions.CreateTime(horario.HORA_FIN.Hour, horario.HORA_FIN.Minute, horario.HORA_FIN.Second)) &&
                                        (DbFunctions.CreateTime(horario.HORA_INICIO.Hour, horario.HORA_INICIO.Minute, horario.HORA_INICIO.Second)
                                         < DbFunctions.CreateTime(e.HORA_FIN.Hour, e.HORA_FIN.Minute, e.HORA_FIN.Second)));
                }
                t = query.Count();

                // overlops de dia
                if (query.Count() > 0)
                {
                    query = query.Where(e => (horario.DIA == e.DIA));
                }

                t = query.Count();
                //a partir de aca query tiene todos los horarios que se crusan en fecha  hora y dia
                // overlaps de profesor

                query = query.Where(e => (e.ACTIVIDAD.ID_PROFESOR == actividadVM.ID_PROFESOR) || (e.ID_LOCACION == horario.ID_LOCACION));

                t = query.Count();



                if (t > 0)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                db.SaveChanges();
                result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }