Exemplo n.º 1
0
        public IHttpActionResult PostStudentComment(StudentComment studentComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.StudentComments.Add(studentComment);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (StudentCommentExists(studentComment.StudentId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = studentComment.StudentId }, studentComment));
        }
Exemplo n.º 2
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>";
            }
        }
Exemplo n.º 3
0
 public ActionResult ViewComments(CommentsViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (string.IsNullOrEmpty(User.Identity.GetUserId()))
         {
             ModelState.AddModelError("User", "User not logged in");
             return(View(GetCommentsViewModelFor(model.PostId)));
         }
         Comment comment = new Comment()
         {
             Text         = model.NewCommentText,
             PostId       = model.PostId,
             StudentId    = model.CurrentStudentId,
             TimeAnswered = DateTime.Now
         };
         StudentComment studentComment = new StudentComment()
         {
             CommentId = comment.Id,
             StudentId = comment.StudentId,
             Voted     = false
         };
         Post post = db.Posts.Include(p => p.Comments).FirstOrDefault(p => p.Id == model.PostId);
         post.Comments.Add(comment);
         db.StudentComments.Add(studentComment);
         db.SaveChanges();
         return(RedirectToAction("ViewComments", new { postId = model.PostId }));
     }
     return(View(GetCommentsViewModelFor(model.PostId)));
 }
Exemplo n.º 4
0
        public IHttpActionResult PutStudentComment(int id, StudentComment studentComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != studentComment.StudentId)
            {
                return(BadRequest());
            }

            db.Entry(studentComment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentCommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 5
0
        public IHttpActionResult GetStudentComment(int id)
        {
            StudentComment studentComment = db.StudentComments.Find(id);

            if (studentComment == null)
            {
                return(NotFound());
            }

            return(Ok(studentComment));
        }
Exemplo n.º 6
0
        public IHttpActionResult SetVoted(int studentId, int id)
        {
            StudentComment studentComment = db.StudentComments.FirstOrDefault(p => p.StudentId == studentId && p.CommentId == id);

            if (studentComment == null)
            {
                return(NotFound());
            }
            studentComment.Voted = true;
            db.SaveChanges();
            return(Ok(studentComment));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> EditComment(int?id)
        {
            var student = await _repository.FindByIdAsync <Student>(id);

            StudentComment studentModel = new StudentComment
            {
                StudentFirstName = student.FirstName,
                StudentLastName  = student.LastName,
                Comment          = student.Comment,
            };

            return(View(studentModel));
        }
Exemplo n.º 8
0
        public IHttpActionResult DeleteStudentComment(int id)
        {
            StudentComment studentComment = db.StudentComments.Find(id);

            if (studentComment == null)
            {
                return(NotFound());
            }

            db.StudentComments.Remove(studentComment);
            db.SaveChanges();

            return(Ok(studentComment));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Publisher for Individual Comment Letter.
        /// </summary>
        /// <param name="studentCommentId"></param>
        public CommentLetter(int studentCommentId, bool commandLine = false, String saveDir = "")
        {
            SaveDirectory = saveDir;
            using (WebhostEntities db = new WebhostEntities())
            {
                if (db.StudentComments.Where(com => com.id == studentCommentId).Count() <= 0)
                {
                    throw new CommentException(String.Format("No comment letter with id={0} exists.", studentCommentId));
                }

                StudentComment studentParagraph = db.StudentComments.Where(com => com.id == studentCommentId).Single();

                flagFileName = String.Format("{1}{0}_flag.txt", studentCommentId, commandLine?"":saveDir.Equals("")?"~/Temp/":saveDir + "\\");

                StudentHTML = CleanTags(studentParagraph.HTML, true);
                HeaderHTML  = CleanTags(studentParagraph.CommentHeader.HTML, true);
                StudentName = studentParagraph.Student.FirstName + " " + studentParagraph.Student.LastName;
                AdvisorName = studentParagraph.Student.Advisor.FirstName + " " + studentParagraph.Student.Advisor.LastName;
                CourseName  = studentParagraph.CommentHeader.Section.Course.Name;
                Authors     = new Dictionary <string, Signature>();
                foreach (Faculty teacher in studentParagraph.CommentHeader.Section.Teachers)
                {
                    Authors.Add(String.Format("{0} {1}", teacher.FirstName, teacher.LastName), new Signature(teacher.ID));
                }

                showExam  = !studentParagraph.CommentHeader.Section.Block.LongName.Contains("Sports");
                showFinal = studentParagraph.CommentHeader.TermIndex == studentParagraph.CommentHeader.Section.Terms.OrderBy(term => term.StartDate).ToList().Last().id;

                FinalGrade  = studentParagraph.FinalGrade.Name;
                ExamGrade   = studentParagraph.ExamGrade.Name;
                TermGrade   = studentParagraph.TermGrade.Name;
                EffortGrade = studentParagraph.EffortGrade.Name;

                TermName    = studentParagraph.CommentHeader.Term.Name;
                PublishDate = studentParagraph.CommentHeader.Term.CommentsDate;
                String fileName = String.Format("{0} - {1} {2}", StudentName, studentParagraph.CommentHeader.Section.Block.Name, CourseName.Replace("+", "p")).ToLower();

                fileName = fileName.Replace(" ", "_");
                fileName = fileName.Replace("\"", "");
                Regex disalowedChars = new Regex(@"(\.|:|&|#|@|\*|~|\?|<|>|\||\^|( ( )+)|/)");
                foreach (Match match in disalowedChars.Matches(fileName))
                {
                    fileName = fileName.Replace(match.Value, "");
                }

                fileName = String.Format("{0}{1}.pdf", commandLine?"C:\\Temp\\":saveDir.Equals("")?"~/Temp/":saveDir + "\\", fileName);

                Init(fileName, String.Format("{0} - {1} {2} {3} Comment Letter", StudentName, studentParagraph.CommentHeader.Section.Block.Name, CourseName, TermName), Authors.Keys.First());
            }
        }
        public void LoadComment(int CommentId)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                StudentComment comment = db.StudentComments.Where(c => c.id == CommentId).Single();

                CommentLabel.Text = String.Format("Comment for {0} {1} in {2}", comment.Student.FirstName, comment.Student.LastName, comment.CommentHeader.Section.Course.Name);

                EffortGradeLabel.Text    = comment.EffortGrade.Name;
                TrimesterGradeLabel.Text = comment.TermGrade.Name;
                ExamGradeLabel.Text      = comment.ExamGrade.Name;
                FinalGradeLabel.Text     = comment.FinalGrade.Name;

                CommentPreview.Content = comment.CommentHeader.HTML + comment.HTML;
            }
        }
Exemplo n.º 11
0
        public async Task <IActionResult> EditComment(StudentComment model)
        {
            if (ModelState.IsValid)
            {
                var student = await _repository.FindByIdAsync <Student>(model.Id);

                student.Comment = model.Comment;
                await _repository.SaveAsync();

                _logger.LogInformation($"User {_user} edited comment of student with {student.Id}");
                var currentUrl = HttpContext.Request.Headers["Referer"];
                return(Redirect(currentUrl));
            }
            _logger.LogError($"Error with ModelState validation. User {_user}");
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 12
0
        public IHttpActionResult GetVoted(int studentId, int id)
        {
            StudentComment studentComment = db.StudentComments.FirstOrDefault(p => p.StudentId == studentId && p.CommentId == id);

            if (studentComment == null)
            {
                return(NotFound());
            }
            StudentCommentDto dto = new StudentCommentDto()
            {
                CommentId = studentComment.CommentId,
                StudentId = studentComment.StudentId,
                Voted     = studentComment.Voted
            };

            return(Ok(dto));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initialize a student comment.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="includeHeader"></param>
        public StudentCommentInfo(int id, bool includeHeader = false)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                StudentComment comment = db.StudentComments.Find(id);
                if (comment == null)
                {
                    throw new ArgumentException("Invalid Student Comment.");
                }

                Grades = new GradeInfo()
                {
                    EngagementGrade = comment.EngagementGrade.Name,
                    ExamGrade       = comment.ExamGrade.Name,
                    FinalGrade      = comment.FinalGrade.Name,
                    TrimesterGrade  = comment.TermGrade.Name
                };

                Id       = id;
                Student  = new StudentInfo(comment.StudentID);
                HeaderId = comment.HeaderIndex;
                if (comment.RTF.Length <= 0)
                {
                    HtmlContent = CommentLetter.ConvertToBase64String(comment.HTML);
                }
                else
                {
                    RtfContent = comment.RTF;
                }

                if (includeHeader)
                {
                    Header = new CommentHeaderInfo(HeaderId);
                }
            }
        }
Exemplo n.º 14
0
        public IHttpActionResult PutUpdatedStudentComment(int section_id, int student_id, [FromBody] StudentCommentInfo info, [FromUri] String format = "rtf")
        {
            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."))));
                }

                if (section.Students.Where(s => s.ID == student_id).Count() <= 0)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException("Invalid Student 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."))));
                }

                CommentHeader header = section.CommentHeaders.Where(h => h.TermIndex == termId).Single();

                if (header.StudentComments.Where(com => com.StudentID == student_id).Count() <= 0)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Conflict, new ArgumentException("No Comment for this student saved."))));
                }

                StudentComment comment = header.StudentComments.Where(com => com.StudentID == student_id).Single();

                Dictionary <String, int> GradeEntries = CommentLetter.GetGradeTableEntryData();

                comment.EffortGradeID = GradeEntries[info.Grades.EngagementGrade];
                comment.ExamGradeID   = GradeEntries[info.Grades.ExamGrade];
                comment.TermGradeID   = GradeEntries[info.Grades.TrimesterGrade];
                comment.FinalGradeID  = GradeEntries[info.Grades.FinalGrade];

                if (format.Equals("html"))
                {
                    comment.HTML = CommentLetter.ConvertFromBase64String(info.HtmlContent);
                }
                else
                {
                    comment.RTF = info.RtfContent;
                }

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

                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, new StudentCommentInfo(header.StudentComments.Where(com => com.StudentID == student_id).Single().id))));
            }
        }
Exemplo n.º 15
0
        protected void StudentSelectCmbBx_SelectedIndexChanged(object sender, EventArgs e)
        {
            CommentGrades.ResetBar();
            State.log.WriteLine("{0} {1}:  Loading new student selection.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
            if (Saving)
            {
                State.log.WriteLine("{1} {0}:  Aborted Changing Comment while Saving.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
                WebhostEventLog.CommentLog.LogWarning("Aborted changing comment while saving.");
                return;
            }
            if (LoadedHeaderId == -1)
            {
                State.log.WriteLine("{0} {1}:  No Header is Loaded... There's a problem...", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                StudentSelectCmbBx.DataSource = new List <string>();
                StudentSelectCmbBx.DataBind();
                WebhostEventLog.CommentLog.LogError("Cannot Select a student while no Header is loaded...");
                return;
            }

            try
            {
                SelectedStudentId = Convert.ToInt32(StudentSelectCmbBx.SelectedValue);
            }
            catch (Exception ex)
            {
                State.log.WriteLine("{1} {0}:  Failed:  {2}", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString(), ex.Message);
                WebhostEventLog.CommentLog.LogError("Failed to select Student: {0}", ex.Message);
                return;
            }

            using (WebhostEntities db = new WebhostEntities())
            {
                CommentHeader header = db.CommentHeaders.Where(hdr => hdr.id == LoadedHeaderId).Single();
                // check for existing comments.
                if (header.StudentComments.Where(com => com.StudentID == SelectedStudentId).Count() > 0)
                {
                    // check for multiples.
                    if (header.StudentComments.Where(com => com.StudentID == SelectedStudentId).Count() > 1)
                    {
                        State.log.WriteLine("{1} {0}:  Something went wrong!  Too many comments for Student.id={2} and CommentHeader.id={3}", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString(), SelectedStudentId, LoadedHeaderId);
                        MailControler.MailToWebmaster("Class has Too Many comment paragraphs....", String.Format("{0} objects match comment paragraph for Student.id={4} in [{1}] {2} {3} comments.",
                                                                                                                 header.StudentComments.Where(com => com.StudentID == SelectedStudentId).Count(), header.Section.Block.LongName, header.Section.Course.Name, header.Term.Name), ((BasePage)Page).user);

                        WebhostEventLog.CommentLog.LogError("Something went wrong!  Too many comments for Student.id={0} and CommentHeader.id={1}", SelectedStudentId, LoadedHeaderId);

                        /*********************************************************************
                        * TODO:
                        * Handle This some how!
                        *
                        * Make a pop-up to choose which to keep.
                        *
                        *********************************************************************/

                        State.log.WriteLine("{1} {0}:  Aborting the defunct Header Loader.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
                        return;
                    }

                    // Load the unique comment.

                    StudentComment comment = header.StudentComments.Where(com => com.StudentID == SelectedStudentId).Single();
                    LoadedCommentId = comment.id;

                    State.log.WriteLine("{0} {1}:  Loading unique comment id={2}", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString(), LoadedCommentId);
                    WebhostEventLog.CommentLog.LogInformation("Loaded Comment id {0}", LoadedCommentId);
                    StudentCommentHTML             = comment.HTML;
                    CommentGrades.EffortGradeID    = comment.EffortGradeID;
                    CommentGrades.FinalGradeID     = comment.FinalGradeID;
                    CommentGrades.ExamGradeID      = comment.ExamGradeID;
                    CommentGrades.TrimesterGradeID = comment.TermGradeID;
                    StudentEditor.Content          = comment.HTML;

                    StudentNameLabel.Text = String.Format("Comment for {0} {1}", comment.Student.FirstName, comment.Student.LastName);
                }
                else
                {
                    // Create new blank comment.
                    State.log.WriteLine("{0} {1}:  Creating a new Student Comment paragraph.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                    WebhostEventLog.CommentLog.LogInformation("Creating new student comment.");
                    StudentComment comment = new StudentComment()
                    {
                        id            = db.StudentComments.Count() > 0 ? db.StudentComments.OrderBy(com => com.id).ToList().Last().id + 1 : 0,
                        StudentID     = SelectedStudentId,
                        Student       = db.Students.Where(s => s.ID == SelectedStudentId).Single(),
                        HeaderIndex   = header.id,
                        HTML          = "",
                        TermGradeID   = CommentGrades.AFDefault,
                        EffortGradeID = CommentGrades.EffortDefault,
                        FinalGradeID  = CommentGrades.AFDefault,
                        ExamGradeID   = CommentGrades.AFDefault
                    };


                    db.StudentComments.Add(comment);
                    db.SaveChanges();
                    LoadedCommentId       = comment.id;
                    comment               = db.StudentComments.Where(c => c.id == LoadedCommentId).Single();
                    StudentEditor.Content = "";
                    StudentNameLabel.Text = String.Format("Comment for {0} {1}", comment.Student.FirstName, comment.Student.LastName);
                    State.log.WriteLine("{0} {1}:  New blank comment is saved to the database.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                }

                EditorLabel.Text     = "Editing Student Individual Comment.";
                HeaderBtn.Visible    = true;
                HeaderPanel.Visible  = false;
                StudentPanel.Visible = true;
                PreviewBtn.Visible   = true;
            }
        }
Exemplo n.º 16
0
        protected void SaveBtn_Click(object sender, EventArgs e)
        {
            if (SelectedSectionId == -1)
            {
                State.log.WriteLine("{0} {1}:  Cannot Save with no section selected.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                LogWarning("Cannot save with no section selected.");
                return;
            }
            if (Saving)
            {
                State.log.WriteLine("{1} {0}:  Aborted multiple Saving attempts.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
                LogWarning("Aborted multiple Saving Attempts.");
                return;
            }
            using (WebhostEntities db = new WebhostEntities())
            {
                Saving = true;
                if (HeaderPanel.Visible)
                {
                    CommentHeader header = db.CommentHeaders.Where(h => h.id == LoadedHeaderId).Single();
                    State.log.WriteLine("{0} {1}:  Saving Header Paragraph.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                    // Save the Header!
                    if (HeaderEditor.Content.Length < header.HTML.Length)
                    {
                        State.log.WriteLine("{0} {1}:  Warning--suspicious overwrite:{2}Original:{2}{3}{2}Replacement:{2}{4}", DateTime.Today.ToShortDateString(),
                                            DateTime.Now.ToLongTimeString(), Environment.NewLine, header.HTML, HeaderEditor.Content);
                        WebhostEventLog.CommentLog.LogWarning("Suspicious Overwrite:{0}Original:{0}{1}{0}========================================================{0}Replacement:{0}{2}",
                                                              Environment.NewLine, header.HTML, HeaderEditor.Content);
                    }

                    String html = HeaderEditor.Content;
                    String temp = html;
                    html = CommentLetter.CleanTags(html);

                    if (!temp.Equals(html))
                    {
                        WebhostEventLog.CommentLog.LogWarning("CleanTags method changed:{0}{1}{0}============================================================={0}Into:{0}{2}",
                                                              Environment.NewLine, temp, html);
                    }

                    WebhostEventLog.CommentLog.LogInformation("Saving Header:{0}{1}", Environment.NewLine, html);

                    HeaderEditor.Content = html;

                    header.HTML = HeaderEditor.Content;
                    HeaderHTML  = HeaderEditor.Content;
                }

                if (LoadedCommentId != -1)
                {
                    State.log.WriteLine("{0} {1}:  Saving Student Comment.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                    StudentComment comment = db.StudentComments.Where(com => com.id == LoadedCommentId).Single();

                    if (StudentEditor.Content.Length < comment.HTML.Length)
                    {
                        State.log.WriteLine("{0} {1}:  Warning--suspicious overwrite:{2}Original:{2}{3}{2}Replacement:{2}{4}", DateTime.Today.ToShortDateString(),
                                            DateTime.Now.ToLongTimeString(), Environment.NewLine, comment.HTML, StudentEditor.Content);
                        WebhostEventLog.CommentLog.LogWarning("Suspicious Overwrite:{0}Original:{0}{1}{0}========================================================{0}Replacement:{0}{2}",
                                                              Environment.NewLine, comment.HTML, StudentEditor.Content);
                    }


                    String html = StudentEditor.Content;

                    String temp = html;
                    html = CommentLetter.CleanTags(html);

                    if (!temp.Equals(html))
                    {
                        WebhostEventLog.CommentLog.LogWarning("CleanTags method changed:{0}{1}{0}============================================================={0}Into:{0}{2}",
                                                              Environment.NewLine, temp, html);
                    }

                    WebhostEventLog.CommentLog.LogInformation("Saving Comment for {2} {3}:{0}{1}", Environment.NewLine, html, comment.Student.FirstName, comment.Student.LastName);

                    StudentEditor.Content = html;

                    comment.HTML          = StudentEditor.Content;
                    comment.EffortGradeID = CommentGrades.EffortGradeID;
                    comment.FinalGradeID  = CommentGrades.FinalGradeID;
                    comment.TermGradeID   = CommentGrades.TrimesterGradeID;
                    comment.ExamGradeID   = CommentGrades.ExamGradeID;
                    StudentCommentHTML    = StudentEditor.Content;
                }

                db.SaveChanges();
                State.log.WriteLine("{0} {1}:  Changes saved to the Database.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                WebhostEventLog.CommentLog.LogInformation("Save Complete.");
            }

            Saving = false;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Get a human readable course request overview in a CSV formatted spreadsheet.
        /// </summary>
        /// <param name="termId">WebhostEntities.Term.id</param>
        /// <returns></returns>
        public static CSV ForExcel(int termId)
        {
            CSV csv = new CSV();

            using (WebhostEntities db = new WebhostEntities())
            {
                List<CourseRequest> thistermreqs =
                    db.CourseRequests.Where(c => c.TermId == termId && 
                        !c.RequestableCourse.Course.BlackBaudID.Equals("NONE")).OrderBy(c => c.RequestableCourse.Course.DepartmentID).ThenBy(c => c.RequestableCourse.Course.Name).ToList();

                Term term = db.Terms.Find(termId);

                int ptid = DateRange.GetCurrentOrLastTerm();

                foreach (CourseRequest cr in thistermreqs)
                {
                    Dictionary<String, String> row = new Dictionary<string, string>()
                    {
                        {"Student", String.Format("{0} {1}", cr.Student.FirstName, cr.Student.LastName)},
                        {"Grade", gradeLevels(term.AcademicYearID)[cr.Student.GraduationYear]},
                        {"Course", cr.RequestableCourse.Course.Name.Replace(",", "")},
                        {"Department", cr.RequestableCourse.Course.Department.Name},
                        {"Priority", cr.IsSecondary || cr.IsGlobalAlternate?"Alternate":""},
                        {"Advisor", String.Format("{0} {1}", cr.Student.Advisor.FirstName, cr.Student.Advisor.LastName)}
                    };

                    if(cr.RequestableCourse.Course.Name.Contains("AP"))
                    {
                        if (cr.APRequests.Count <= 0) row.Add("AP Form Submitted", "No");
                        else
                        {
                            row.Add("AP Form Submitted", "Yes");
                            APRequest req = cr.APRequests.FirstOrDefault();
                            foreach(Section section in req.Sections.ToList())
                            {
                                try
                                {
                                    row.Add(String.Format("{0} Course", section.Course.Department.Name), section.Course.Name);
                                    if (cr.Student.StudentComments.Where(com => com.CommentHeader.SectionIndex == section.id && com.CommentHeader.TermIndex == ptid).Count() > 0)
                                    {
                                        StudentComment comment = cr.Student.StudentComments.Where(com => com.CommentHeader.SectionIndex == section.id && com.CommentHeader.TermIndex == ptid).Single();
                                        row.Add(String.Format("{0} Grade", section.Course.Department.Name), comment.FinalGrade.Name);
                                    }
                                    else
                                    {
                                        row.Add(String.Format("{0} Grade", section.Course.Department.Name), "Not Submitted");
                                    }
                                }
                                catch(Exception e)
                                {
                                    State.log.WriteLine(e.Message);
                                }
                            }

                            row.Add("Teacher Signed", String.Format("{0} {1}", req.Teacher.FirstName, req.Teacher.LastName));
                            row.Add("Dept Head Signed", String.Format("{0} {1}", req.DepartmentHead.FirstName, req.DepartmentHead.LastName));
                            row.Add("Approval", req.GradeTableEntry.Name);
                        }
                    }

                    csv.Add(row);
                }
            }

            return csv;
        }
Exemplo n.º 18
0
 public static Student EditEntity(Student student, StudentComment studentFromModel)
 {
     student.Id      = studentFromModel.Id;
     student.Comment = studentFromModel.Comment;
     return(student);
 }
Exemplo n.º 19
0
        protected void SelectCR_Click(object sender, EventArgs e)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                LoadedId = -1;
                int crid = Convert.ToInt32(CourseRequestDDL.SelectedValue);
                WebhostMySQLConnection.CourseRequest courseRequest = db.CourseRequests.Where(cr => cr.id == crid).Single();

                RequestedCourseName.Text = courseRequest.RequestableCourse.Course.Name;


                int     sid     = Convert.ToInt32(StudentSelectDDL.SelectedValue);
                Student student = db.Students.Where(s => s.ID == sid).Single();

                int        termId         = DateRange.GetCurrentOrLastTerm();
                List <int> currentClasses = student.Sections.Where(sec => sec.Terms.Select(t => t.id).Contains(termId)).Select(sec => sec.id).ToList();
                CurrentCourseDDL.DataSource     = SectionListItem.GetDataSource(currentClasses);
                CurrentCourseDDL.DataTextField  = "Text";
                CurrentCourseDDL.DataValueField = "ID";
                CurrentCourseDDL.DataBind();


                SecondaryCourseDDL.DataSource     = SectionListItem.GetDataSource(currentClasses);
                SecondaryCourseDDL.DataTextField  = "Text";
                SecondaryCourseDDL.DataValueField = "ID";
                SecondaryCourseDDL.DataBind();

                int year = DateRange.GetCurrentAcademicYear();

                GradeTable stdaf = db.GradeTables.Where(gt => gt.AcademicYearID == year && gt.Name.Equals("Standard A-F Scale")).Single();

                CurrentCourseGradeDDL.DataSource     = stdaf.GradeTableEntries.ToList();
                CurrentCourseGradeDDL.DataTextField  = "Name";
                CurrentCourseGradeDDL.DataValueField = "id";
                CurrentCourseGradeDDL.DataBind();

                SecondaryCourseGradeDDL.DataSource     = stdaf.GradeTableEntries.ToList();
                SecondaryCourseGradeDDL.DataTextField  = "Name";
                SecondaryCourseGradeDDL.DataValueField = "id";
                SecondaryCourseGradeDDL.DataBind();

                List <int> facultyIds = db.Faculties.Select(f => f.ID).ToList();

                CurrentTeacherDDL.DataSource     = FacultyListItem.GetDataSource(facultyIds);
                CurrentTeacherDDL.DataTextField  = "Text";
                CurrentTeacherDDL.DataValueField = "ID";
                CurrentTeacherDDL.DataBind();

                DeptHeadDDL.DataSource     = FacultyListItem.GetDataSource(facultyIds);
                DeptHeadDDL.DataTextField  = "Text";
                DeptHeadDDL.DataValueField = "ID";
                DeptHeadDDL.DataBind();

                GradeTable approval = db.GradeTables.Where(gt => gt.AcademicYearID == year && gt.Name.Equals("AP Approval")).Single();

                ApprovalDDL.DataSource     = approval.GradeTableEntries.ToList();
                ApprovalDDL.DataTextField  = "Name";
                ApprovalDDL.DataValueField = "id";
                ApprovalDDL.DataBind();

                ApprovalPanel.Visible = true;

                if (courseRequest.APRequests.Count > 0)
                {
                    APRequest apcr = courseRequest.APRequests.FirstOrDefault();
                    LoadedId = apcr.id;
                    if (apcr.Sections.Count > 0)
                    {
                        List <Section> secs = apcr.Sections.ToList();
                        CurrentCourseDDL.ClearSelection();
                        CurrentCourseDDL.SelectedValue = Convert.ToString(secs[0].id);
                        if (student.StudentComments.Where(com => com.CommentHeader.SectionIndex == secs[0].id && com.CommentHeader.TermIndex == termId).Count() > 0)
                        {
                            StudentComment comment = student.StudentComments.Where(com => com.CommentHeader.SectionIndex == secs[0].id && com.CommentHeader.TermIndex == termId).Single();
                            CurrentCourseGradeDDL.ClearSelection();
                            CurrentCourseGradeDDL.SelectedValue = Convert.ToString(comment.FinalGradeID);
                        }
                        if (secs.Count > 1)
                        {
                            SecondaryCourseDDL.ClearSelection();
                            SecondaryCourseDDL.SelectedValue = Convert.ToString(secs[1].id);
                            if (student.StudentComments.Where(com => com.CommentHeader.SectionIndex == secs[1].id && com.CommentHeader.TermIndex == termId).Count() > 0)
                            {
                                StudentComment comment = student.StudentComments.Where(com => com.CommentHeader.SectionIndex == secs[1].id && com.CommentHeader.TermIndex == termId).Single();
                                SecondaryCourseGradeDDL.ClearSelection();
                                SecondaryCourseGradeDDL.SelectedValue = Convert.ToString(comment.FinalGradeID);
                            }
                        }
                    }

                    CurrentTeacherDDL.ClearSelection();
                    CurrentTeacherDDL.SelectedValue = Convert.ToString(apcr.TeacherSignedBy);

                    DeptHeadDDL.ClearSelection();
                    DeptHeadDDL.SelectedValue = Convert.ToString(apcr.DeptHeadSignedBy);

                    ApprovalDDL.ClearSelection();
                    ApprovalDDL.SelectedValue = Convert.ToString(apcr.ApprovalId);
                }
            }
        }
Exemplo n.º 20
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var u = UserManager.FindByEmail(model.Email);
                if (u != null)
                {
                    ModelState.AddModelError("Username", "This username already exists.");
                    return(View(model));
                }
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    UserManager.AddToRole(user.Id, "User");
                    Student student = new Student()
                    {
                        FirstName = model.FirstName,
                        LastName  = model.LastName,
                        UserName  = model.Email,
                        City      = model.City,
                        UserId    = UserManager.FindByEmail(model.Email).Id
                    };
                    List <Post>    posts    = db.Posts.ToList();
                    List <Comment> comments = db.Comments.ToList();
                    foreach (Post post in posts)
                    {
                        StudentPost sp = new StudentPost()
                        {
                            Post    = post,
                            Student = student,
                            Voted   = false
                        };
                        db.StudentPosts.Add(sp);
                    }
                    foreach (Comment comment in comments)
                    {
                        StudentComment sc = new StudentComment()
                        {
                            Comment = comment,
                            Student = student,
                            Voted   = false
                        };
                        db.StudentComments.Add(sc);
                    }
                    db.Students.Add(student);
                    db.SaveChanges();
                    return(RedirectToAction("Login", "Account"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }