Ejemplo n.º 1
0
        public ActionResult Schools(string sortOrder, string filter, string archived, int page = 1, int pageSize = 5)
        {
            ViewBag.searchQuery  = string.IsNullOrEmpty(filter) ? "" : filter;
            ViewBag.showArchived = (archived ?? "") == "on";

            page     = page > 0 ? page : 1;
            pageSize = pageSize > 0 ? pageSize : 10;

            ViewBag.CurrentSort = sortOrder;

            IEnumerable <school> schools;
            var repository = new SchoolRepository();

            //filtered or all records
            if (string.IsNullOrEmpty(filter))
            {
                schools = repository.Get();
            }
            else
            {
                schools = repository.Get().Where(x => x.SchoolName.Contains(filter));
            }

            //Sorting order
            schools       = schools.OrderBy(x => x.SchoolName);
            ViewBag.Count = schools.Count();
            return(View(schools.ToPagedList(page, pageSize)));
        }
Ejemplo n.º 2
0
        public IActionResult SchoolFullInfo(int IDSchool)
        {
            var school          = SchoolRepository.Get(IDSchool);
            var schoolViewModel = Mapper.Map <SchoolViewModel>(school);

            return(View(schoolViewModel));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            if (args.Any())
            {
                string        fileName = string.Empty;
                string        date     = string.Empty;
                List <string> grades   = new List <string>()
                {
                    "pk", "k", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"
                };
                // There aren't nearly this many blocks in a day, but this future proofs it. It can't pull absences for blocks that dont exist
                List <int> softBlocks = new List <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
                };
                List <int> hardBlocks = new List <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
                };
                bool          allSchools           = false;
                bool          onlyPeriodAttendance = false;
                bool          onlyDailyAttendance  = false;
                List <string> options = new List <string>();

                List <string> selectedSchoolIDs = new List <string>();

                foreach (string argument in args)
                {
                    if (argument.ToLower().StartsWith("/schoolid:"))
                    {
                        foreach (string enteredID in argument.Substring(10, argument.Length - 10).Split(new char[] { ';', ',' }))
                        {
                            if (!string.IsNullOrEmpty(enteredID))
                            {
                                selectedSchoolIDs.Add(enteredID);
                            }
                        }
                    }
                    else if (argument.ToLower().StartsWith("/filename:"))
                    {
                        fileName = argument.Substring(10, argument.Length - 10);
                    }
                    else if (argument.ToLower().StartsWith("/allschools"))
                    {
                        options.Add("allschools");
                        allSchools = true;
                    }
                    else if (argument.ToLower().StartsWith("/justperiodattendance"))
                    {
                        options.Add("justperiodattendance");
                        onlyPeriodAttendance = true;
                    }
                    else if (argument.ToLower().StartsWith("/justdailyattendance"))
                    {
                        options.Add("justdailyattendance");
                        onlyDailyAttendance = true;
                    }
                    else if (argument.ToLower().StartsWith("/date:"))
                    {
                        date = argument.Substring(6, argument.Length - 6);
                        if (date.ToLower().Equals("today"))
                        {
                            date = DateTime.Today.ToString();
                        }
                        if (date.ToLower().Equals("yesterday"))
                        {
                            date = Helpers.GetPreviousBusinessDay(DateTime.Today).ToString();
                        }
                        if (date.ToLower().Equals("now"))
                        {
                            date = DateTime.Now.ToString();
                        }
                    }
                    else if (argument.ToLower().StartsWith("/logfilename:"))
                    {
                        Log.LogFileName = argument.Substring(13, argument.Length - 13);
                    }
                    else if (argument.ToLower().StartsWith("/blocks:"))
                    {
                        string        blob           = argument.Substring(8, argument.Length - 8);
                        char[]        splitChars     = { ',', ';' };
                        List <string> unparsedBlocks = blob.Split(splitChars).ToList();
                        softBlocks.Clear();
                        foreach (string s in unparsedBlocks)
                        {
                            if (!string.IsNullOrEmpty(s))
                            {
                                int parsed = 0;
                                if (int.TryParse(s, out parsed))
                                {
                                    if (parsed > 0)
                                    {
                                        softBlocks.Add(parsed);
                                    }
                                }
                            }
                        }
                    }
                    else if (argument.ToLower().StartsWith("/hardblocks:"))
                    {
                        string        blob           = argument.Substring(12, argument.Length - 12);
                        char[]        splitChars     = { ',', ';' };
                        List <string> unparsedBlocks = blob.Split(splitChars).ToList();
                        hardBlocks.Clear();
                        foreach (string s in unparsedBlocks)
                        {
                            if (!string.IsNullOrEmpty(s))
                            {
                                int parsed = 0;
                                if (int.TryParse(s, out parsed))
                                {
                                    if (parsed > 0)
                                    {
                                        hardBlocks.Add(parsed);
                                    }
                                }
                            }
                        }
                    }
                    else if (argument.ToLower().StartsWith("/grades:"))
                    {
                        string gradesRaw = argument.Substring(8, argument.Length - 8).Trim('\"').Trim();
                        grades = new List <string>();
                        Log.Info("Limiting student selection to specific grades");
                        foreach (string ss in gradesRaw.Split(','))
                        {
                            if (!string.IsNullOrEmpty(ss))
                            {
                                grades.Add(ss.ToLower());
                                Log.Info(" Adding grade \"" + ss + "\"");
                            }
                        }
                    }
                }

                if (((selectedSchoolIDs.Count <= 0) && (!allSchools)) || (string.IsNullOrEmpty(fileName)) || (string.IsNullOrEmpty(date)))
                {
                    SendSyntax();
                }
                else
                {
                    if (Config.ConfigFileExists())
                    {
                        DateTime parsedDate = Helpers.ParseDate(date);

                        try
                        {
                            Log.ToLog("----------------------------------------------------------------");
                            Log.Info("Started: " + DateTime.Now);
                            Log.Info("Date: " + date);
                            Log.Info("Output: " + fileName);
                            Log.Info("Grades: " + grades.ToCommaSeparatedString());
                            Log.Info("Soft Blocks: " + softBlocks.ToCommaSeparatedString());
                            Log.Info("Hard Blocks: " + hardBlocks.ToCommaSeparatedString());
                            Log.Info("Options: " + options.ToCommaSeparatedString());
                            Log.Info("Schools: " + (allSchools ? "ALL" : selectedSchoolIDs.ToCommaSeparatedString()));

                            Dictionary <Student, List <Absence> > studentsWithAbsences = new Dictionary <Student, List <Absence> >();
                            List <School>     selectedSchools = new List <School>();
                            AbsenceRepository absenceRepo     = new AbsenceRepository();
                            StudentRepository studentRepo     = new StudentRepository();
                            using (
                                SqlConnection connection = new SqlConnection(Config.dbConnectionString_SchoolLogic))
                            {
                                SchoolRepository schoolRepo = new SchoolRepository(connection);

                                if (allSchools)
                                {
                                    selectedSchools = schoolRepo.GetAll();
                                }
                                else
                                {
                                    selectedSchools = schoolRepo.Get(selectedSchoolIDs);
                                }

                                Log.Info("Loading students");
                                foreach (School school in selectedSchools)
                                {
                                    List <Student> schoolStudents = studentRepo.LoadForSchool(connection, school, parsedDate).Where(s => grades.Contains(s.Grade.ToLower())).ToList();

                                    if (onlyDailyAttendance && !onlyPeriodAttendance)
                                    {
                                        Log.Info("Only using daily attendance students");
                                        schoolStudents = schoolStudents.Where(s => s.IsTrackDaily == true).ToList();
                                    }

                                    if (onlyPeriodAttendance && !onlyDailyAttendance)
                                    {
                                        Log.Info("Only using period attendance students");
                                        schoolStudents = schoolStudents.Where(s => s.IsTrackDaily == false).ToList();
                                    }

                                    Log.Info("Loaded " + schoolStudents.Count + " students for school " + school.Name);

                                    int schoolAbsenceCount = 0;

                                    // Load student absences
                                    foreach (Student student in schoolStudents)
                                    {
                                        List <Absence> studentAbsences = absenceRepo.LoadAbsencesFor(connection, school, student,
                                                                                                     parsedDate, parsedDate.AddHours(23.5)).Where(abs => hardBlocks.Contains(abs.BlockNumber)).ToList();
                                        if (studentAbsences.Count > 0)
                                        {
                                            studentsWithAbsences.Add(student, studentAbsences);
                                        }
                                        schoolAbsenceCount += studentAbsences.Count;
                                    }
                                    Log.Info(" Loaded " + schoolAbsenceCount + " absences for school " + school.Name);
                                }
                            }

                            Log.Info("Creating CSV data");

                            MemoryStream csvContents = AbsenceCSV.GenerateCSV(studentsWithAbsences, softBlocks);
                            Log.Info("Saving CSV file (" + fileName + ")");
                            if (FileHelpers.FileExists(fileName))
                            {
                                FileHelpers.DeleteFile(fileName);
                            }
                            FileHelpers.SaveFile(csvContents, fileName);
                            Log.Info("Done!");
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.Message);
                        }
                    }
                    else
                    {
                        Log.Error("Configuration file not found");
                        Log.Info("Creating new config file (" + Config.configFileName + ")...");
                        Log.Info("Please edit the file and try again");
                        Config.CreateNewConfigFile();
                    }
                }
            }
            else
            {
                // If any argument is missing, send the syntax
                SendSyntax();
            }
        }
 public School Get(int id)
 {
     return(repository.Get(id));
 }
 public School GetSchool(int teacherid)
 {
     var teacher = teacherRepository.Get(teacherid);
     return schoolRepository.Get(teacher.SchoolId);
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            if (args.Any())
            {
                string        fileName = string.Empty;
                string        date     = string.Empty;
                List <string> grades   = new List <string>()
                {
                    "pk", "k", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"
                };
                bool          allSchools = false;
                List <string> options    = new List <string>();

                List <string> selectedSchoolIDs = new List <string>();

                foreach (string argument in args)
                {
                    if (argument.ToLower().StartsWith("/schoolid:"))
                    {
                        foreach (string enteredID in argument.Substring(10, argument.Length - 10).Split(new char[] { ';', ',' }))
                        {
                            if (!string.IsNullOrEmpty(enteredID))
                            {
                                selectedSchoolIDs.Add(enteredID);
                            }
                        }
                    }
                    else if (argument.ToLower().StartsWith("/allschools"))
                    {
                        options.Add("allschools");
                        allSchools = true;
                    }
                    else if (argument.ToLower().StartsWith("/filename:"))
                    {
                        fileName = argument.Substring(10, argument.Length - 10);
                    }
                    else if (argument.ToLower().StartsWith("/logfilename:"))
                    {
                        Log.LogFileName = argument.Substring(13, argument.Length - 13);
                    }
                    else if (argument.ToLower().StartsWith("/date:"))
                    {
                        date = argument.Substring(6, argument.Length - 6);
                        if (date.ToLower().Equals("today"))
                        {
                            date = DateTime.Today.ToString();
                        }
                        if (date.ToLower().Equals("yesterday"))
                        {
                            date = Helpers.GetPreviousBusinessDay(DateTime.Today).ToString();
                        }
                        if (date.ToLower().Equals("now"))
                        {
                            date = DateTime.Now.ToString();
                        }
                    }
                    else if (argument.ToLower().StartsWith("/grades:"))
                    {
                        string gradesRaw = argument.Substring(8, argument.Length - 8).Trim('\"').Trim();
                        grades = new List <string>();
                        Log.ToLog("Limiting student selection to specific grades");
                        foreach (string ss in gradesRaw.Split(','))
                        {
                            if (string.IsNullOrEmpty(ss))
                            {
                                grades.Add(ss.ToLower());

                                Log.ToLog(" Adding grade \"" + ss + "\"");
                            }
                        }
                    }
                }

                if (((selectedSchoolIDs.Count <= 0) && (!allSchools)) || (string.IsNullOrEmpty(fileName)) || (string.IsNullOrEmpty(date)))
                {
                    SendSyntax();
                }
                else
                {
                    if (Config.ConfigFileExists())
                    {
                        DateTime parsedDate = Helpers.ParseDate(date);

                        try
                        {
                            Log.ToLog("----------------------------------------------------------------");
                            Log.Info("Started: " + DateTime.Now);
                            Log.Info("Date: " + date);
                            Log.Info("Output: " + fileName);
                            Log.Info("Grades: " + grades.ToCommaSeparatedString());
                            Log.Info("Options: " + options.ToCommaSeparatedString());
                            Log.Info("Schools: " + (allSchools ? "ALL" : selectedSchoolIDs.ToCommaSeparatedString()));

                            List <Student> reportStudents  = new List <Student>();
                            List <School>  selectedSchools = new List <School>();

                            ContactRepository contactRepo = new ContactRepository();
                            StudentRepository studentRepo = new StudentRepository();
                            using (SqlConnection connection = new SqlConnection(Config.dbConnectionString_SchoolLogic))
                            {
                                SchoolRepository schoolRepo = new SchoolRepository(connection);

                                if (allSchools)
                                {
                                    selectedSchools = schoolRepo.GetAll();
                                }
                                else
                                {
                                    selectedSchools = schoolRepo.Get(selectedSchoolIDs);
                                }

                                Log.Info("Loading students");
                                foreach (School school in selectedSchools)
                                {
                                    List <Student> schoolStudents = studentRepo.LoadForSchool(connection, school,
                                                                                              parsedDate).Where(s => grades.Contains(s.Grade.ToLower())).ToList();

                                    Log.Info("Loaded " + schoolStudents.Count + " students for school " +
                                             school.Name);

                                    // Load student contacts
                                    Log.Info("Loading student contacts");
                                    foreach (Student student in schoolStudents)
                                    {
                                        student.Contacts = contactRepo.LoadForStudent(connection, student.DatabaseID);
                                    }
                                    reportStudents.AddRange(schoolStudents);
                                }
                            }


                            Log.Info("Creating CSV data");
                            MemoryStream csvContents = AddressBookCSV.GenerateCSV(reportStudents);
                            Log.Info("Saving CSV file (" + fileName + ")");
                            if (FileHelpers.FileExists(fileName))
                            {
                                FileHelpers.DeleteFile(fileName);
                            }
                            FileHelpers.SaveFile(csvContents, fileName);
                            Log.Info("Done!");
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.Message);
                        }
                    }
                    else
                    {
                        Log.Error("Configuration file not found");
                        Log.Info("Creating new config file (" + Config.configFileName + ")...");
                        Log.Info("Please edit the file and try again");
                        Config.CreateNewConfigFile();
                    }
                }
            }
            else
            {
                // If any argument is missing, send the syntax
                SendSyntax();
            }
        }
Ejemplo n.º 7
0
        public static IEnumerable <School> Get(Guid userId, Guid groupId, IEnumerable <Guid> listSchoolSuperior, IEnumerable <int> listClassificationTypeSchool)
        {
            var repository = new SchoolRepository();

            return(repository.Get(userId, groupId, listSchoolSuperior, listClassificationTypeSchool));
        }