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()} -" +
public async Task <List <Horarios> > MostrarHorarios(string dia, int materiaId, int cursoId) { try { var horas = Diccionarios.MostrarHoras(); dia = dia.Equals("Miércoles") ? "x" : dia; 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 where t0.CursoId == cursoId && t2.MateriaId == materiaId && t1.HoraIni.StartsWith(dia.Substring(0, 1)) select new Horarios { 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(); _horario.Id = temp.Id; _horario.Horario = ($" {horas.Where(w => w.Key.Contains(temp.HoraIni.Substring(2))).Select(s => s.Value).FirstOrDefault()} -" + $" {horas.Where(w => w.Key.Contains(temp.HoraFin.Substring(2))).Select(s => s.Value).FirstOrDefault()}"); horarios.Add(_horario); } return(horarios); } #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 }