예제 #1
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");
        }
예제 #2
0
        /// <summary>
        /// Request a batch of Student's comments.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="StudentIds"></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 RequestByStudent(ADUser user, List <int> StudentIds, String filename, int TermId = -1)
        {
            if (TermId == -1)
            {
                TermId = DateRange.GetCurrentOrLastTerm();
            }
            XMLTree xml = new XMLTree()
            {
                TagName    = "publishrequest",
                Attributes = new Dictionary <string, string>()
                {
                    { "username", user.UserName },
                    { "name", XMLTree.MakeXMLAttributeValueSafe(user.Name) },
                    { "id", user.ID.ToString() },
                    { "type", "student" },
                    { "termid", TermId.ToString() },
                    { "timestamp", DateTime.Now.Ticks.ToString() }
                }
            };

            using (WebhostEntities db = new WebhostEntities())
            {
                foreach (int sid in StudentIds)
                {
                    Student student = db.Students.Where(s => s.ID == sid).Single();
                    if (student.StudentComments.Where(com => com.CommentHeader.TermIndex == TermId).Count() <= 0)
                    {
                        throw new WebhostException(String.Format("No Comments for {0} {1} in term id={2}", student.FirstName, student.LastName, TermId));
                    }

                    XMLTree studentTree = new XMLTree()
                    {
                        TagName    = "student",
                        Attributes = new Dictionary <string, string>()
                        {
                            { "studentid", sid.ToString() }
                        }
                    };

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

                    xml.ChildTrees.Add(studentTree);
                }
            }
            xml.Save(filename + ".pubreq");
        }