예제 #1
0
        public static String PublishTermByStudent(int termId = -1, List <int> studentIds = null, String SaveDir = "")
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                if (db.Terms.Where(t => t.id == termId).Count() <= 0)
                {
                    termId = Import.GetCurrentOrLastTerm();
                }

                Term          term             = db.Terms.Where(t => t.id == termId).Single();
                String        packFileName     = term.Name.ToLower() + "_term_comments.zip";
                List <String> termCommentFiles = new List <string>();

                if (studentIds == null)
                {
                    studentIds = Import.ActiveStudents(termId);
                }

                foreach (int studentId in studentIds)
                {
                    Student student         = db.Students.Where(s => s.ID == studentId).Single();
                    String  studentFileName = String.Format("[{3}] {0}, {1} {2} Comments.zip", student.LastName, student.FirstName, term.Name, student.GraduationYear);
                    WebhostEventLog.CommentLog.LogInformation("Publishing {0}", studentFileName);
                    List <String> studentFiles = new List <String>();
                    List <int>    commentIds   = student.StudentComments.Where(com => com.CommentHeader.TermIndex == termId).Select(com => com.id).ToList();
                    foreach (int id in commentIds)
                    {
                        studentFiles.Add((new CommentLetter(id)).Publish(SaveDir));
                    }

                    if (SaveDir.Equals(""))
                    {
                        termCommentFiles.Add(MailControler.PackForDownloading(studentFiles, studentFileName, HttpContext.Current.Server));
                    }
                    else
                    {
                        termCommentFiles.Add(MailControler.PackForDownloading(studentFiles, String.Format("{0}\\{1}", SaveDir, studentFileName)));
                    }
                }

                if (SaveDir.Equals(""))
                {
                    return(MailControler.PackForDownloading(termCommentFiles, packFileName, HttpContext.Current.Server));
                }
                else
                {
                    return(MailControler.PackForDownloading(termCommentFiles, String.Format("{0}\\{1}", SaveDir, packFileName)));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Publish comments via commandline tool.  dumps them in C:\Temp
        /// Defaults to this term, all students.
        /// </summary>
        /// <param name="termId"></param>
        /// <param name="studentIds"></param>
        public static void CommandLinePublish(int termId = -1, List <int> studentIds = null)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                if (db.Terms.Where(t => t.id == termId).Count() <= 0)
                {
                    termId = Import.GetCurrentOrLastTerm();
                }

                Term          term             = db.Terms.Where(t => t.id == termId).Single();
                String        packFileName     = term.Name.ToLower() + "_term_comments";
                List <String> termCommentFiles = new List <string>();


                if (studentIds == null)
                {
                    studentIds = Import.ActiveStudents(termId);
                }

                foreach (int studentId in studentIds)
                {
                    Student student         = db.Students.Where(s => s.ID == studentId).Single();
                    String  studentFileName = String.Format("{0}, {1} [{3}] {2} Comments", student.LastName, student.FirstName, term.Name, student.GraduationYear);
                    Console.WriteLine("Publishing {0}, {1} [2]", student.LastName, student.FirstName, student.GraduationYear);
                    List <String>         studentFiles = new List <string>();
                    List <StudentComment> commentIds   = student.StudentComments.Where(com => com.CommentHeader.TermIndex == termId).ToList();
                    foreach (StudentComment comment in commentIds)
                    {
                        studentFiles.Add((new CommentLetter(comment.id, true)).Publish(true));
                        Console.WriteLine("\t[{0}] {1}", comment.CommentHeader.Section.Block.LongName, comment.CommentHeader.Section.Course.Name);
                    }

                    termCommentFiles.Add(MailControler.PackForDownloading(studentFiles, studentFileName));
                }

                MailControler.PackForDownloading(termCommentFiles, packFileName);
            }
        }