예제 #1
0
        public static List <Class> List(Guid idTeacher)
        {
            try
            {
                if (idTeacher == null || Equals(idTeacher, Guid.Empty))
                {
                    throw new Exception("Parâmetro inválido");
                }

                List <GridData> rows = null;

                using (Entities db = new Entities())
                {
                    rows = db.GridData
                           .Where(g => g.DeleteDate == null && g.IdTeacher == idTeacher)
                           .ToList();
                }

                if (rows.Count < 1)
                {
                    return(new List <Class>());
                }

                List <Grid> grids = rows.Select(x => GridDAO.Convert(x)).ToList();

                List <Class> list = grids
                                    .Select(x => x.Class)
                                    .GroupBy(x => new { x.IdClass, x.Name })
                                    .Select(x => x.First())
                                    .OrderBy(x => x.Name)
                                    .ToList();

                return(list);
            }
            catch (Exception e)
            {
                string notes = LogHelper.Notes(idTeacher, e.Message);
                Log.Add(Log.TYPE_ERROR, "SistemaMatricula.DAO.ClassDAO.List.ByTeacher", notes);
            }

            return(null);
        }
예제 #2
0
        public static List <Registry> GridList(Guid idStudent, Guid idCourse)
        {
            try
            {
                if (idStudent == null || Equals(idStudent, Guid.Empty))
                {
                    throw new Exception("Parâmetro 'idStudent' vazio");
                }

                if (idCourse == null || Equals(idCourse, Guid.Empty))
                {
                    throw new Exception("Parâmetro 'idCourse' vazio");
                }

                Semester semester = SemesterDAO.Last();

                if (semester == null)
                {
                    throw new Exception("Semestre não encontrado");
                }

                List <GridData> grid = null;

                using (Entities db = new Entities())
                {
                    grid = db.GridData
                           .Where(g => g.DeleteDate == null &&
                                  db.SemesterData
                                  .Where(s => s.InitialDate == semester.InitialDate)
                                  .Select(s => s.IdSemester)
                                  .Contains(g.IdSemester) &&
                                  !db.RegistryData
                                  .Where(r => r.DeleteDate == null && r.IdStudent == idStudent)
                                  .Select(r => r.IdGrid)
                                  .Contains(g.IdGrid) &&
                                  db.ClassData
                                  .Where(c => c.IdCourse == idCourse)
                                  .Select(c => c.IdClass)
                                  .Contains(g.IdClass) &&
                                  g.Status.Trim() == Grid.RELEASED)
                           .ToList();
                }

                if (grid.Count < 1)
                {
                    return(new List <Registry>());
                }

                Student student = StudentDAO.Find(idStudent);

                List <Registry> list = grid
                                       .Select(x => new Registry()
                {
                    Grid = GridDAO.Convert(x), Student = student
                })
                                       .OrderBy(x => x.Grid.Semester.Name)
                                       .ThenBy(x => x.Grid.Weekday)
                                       .ThenBy(x => x.Grid.Time)
                                       .ToList();

                return(list);
            }
            catch (Exception e)
            {
                object[] parameters = { idStudent, idCourse };
                string   notes      = LogHelper.Notes(parameters, e.Message);
                Log.Add(Log.TYPE_ERROR, "SistemaMatricula.DAO.RegistryDAO.GridList", notes);
            }

            return(null);
        }