Exemplo n.º 1
0
 public async Task <List <Horarios> > MostrarEnlaceProfesorHorario(string documento)
 {
     try
     {
         var horas      = Diccionarios.MostrarHoras();
         var diasSemana = Diccionarios.MostrarDias();
         var _horarios  = await(from t0 in context.Col_Cursos
                                join t1 in context.Col_Horarios on t0.CursoId equals t1.CursoId
                                join t2 in context.Col_Materias on t1.MateriaId equals t2.MateriaId
                                join t3 in context.Col_Personas on t1.PersonaId equals t3.PersonaId
                                where t3.NumeroDocumento.Equals(documento) || t3.PersonaId.Equals(Convert.ToInt32(documento))
                                select new Horarios
         {
             Curso   = t0.Nombre,
             Materia = t2.Nombre,
             HoraFin = t1.HoraFin,
             HoraIni = t1.HoraIni,
             Id      = t1.HorarioId
         }).ToListAsync();
         List <Horarios> horarios = new List <Horarios>();
         foreach (var temp in _horarios)
         {
             Horarios _horario = new Horarios
             {
                 Id      = temp.Id,
                 Curso   = temp.Curso,
                 Materia = temp.Materia,
                 Dia     = diasSemana.Where(w => w.Key.StartsWith(temp.HoraIni.Substring(0, 1))).Select(s => s.Value).FirstOrDefault(),
                 Horario = $" {horas.Where(w => w.Key.Contains(temp.HoraIni[2..])).Select(s => s.Value).FirstOrDefault()} -" +
Exemplo n.º 2
0
        public async Task <List <Col_Horarios> > MostrarDiasSemana(int materiaId, int cursoId)
        {
            try
            {
                var diasSemana = Diccionarios.MostrarDias();
                var _dias      = await(from t0 in context.Col_Materias
                                       join t1 in context.Col_Horarios on t0.MateriaId equals t1.MateriaId
                                       join t2 in context.Col_Cursos on t1.CursoId equals t2.CursoId
                                       where t2.CursoId == cursoId && t0.MateriaId == materiaId
                                       select new Col_Horarios
                {
                    HorarioId = t1.HorarioId,
                    HoraIni   = t1.HoraIni,
                }).ToListAsync();

                List <Col_Horarios> dias = new List <Col_Horarios>();
                foreach (var item in _dias.GroupBy(g => g.HoraIni.Substring(0, 1)))
                {
                    Col_Horarios dia = new Col_Horarios();
                    dia.HorarioId = item.Select(s => s.HorarioId).FirstOrDefault();
                    dia.Dia       = diasSemana.Where(w => w.Key.StartsWith(item.Select(s => s.HoraIni.Substring(0, 1)).FirstOrDefault()))
                                    .Select(s => s.Value).FirstOrDefault();
                    dias.Add(dia);
                }
                return(dias.OrderBy(o => o.Dia).ToList());
            }
            #region catch
            catch (DbEntityValidationException e)
            {
                string err = "";
                foreach (DbEntityValidationResult eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (DbValidationError ve in eve.ValidationErrors)
                    {
                        err += ve.ErrorMessage;
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                return(null);
            }

            catch (Exception e)
            {
                string err = "";
                if (e.InnerException != null)
                {
                    if (e.InnerException.Message != null)
                    {
                        err = (e.InnerException.Message);
                        if (e.InnerException.InnerException != null)
                        {
                            err += e.InnerException.InnerException.Message;
                        }
                    }
                }
                else
                {
                    err = (e.Message);
                }
                return(null);
            }
            #endregion
        }