Exemplo n.º 1
0
        public ADUser(Fingerprint fp)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                Fingerprint print = db.Fingerprints.Find(fp.Id);

                if (print.FacultyOwners.Count == 1)
                {
                    Faculty faculty = print.FacultyOwners.Single();
                    UserName = faculty.UserName;
                }
                else if (print.StudentOwners.Count == 1)
                {
                    Student student = print.StudentOwners.Single();
                    UserName = student.UserName;
                }
                else
                {
                    throw new System.IO.InvalidDataException("Invalid use of Fingerprint.");
                }

                Authenticated = true;
                _History      = new List <string>();
            }
        }
Exemplo n.º 2
0
        private void ReloadTables()
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                Section section = db.Sections.Where(sec => sec.id == SectionID).Single();


                RemoveTeacherDDL.DataSource = (from teacher in section.Teachers
                                               orderby teacher.LastName, teacher.FirstName
                                               select new
                {
                    Name = teacher.FirstName + " " + teacher.LastName,
                    ID = teacher.ID
                }).ToList();
                RemoveTeacherDDL.DataTextField  = "Name";
                RemoveTeacherDDL.DataValueField = "ID";
                RemoveTeacherDDL.DataBind();

                StudentTable.Rows.Clear();

                StudentGroupSelector1.AddStudent(section.Students.OrderBy(st => st.LastName).ThenBy(st => st.FirstName).Select(s => s.ID).ToList());
                foreach (Student student in section.Students.OrderBy(st => st.LastName).ThenBy(st => st.FirstName))
                {
                    TableRow  row  = new TableRow();
                    TableCell cell = new TableCell();
                    cell.Text = String.Format("{0} {1}", student.FirstName, student.LastName);
                    row.Cells.Add(cell);
                    StudentTable.Rows.Add(row);
                }
            }
        }
Exemplo n.º 3
0
        public IHttpActionResult GetCommentHeaderForSection(int section_id)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                Section section = db.Sections.Find(section_id);
                if (section == null)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException("Invalid Section Id."))));
                }

                WebhostUserPrinciple principal = (WebhostUserPrinciple)ActionContext.RequestContext.Principal;
                int id = ((WebhostIdentity)principal.Identity).User.Id;

                Faculty self = db.Faculties.Find(id);

                if (!self.Sections.Contains(section))
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new UnauthorizedAccessException("You are not a teacher for this class."))));
                }

                int termId = DateRange.GetCurrentOrLastTerm();

                if (section.CommentHeaders.Where(h => h.TermIndex == termId).Count() <= 0)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NoContent, new ArgumentException("No Comment Header for this Term is saved."))));
                }

                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, new CommentHeaderInfo(section.CommentHeaders.Where(h => h.TermIndex == termId).Single().id), "text/json")));
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                using (WebhostEntities db = new WebhostEntities())
                {
                    List <int> indep = new List <int>();
                    List <int> lib   = new List <int>();
                    List <int> super = new List <int>();

                    foreach (Student student in db.Students.Where(s => s.isActive))
                    {
                        switch (student.AcademicLevel)
                        {
                        case 3: indep.Add(student.ID); break;

                        case 2: lib.Add(student.ID); break;

                        default: super.Add(student.ID); break;
                        }

                        IndependentSelector.AddStudent(indep);
                        LibrarySelector.AddStudent(lib);
                        SupervisedSelector.AddStudent(super);
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected void SaveBtn_Click(object sender, EventArgs e)
        {
            if (DormId == -1)
            {
                return;
            }
            using (WebhostEntities db = new WebhostEntities())
            {
                Dorm dorm = db.Dorms.Where(d => d.id == DormId).Single();

                dorm.DormHeadId = Convert.ToInt32(DormHeadSelector.SelectedValue);

                dorm.DormParents.Clear();
                foreach (int id in DormParentSelector.GroupIds)
                {
                    Faculty faculty = db.Faculties.Where(f => f.ID == id).Single();
                    dorm.DormParents.Add(faculty);
                }

                dorm.Students.Clear();
                foreach (int id in StudentSelector.GroupIds)
                {
                    Student student = db.Students.Where(s => s.ID == id).Single();
                    dorm.Students.Add(student);
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 6
0
        static void RandomlyAssignStudents(int activityId, int numberOfStudents)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                List <int> studentIds = db.Students.Where(s => s.GraduationYear > DateTime.Now.Year).Select(s => s.ID).ToList();
                Random     rand       = new Random();
                for (int i = 0; i < numberOfStudents; i++)
                {
                    int sid = studentIds[rand.Next(studentIds.Count)];
                    studentIds.Remove(sid);

                    StudentSignup newSignup = new StudentSignup()
                    {
                        ActivityId  = activityId,
                        StudentId   = sid,
                        IsBanned    = false,
                        IsRescended = false,
                        TimeStamp   = DateTime.Now.AddMinutes(rand.Next(30))
                    };
                    Console.WriteLine("Added {0} to {1}", sid, activityId);
                    db.StudentSignups.Add(newSignup);
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 7
0
        public CommentReviewPDF(int sectionId, int termId)
        {
            Letters = new List <CommentLetter>();
            using (WebhostEntities db = new WebhostEntities())
            {
                Section section = db.Sections.Find(sectionId);
                if (section == null)
                {
                    WebhostEventLog.CommentLog.LogError("Failed to locate section {0} for comment review.", sectionId);
                    throw new ArgumentException(String.Format("Invalide Section Id {0}", sectionId));
                }

                Title = String.Format("Comment Proofs [{0}] {1}", section.Block.LongName, section.Course.Name);

                CommentHeader Header;
                try
                {
                    Header = section.CommentHeaders.Where(h => h.TermIndex == termId).Single();
                }
                catch (Exception e)
                {
                    WebhostEventLog.CommentLog.LogError(String.Format("Failed to locate Header Paragraph:  {0}", e.Message));
                    throw new ArgumentException("Failed to locate Header Paragraph", e);
                }

                HeaderHTML = Header.HTML;

                foreach (int id in Header.StudentComments.Select(c => c.id).ToList())
                {
                    Letters.Add(new CommentLetter(id));
                }
            }
        }
        /// <summary>
        /// If there are duplicates of a course request.  Trash them.
        /// </summary>
        /// <param name="termId"></param>
        public static void CleanDuplicateCourseRequests(int termId)
        {
            using(WebhostEntities db = new WebhostEntities())
            {
                List<CourseRequest> Okay = new List<CourseRequest>();
                List<CourseRequest> Duplicates = new List<CourseRequest>();
                foreach(CourseRequest cr in db.CourseRequests.Where(cr => cr.TermId == termId && !cr.RequestableCourse.Course.BlackBaudID.Equals("NONE")).ToList())
                {
                    if(Okay.Where(c => c.StudentId == cr.StudentId && c.RequestableCourse.CourseId == cr.RequestableCourse.CourseId).Count() > 0)
                    {
                        Duplicates.Add(cr);
                    }
                    else
                    {
                        Okay.Add(cr);
                    }
                }

                foreach(CourseRequest dup in Duplicates)
                {
                    foreach(APRequest req in dup.APRequests.ToList())
                    {
                        req.Sections.Clear();
                        db.APRequests.Remove(req);
                    }

                    db.CourseRequests.Remove(dup);
                }

                db.SaveChanges();
            }
        }
        /// <summary>
        /// Get a CSV of a particular Student's course requests along with their current courses.
        /// </summary>
        /// <param name="termId"></param>
        /// <param name="studentId"></param>
        /// <returns></returns>
        public static CSV StudentCourseRequests(int termId, int studentId)
        {
            CSV csv = new CSV();
            using(WebhostEntities db = new WebhostEntities())
            {
                Student student = db.Students.Where(s => s.ID == studentId).Single();
                foreach(Section section in student.Sections.Where(sec => sec.Terms.Where(t => t.id == termId).Count() > 0).ToList())
                {
                    csv.Add(new Dictionary<String, String>()
                        {
                            {"Block", section.Block.Name},
                            {"Course", section.Course.Name},
                            {"Full Year", section.Course.LengthInTerms > 1?"X":""}
                        });
                }

                foreach(CourseRequest request in student.CourseRequests.Where(cr => cr.TermId == termId).ToList())
                {
                    String priority = request.IsGlobalAlternate ? "Third Choice" : request.IsSecondary ? "Second Choice" : "First Choice";
                    csv.Add(new Dictionary<String, String>()
                        {
                            {"Block","Request"},
                            {"Course", request.RequestableCourse.Course.Name},
                            {priority, "X"}
                        });
                }
            }
            return csv;
        }
        new protected void Page_Init(object sender, EventArgs e)
        {
            base.Page_Init(sender, e);
            using (WebhostEntities db = new WebhostEntities())
            {
                int ay = DateRange.GetCurrentAcademicYear();
                StudyHallLocationSelector.DataSource = (from section in db.Sections
                                                        where section.Course.AcademicYearID == ay && section.Block.Name.Equals("Study Hall")
                                                        select new
                {
                    Text = section.Course.Name,
                    id = section.id
                }).ToList();
                StudyHallLocationSelector.DataTextField  = "Text";
                StudyHallLocationSelector.DataValueField = "id";
                StudyHallLocationSelector.DataBind();

                if (SelectedStudyHall != -1)
                {
                    Section studyHall = db.Sections.Where(sec => sec.id == SelectedStudyHall).Single();
                    foreach (Student student in studyHall.Students.OrderByDescending(s => s.AcademicLevel).ThenBy(s => s.LastName).ThenBy(s => s.FirstName).ToList())
                    {
                        TableRow            row   = new TableRow();
                        TableCell           cell  = new TableCell();
                        StudyHallCheckInRow shcir = (StudyHallCheckInRow)LoadControl("~/UserControls/StudyHallCheckInRow.ascx");
                        shcir.StudentId = student.ID;
                        shcir.Date      = SelectedDate;
                        shcir.LoadRow();
                        cell.Controls.Add(shcir);
                        row.Cells.Add(cell);
                        CheckInTable.Rows.Add(row);
                    }
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initialize a SectionInfo object given the Section.Index
        /// </summary>
        /// <param name="id">Section.Index</param>
        /// <param name="listDetailedRosters">Include detailed student and teacher info?</param>
        public SectionInfo(int id, bool listDetailedRosters = false)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                Section section = db.Sections.Find(id);
                if (section == null)
                {
                    throw new ArgumentException("Invalid Section Id.");
                }

                Id         = id;
                CourseId   = section.CourseIndex;
                Course     = section.Course.Name;
                Block      = section.Block.LongName;
                StudentIds = section.Students.Select(s => s.ID).ToList();
                TeacherIds = section.Teachers.Select(t => t.ID).ToList();
                if (listDetailedRosters)
                {
                    Students = new List <StudentInfo>();
                    Teachers = new List <TeacherInfo>();
                    foreach (int sid in StudentIds)
                    {
                        Students.Add(new StudentInfo(sid));
                    }

                    foreach (int tid in TeacherIds)
                    {
                        Teachers.Add(new TeacherInfo(tid));
                    }
                }
            }
        }
Exemplo n.º 12
0
        private void LoadEditor()
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                Credit credit = db.Credits.Where(c => c.id == CreditId).Single();

                CreditTypeDDL.DataSource     = GradeTableEntryListItem.GetDataSource(credit.CreditType.GradeTable.GradeTableEntries.Select(g => g.id).ToList());
                CreditTypeDDL.DataTextField  = "Text";
                CreditTypeDDL.DataValueField = "ID";
                CreditTypeDDL.DataBind();

                CreditTypeDDL.ClearSelection();
                CreditTypeDDL.SelectedValue = Convert.ToString(credit.CreditTypeId);

                CreditValueDDL.DataSource     = GradeTableEntryListItem.GetDataSource(credit.CreditValue.GradeTable.GradeTableEntries.Select(g => g.id).ToList());
                CreditValueDDL.DataTextField  = "Text";
                CreditValueDDL.DataValueField = "ID";
                CreditValueDDL.DataBind();

                CreditValueDDL.ClearSelection();
                CreditValueDDL.SelectedValue = Convert.ToString(credit.CreditValueId);

                NotesInput.Text = credit.Notes;

                UpdateAll.Checked = credit.Sections.Count > 1;
            }
        }
        public IHttpActionResult PutUpdatedCommentHeader(int section_id, int term_id, [FromBody] String content)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                int header = -1;
                try
                {
                    header = db.CommentHeaders.Where(h => h.SectionIndex == section_id && h.TermIndex == term_id).Single().id;
                }
                catch (Exception e)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e)));
                }

                CommentHeader headerParagraph = db.CommentHeaders.Find(header);

                content = CommentLetter.ConvertFromBase64String(content);

                headerParagraph.HTML = CommentLetter.CleanTags(content);

                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Conflict, e)));
                }

                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, new CommentHeaderInfo(header))));
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Request a set of classes be published in bulk.
        /// </summary>
        /// <param name="user">requesting user</param>
        /// <param name="SectionIds">List of Section.id's</param>
        /// <param name="filename">file name given by the Server.MapPath() method.</param>
        /// <param name="TermId">default to the current term</param>
        public static void RequestByClass(ADUser user, List <int> SectionIds, String filename, int TermId = -1)
        {
            WebhostEventLog.Syslog.LogInformation("{0} has requested Comment Letters for {1} sections", user.Name, SectionIds.Count);
            if (TermId == -1)
            {
                TermId = DateRange.GetCurrentOrLastTerm();
            }

            LogEntry log = new LogEntry();

            XMLTree xml = new XMLTree()
            {
                TagName    = "publishrequest",
                Attributes = new Dictionary <string, string>()
                {
                    { "username", user.UserName },
                    { "name", XMLTree.MakeXMLAttributeValueSafe(user.Name) },
                    { "id", user.ID.ToString() },
                    { "type", "class" },
                    { "termid", TermId.ToString() },
                    { "timestamp", DateTime.Now.Ticks.ToString() }
                }
            };

            using (WebhostEntities db = new WebhostEntities())
            {
                foreach (int sectionId in SectionIds)
                {
                    Section section = db.Sections.Where(sec => sec.id == sectionId).Single();
                    if (section.CommentHeaders.Where(c => c.TermIndex == TermId).Count() != 1)
                    {
                        throw new WebhostException(String.Format("No comment header for Term id={0} of {1} ({2})", TermId, section.Course.Name, sectionId));
                    }

                    CommentHeader header = section.CommentHeaders.Where(c => c.TermIndex == TermId).Single();

                    XMLTree sectionTree = new XMLTree()
                    {
                        TagName    = "section",
                        Attributes = new Dictionary <string, string>()
                        {
                            { "headerid", header.id.ToString() }
                        }
                    };

                    foreach (int comid in header.StudentComments.Select(c => c.id).ToList())
                    {
                        sectionTree.ChildNodes.Add(new SimpleXMLTag()
                        {
                            TagName = "comment",
                            Value   = comid.ToString()
                        });
                    }

                    xml.ChildTrees.Add(sectionTree);
                }
            }

            xml.Save(filename + ".pubreq");
        }
Exemplo n.º 15
0
        static void CleanUpCourseRequests(int studentId, int termId)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                Student    student      = db.Students.Find(studentId);
                List <int> reqCourseIds = new List <int>();
                bool       cleanedUp    = false;
                foreach (WebhostMySQLConnection.CourseRequest cr in student.CourseRequests.Where(c => c.TermId == termId).ToList())
                {
                    if (reqCourseIds.Contains(cr.CourseId))
                    {
                        cleanedUp = true;
                        Console.WriteLine("Deleting Duplicate Course Request for {0} {1} - {2}.", student.FirstName, student.LastName, cr.RequestableCourse.Course.Name);
                        db.CourseRequests.Remove(cr);
                    }
                    else
                    {
                        reqCourseIds.Add(cr.CourseId);
                    }
                }

                if (cleanedUp)
                {
                    db.SaveChanges();
                }
                else
                {
                    Console.WriteLine("No Changes to Save.");
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Get a CSV Table showing students who have or have not completed their course requests for this term.
        /// </summary>
        /// <param name="termId"></param>
        /// <returns></returns>
        public static CSV CourseRequestsCompleted(int termId)
        {
            CSV csv = new CSV();
            using (WebhostEntities db = new WebhostEntities())
            {
                Term thisTerm = db.Terms.Find(termId);
                List<Student> relevantStudents = db.Students.Where(s => s.isActive 
                    && s.GraduationYear >= thisTerm.AcademicYearID 
                    && s.GraduationYear < thisTerm.AcademicYearID + 4).OrderBy(s => s.LastName).ThenBy(s => s.FirstName).ToList();

                foreach(Student student in relevantStudents)
                {

                    int classCount = student.Sections.Where(sec => sec.Terms.Where(t => t.id == thisTerm.id).Count() > 0).Count();
                    Dictionary<String, String> row = new Dictionary<string, string>()
                    {
                        {"LastName", student.LastName},
                        {"FirstName", student.FirstName},
                        {"Grade", gradeLevels(thisTerm.AcademicYearID)[student.GraduationYear]},
                        {"Advisor", String.Format("{0} {1}", student.Advisor.FirstName, student.Advisor.LastName)},
                        {"Submitted?", student.CourseRequests.Where(cr => cr.TermId == termId).Count() > 0?"Yes":"No"},
                        {String.Format("# of existing {0} course", thisTerm.Name), Convert.ToString(classCount)}
                    };

                    csv.Add(row);
                }

            }
            return csv;
        }
Exemplo n.º 17
0
        static void GenerateAllAttendanceDigest()
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                int  tid  = DateRange.GetCurrentOrLastTerm();
                Term term = db.Terms.Find(tid);
                foreach (Section section in term.Sections.ToList())
                {
                    CSV    csv  = ClassAttendanceStatisticsDigest(section.id);
                    String dept = section.Course.Department.Name;
                    if (!Directory.Exists(String.Format("C:\\Temp\\Attendance Stats\\{0}", dept)))
                    {
                        Directory.CreateDirectory(String.Format("C:\\Temp\\Attendance Stats\\{0}", dept));
                    }

                    String fileName = String.Format("{0}_{1}_[{2}].csv", section.Block.LongName.ToLower(), section.Course.Name.ToLower(), section.id);
                    Regex  invalid  = new Regex("[\\\\/:\\*\\?\"<>\\|]");
                    foreach (Match match in invalid.Matches(fileName))
                    {
                        fileName = fileName.Replace(match.Value, "");
                    }
                    csv.Save(String.Format("C:\\Temp\\Attendance Stats\\{0}\\{1}", dept, fileName));
                    Console.WriteLine("Done with {0}.", csv.Heading);
                }

                Console.WriteLine("Done with everything!");
                Console.ReadKey();
            }
        }
Exemplo n.º 18
0
        public static String PublishClass(int headerId, String SaveDir = "")
        {
            List <int>    commentIds   = new List <int>();
            List <String> fileNames    = new List <string>();
            String        packFileName = "";

            using (WebhostEntities db = new WebhostEntities())
            {
                CommentHeader header = db.CommentHeaders.Find(headerId);
                packFileName = String.Format("{0} {1} comments", header.Section.Block.LongName, header.Section.Course.Name).ToLower();
                WebhostEventLog.CommentLog.LogInformation("Publishing {0}", packFileName);
                packFileName = packFileName.Replace(" ", "_");
                packFileName = packFileName.Replace("\"", "");
                Regex disalowedChars = new Regex(@"(\.|:|&|#|@|\*|~|\?|<|>|\||\^|( ( )+)|/)");
                foreach (Match match in disalowedChars.Matches(packFileName))
                {
                    packFileName = packFileName.Replace(match.Value, "");
                }

                foreach (int id in header.StudentComments.Select(c => c.id))
                {
                    fileNames.Add((new CommentLetter(id)).Publish(SaveDir));
                }
            }

            if (SaveDir.Equals(""))
            {
                return(MailControler.PackForDownloading(fileNames, packFileName, HttpContext.Current.Server));
            }
            else
            {
                return(MailControler.PackForDownloading(fileNames, String.Format("{0}\\{1}.zip", SaveDir, packFileName)));
            }
        }
Exemplo n.º 19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                using (WebhostEntities db = new WebhostEntities())
                {
                    StudentSelectDDL.DataSource = (from student in db.Students
                                                   orderby student.LastName, student.FirstName
                                                   select new
                    {
                        Text = student.FirstName + " " + student.LastName + " (" + student.GraduationYear + ")",
                        id = student.ID
                    }).ToList();
                    StudentSelectDDL.DataTextField  = "Text";
                    StudentSelectDDL.DataValueField = "id";
                    StudentSelectDDL.DataBind();

                    FacultySelectDDL.DataSource = (from teacher in db.Faculties
                                                   orderby teacher.LastName, teacher.FirstName
                                                   select new
                    {
                        Text = teacher.FirstName + " " + teacher.LastName,
                        id = teacher.ID
                    }).ToList();
                    FacultySelectDDL.DataTextField  = "Text";
                    FacultySelectDDL.DataValueField = "id";
                    FacultySelectDDL.DataBind();
                }
            }
        }
Exemplo n.º 20
0
        public CommentLetter(int commentId) : base()
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                StudentComment comment = db.StudentComments.Find(commentId);

                String studentName = String.Format("{0} {1}", comment.Student.FirstName, comment.Student.LastName);
                String advisorName = String.Format("{0} {1}", comment.Student.Advisor.FirstName, comment.Student.Advisor.LastName);
                String courseName  = comment.CommentHeader.Section.Course.Name;

                String title = String.Format("{0} {1} Comments for {2}", courseName, comment.CommentHeader.Term.Name, studentName);
                foreach (char ch in Path.GetInvalidFileNameChars())
                {
                    title = title.Replace(ch, ' ');
                }

                this.Title = title;

                HeaderTable = GenerateHeaderTable(advisorName, studentName, courseName, comment.ExamGrade.Name, comment.TermGrade.Name, comment.EffortGrade.Name, comment.FinalGrade.Name);

                IndividualParagraph = comment.HTML;

                Content = comment.CommentHeader.HTML + comment.HTML + "<table style='vertical-align: top'><tr>";
                foreach (Faculty teacher in comment.CommentHeader.Section.Teachers.ToList())
                {
                    Content += String.Format("<td>{1} {2}<br/>{0}</td>", SignatureImage(teacher.ID), teacher.FirstName, teacher.LastName);
                }
                Content += "</tr></table>";
            }
        }
        public CommentHeaderReviewPDF(int termId = -1)
        {
            if (termId == -1)
            {
                termId = DateRange.GetCurrentOrLastTerm();
            }

            Headers = new List <SmallHeader>();
            using (WebhostEntities db = new WebhostEntities())
            {
                Term term = db.Terms.Where(t => t.id == termId).Single();
                foreach (Section section in term.Sections.Where(sec => sec.getsComments).ToList())
                {
                    string html = "<p>Not done!</p>";
                    if (section.CommentHeaders.Where(hdr => hdr.TermIndex == termId).Count() > 0)
                    {
                        html = section.CommentHeaders.Where(hdr => hdr.TermIndex == termId).First().HTML;
                    }

                    Headers.Add(new SmallHeader()
                    {
                        html      = html,
                        className = String.Format("[{0}] {1}", section.Block.LongName, section.Course.Name),
                        teachers  = TeacherNames(section.Teachers.ToList())
                    });
                }
            }
        }
Exemplo n.º 22
0
            public static List <MedAttendanceMarking> GetDatasource(int year = -1)
            {
                using (WebhostEntities db = new WebhostEntities())
                {
                    if (db.AcademicYears.Where(y => y.id == year).Count() <= 0)
                    {
                        year = DateRange.GetCurrentAcademicYear();
                    }

                    GradeTable gt = db.GradeTables.Where(g => g.AcademicYearID == year && g.Name.Equals("Attendance")).Single();
                    List <MedAttendanceMarking> mks = new List <MedAttendanceMarking>();
                    foreach (int entry in gt.GradeTableEntries.Select(e => e.id).ToList())
                    {
                        try
                        {
                            mks.Add(new MedAttendanceMarking(entry));
                        }
                        catch
                        {
                            // ignore!
                        }
                    }

                    return(mks);
                }
            }
Exemplo n.º 23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                using (WebhostEntities db = new WebhostEntities())
                {
                    int year = DateRange.GetCurrentAcademicYear();

                    DormSelector.DataSource     = db.Dorms.Where(d => d.AcademicYearId == year).ToList();
                    DormSelector.DataTextField  = "Name";
                    DormSelector.DataValueField = "id";
                    DormSelector.DataBind();

                    DormHeadSelector.DataSource = (from faculty in db.Faculties
                                                   orderby faculty.LastName, faculty.FirstName
                                                   select new
                    {
                        Name = faculty.FirstName + " " + faculty.LastName,
                        id = faculty.ID
                    }).ToList();
                    DormHeadSelector.DataTextField  = "Name";
                    DormHeadSelector.DataValueField = "id";
                    DormHeadSelector.DataBind();
                }
            }
        }
Exemplo n.º 24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                using (WebhostEntities db = new WebhostEntities())
                {
                    int year = DateRange.GetCurrentAcademicYear();
                    DutyTeamSelectList.DataSource = (from team in db.DutyTeams.Where(t => t.AcademicYearID == year)
                                                     select new
                    {
                        Name = team.Name,
                        ID = team.id
                    }).ToList();
                    DutyTeamSelectList.DataTextField  = "Name";
                    DutyTeamSelectList.DataValueField = "ID";
                    DutyTeamSelectList.DataBind();

                    if (db.Faculties.Where(f => f.ID == user.ID).Count() > 0)
                    {
                        Faculty faculty = db.Faculties.Where(f => f.ID == user.ID).Single();
                        if (faculty.DutyTeams.Where(dt => dt.AcademicYearID == year).Count() > 0)
                        {
                            DutyTeamSelectList.ClearSelection();
                            DutyTeamSelectList.SelectedValue = Convert.ToString(faculty.DutyTeams.Where(dt => dt.AcademicYearID == year).ToList().First().id);
                            DutyRosterEditor1.DutyTeamId     = Convert.ToInt32(DutyTeamSelectList.SelectedValue);
                            WeekendBuilder1.DutyTeamID       = Convert.ToInt32(DutyTeamSelectList.SelectedValue);
                        }
                    }
                }
            }
        }
Exemplo n.º 25
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                using (WebhostEntities db = new WebhostEntities())
                {
                    DTLSelector.DataSource = (from faculty in db.Faculties
                                              orderby faculty.LastName, faculty.FirstName
                                              select new
                    {
                        Name = faculty.FirstName + " " + faculty.LastName,
                        id = faculty.ID
                    }).ToList();
                    DTLSelector.DataTextField  = "Name";
                    DTLSelector.DataValueField = "id";
                    DTLSelector.DataBind();


                    AODSelector.DataSource = (from faculty in db.Faculties
                                              orderby faculty.LastName, faculty.FirstName
                                              select new
                    {
                        Name = faculty.FirstName + " " + faculty.LastName,
                        id = faculty.ID
                    }).ToList();
                    AODSelector.DataTextField  = "Name";
                    AODSelector.DataValueField = "id";
                    AODSelector.DataBind();
                }

                SaveBtn.Visible = false;
            }
        }
Exemplo n.º 26
0
        static void GetPreRegisteredStudentList()
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                List <Student> students = new List <Student>();
                foreach (RegistrationRequest req in db.RegistrationRequests.ToList())
                {
                    if (!students.Contains(req.Student) && req.RequestCompleted)
                    {
                        students.Add(req.Student);
                    }
                }

                CSV csv = new CSV();
                foreach (Student student in students)
                {
                    Dictionary <String, String> row = new Dictionary <string, string>()
                    {
                        { "Last Name", student.LastName },
                        { "First Name", student.FirstName },
                        { "Class of", student.GraduationYear.ToString() }
                    };
                    csv.Add(row);
                }

                csv.Save(new FileStream("C:\\Temp\\preregistrations.csv", FileMode.CreateNew));
            }
        }
Exemplo n.º 27
0
        public IHttpActionResult GetCurrentCommentHeaders([FromUri] bool includeComments = false)
        {
            List <CommentHeaderInfo> commentHeaders = new List <CommentHeaderInfo>();

            using (WebhostEntities db = new WebhostEntities())
            {
                WebhostUserPrinciple principal = (WebhostUserPrinciple)ActionContext.RequestContext.Principal;
                int id = ((WebhostIdentity)principal.Identity).User.Id;

                Faculty self = db.Faculties.Find(id);

                int        termId  = DateRange.GetCurrentOrLastTerm();
                List <int> headers = new List <int>();
                foreach (Section section in self.Sections.Where(s => s.Terms.Where(t => t.id == termId).Count() > 0).ToList())
                {
                    if (section.CommentHeaders.Where(h => h.TermIndex == termId).Count() > 0)
                    {
                        headers.Add(section.CommentHeaders.Where(h => h.TermIndex == termId).Single().id);
                    }
                }

                foreach (int headerId in headers)
                {
                    commentHeaders.Add(new RequestHandlers.CommentHeaderInfo(headerId, includeComments));
                }
            }

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, commentHeaders, "text/json");

            return(ResponseMessage(response));
        }
Exemplo n.º 28
0
        static List <DateTime> GetClassDays(int academicYear)
        {
            List <DateTime> days = new List <DateTime>();

            using (WebhostEntities db = new WebhostEntities())
            {
                AcademicYear year  = db.AcademicYears.Find(academicYear);
                DateTime     start = year.Terms.OrderBy(t => t.StartDate).First().StartDate;
                DateTime     end   = year.Terms.OrderBy(t => t.EndDate).Last().EndDate;

                for (DateTime dt = start; dt <= end; dt = dt.AddDays(1))
                {
                    if (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday)
                    {
                        continue;
                    }

                    if (db.AttendanceMarkings.Where(at => at.AttendanceDate.Equals(dt)).Count() > 0)
                    {
                        days.Add(dt);
                    }
                }
            }
            return(days);
        }
Exemplo n.º 29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                if (WeekendId == -1)
                {
                    WeekendLabel.Text = "No information Yet!";
                    return;
                }
                Weekend weekend = db.Weekends.Where(w => w.id == WeekendId).Single();

                WeekendLabel.Text = weekend.DutyTeam.Name + " Weekend!";
                ActivitiesTable.Rows.Clear();
                ActivitiesTable.Rows.Add(DutyScheduleRow.HeaderRow);
                List <DutyScheduleRow> rows = new List <DutyScheduleRow>();
                foreach (WeekendActivity activity in weekend.WeekendActivities.Where(act => !act.IsDeleted).ToList())
                {
                    rows.Add(new DutyScheduleRow(activity.id, false, IsMobile, ((BasePage)Page).user.IsTeacher));
                }
                if (((BasePage)Page).user.IsTeacher)
                {
                    foreach (WeekendDuty duty in weekend.WeekendDuties.Where(dut => !dut.IsDeleted).ToList())
                    {
                        rows.Add(new DutyScheduleRow(duty.id, true, IsMobile, true));
                    }
                }
                rows.Sort();

                ActivitiesTable.Rows.AddRange(rows.ToArray());
            }
        }
Exemplo n.º 30
0
        protected void LoadAdminPanel(WebhostEntities db, Faculty teacher, int curTerm)
        {
            PingBtn.Visible = false;
            if (teacher.Permissions.Where(p => p.Name.Contains("Admin") && p.AcademicYear == DateRange.GetCurrentAcademicYear()).Count() > 0)
            {
                PingBtn.Visible              = true;
                TeacherSelect.DataSource     = FacultyListItem.GetDataSource(db.Faculties.Where(f => f.isActive).OrderBy(f => f.LastName).ThenBy(f => f.FirstName).Select(f => f.ID).ToList());
                TeacherSelect.DataTextField  = "Text";
                TeacherSelect.DataValueField = "ID";
                TeacherSelect.DataBind();

                StudentSelect.DataSource     = StudentListItem.GetDataSource(db.Students.Where(s => s.isActive).OrderBy(f => f.LastName).ThenBy(f => f.FirstName).Select(s => s.ID).ToList());
                StudentSelect.DataTextField  = "Text";
                StudentSelect.DataValueField = "ID";
                StudentSelect.DataBind();
            }
            else if (db.Departments.Where(d => d.DeptHeadId == teacher.ID).Count() > 0)
            {
                List <int> facids = new List <int>();
                Term       term   = db.Terms.Find(curTerm);
                foreach (Department dept in teacher.Departments.ToList())
                {
                    foreach (Section section in term.Sections.Where(s => s.Course.DepartmentID == dept.id).ToList())
                    {
                        foreach (Faculty t in section.Teachers.ToList())
                        {
                            if (!facids.Contains(t.ID))
                            {
                                facids.Add(t.ID);
                            }
                        }
                    }
                }

                TeacherSelect.DataSource     = FacultyListItem.GetDataSource(facids);
                TeacherSelect.DataTextField  = "Text";
                TeacherSelect.DataValueField = "ID";
                TeacherSelect.DataBind();

                StudentSelect.DataSource     = StudentListItem.GetDataSource(teacher.Students.Where(s => s.isActive).Select(s => s.ID).ToList());
                StudentSelect.DataTextField  = "Text";
                StudentSelect.DataValueField = "ID";
                StudentSelect.DataBind();
            }
            else
            {
                TeacherSelect.DataSource = FacultyListItem.GetDataSource(new List <int>()
                {
                    user.ID
                });
                TeacherSelect.DataTextField  = "Text";
                TeacherSelect.DataValueField = "ID";
                TeacherSelect.DataBind();

                StudentSelect.DataSource     = StudentListItem.GetDataSource(teacher.Students.Where(s => s.isActive).Select(s => s.ID).ToList());
                StudentSelect.DataTextField  = "Text";
                StudentSelect.DataValueField = "ID";
                StudentSelect.DataBind();
            }
        }