public void GetJsConfigParametersTest()
        {
            Student a = new Student() { Id = 1 };
            Student b = new Student() { Id = 2 };
            Student c = new Student() { Id = 3 };
            Student d = new Student() { Id = 4 };

            Project p = new Project() { Id = 10 };

            Matching m1 = new Matching() { Id = 1, Project = p, ProjectScore = "A", Student = a, StudentScore = "1" };
            Matching m2 = new Matching() { Id = 1, Project = p, ProjectScore = "C", Student = c, StudentScore = "4" };
            Matching m3 = new Matching() { Id = 0, Project = p, ProjectScore = "D", Student = b, StudentScore = "2" };
            Matching m4 = new Matching() { Id = 0, Project = p, ProjectScore = "B", Student = d, StudentScore = "3" };

            p.Matchings = new List<Matching>();
            p.Matchings.Add(m1);
            p.Matchings.Add(m4);

            int[] st = { 1, 2, 3 };

            IList<Matching> existingProjectMatchings = p.Matchings.ToList();
            IList<Matching> matchingsToRemove = existingProjectMatchings.Where(m => !st.Contains(m.Student.Id)).ToList();
            int[] studentIdsToRemove = matchingsToRemove.Select(m => m.Student.Id).ToArray();
            int[] studentIdsToAdd = st.Where(sId => !existingProjectMatchings.Select(m => m.Student.Id).Contains(sId)).ToArray();

            //Remove students that do not appear in th list of students to add
            foreach (var m in matchingsToRemove)
            {
                p.Matchings.Remove(m);
            }
            // Add students that did not exist before
            foreach (var sId in studentIdsToAdd)
            {
                Matching m = new Matching() { Project = p, Student = new Student() { Id = sId } };
                p.Matchings.Add(m);
            }
               // Matching m = new Matching() { Project = p, Student = st, ProjectScore = ProjectScore.NoScore.ToString(), StudentScore = StudentScore.NoScore.ToString() };

            Console.Out.Write(p.Matchings.Count);
            //string expected = "var MinABusStudents = 1;" + System.Environment.NewLine + "var MinAEngStudents = 1;" + System.Environment.NewLine + "var MinAStudents = 2;" + System.Environment.NewLine + "var MaxRejectedBusStudents = 1;" + System.Environment.NewLine + "var MaxRejectedEngStudents = 1;" + System.Environment.NewLine + "var MaxRejectedStudents = 2;" + System.Environment.NewLine + "var RejectedStudentThreshold = 5;" + System.Environment.NewLine + "var EnforceContinuousStudentRanking = true;" + System.Environment.NewLine + "var NoScore_Bucket = $(\"#NoScore_Bucket\");" + System.Environment.NewLine + "var hf_NoScore_Ids = $(\"#hf_NoScore_Ids\");" + System.Environment.NewLine + "var hf_Bus_Total = $(\"#hf_Bus_Total\");" + System.Environment.NewLine + "var hf_NoScore_Bus_Count = $(\"#hf_NoScore_Bus_Count\");" + System.Environment.NewLine + "var hf_Eng_Total = $(\"#hf_Eng_Total\");" + System.Environment.NewLine + "var hf_NoScore_Eng_Count = $(\"#hf_NoScore_Eng_Count\");" + System.Environment.NewLine + "var A_Bucket = $(\"#A_Bucket\");" + System.Environment.NewLine + "var hf_A_Ids = $(\"#hf_A_Ids\");" + System.Environment.NewLine + "var hf_A_Bus_Count = $(\"#hf_A_Bus_Count\");" + System.Environment.NewLine + "var hf_A_Eng_Count = $(\"#hf_A_Eng_Count\");" + System.Environment.NewLine + "var B_Bucket = $(\"#B_Bucket\");" + System.Environment.NewLine + "var hf_B_Ids = $(\"#hf_B_Ids\");" + System.Environment.NewLine + "var hf_B_Bus_Count = $(\"#hf_B_Bus_Count\");" + System.Environment.NewLine + "var hf_B_Eng_Count = $(\"#hf_B_Eng_Count\");" + System.Environment.NewLine + "var C_Bucket = $(\"#C_Bucket\");" + System.Environment.NewLine + "var hf_C_Ids = $(\"#hf_C_Ids\");" + System.Environment.NewLine + "var hf_C_Bus_Count = $(\"#hf_C_Bus_Count\");" + System.Environment.NewLine + "var hf_C_Eng_Count = $(\"#hf_C_Eng_Count\");" + System.Environment.NewLine + "var X_Bucket = $(\"#X_Bucket\");" + System.Environment.NewLine + "var hf_X_Ids = $(\"#hf_X_Ids\");" + System.Environment.NewLine + "var hf_X_Bus_Count = $(\"#hf_X_Bus_Count\");" + System.Environment.NewLine + "var hf_X_Eng_Count = $(\"#hf_X_Eng_Count\");" + System.Environment.NewLine + "var hfProjectId = $(\"#hfProjectId\");";
            //Project p = ProjectService.GetProjectWithFullDetailsByGuid(new Guid("931b3f50-ff86-4a6c-a407-aafc5bbd0750"));
            //string actual = ProjectService.GetJsVariablesForElementsAndUIRules(ProjectService.GetStudentsForProjectGroupedByScore(p));
            //Assert.AreEqual(1, 1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the matchings for a project whenever user updates the details of a project
        /// </summary>
        /// <param name="studentIdsToAdd">List of student identifiers that will constitute the new matching list of the given project</param>
        public static void ReplaceMatchingsForProjectWith(int projectId, int[] studentIdsToAdd)
        {
            using (MatchingDB db = new MatchingDB())
            {
                Project project = db.Projects.Include("Matchings.Student").Include("ProjectRejects").Where(p => p.Id == projectId).FirstOrDefault();
                if (project.Matchings == null)
                    project.Matchings = new List<Matching>();
                IList<Matching> existingProjectMatchings = project.Matchings.ToList();
                IList<Matching> matchingsToRemove = existingProjectMatchings.Where(m => !studentIdsToAdd.Contains(m.Student.Id)).ToList();
                int[] studentIdsToRemove = matchingsToRemove.Select(m => m.Student.Id).ToArray();
                int[] newStudentIds = studentIdsToAdd.Where(sId => !existingProjectMatchings.Select(m => m.Student.Id).Contains(sId)).ToArray();
                var projectRejectsToRemove = project.ProjectRejects.Where(pr => studentIdsToRemove.Contains(pr.Student.Id)).ToList();
                #region Remove the students that is not on the UI but within the existing matchings of the projects and then add the students that did not appear within the list of existing matchings of the project but appeared on the UI
                //Remove students that do not appear in the list of students to add
                foreach (var m in matchingsToRemove)
                {
                    db.Matchings.Remove(m);
                }
                // Add students that did not exist before
                foreach (var sId in newStudentIds)
                {
                    Student st = db.Students.Include("StudentFeedbacks.Project").Where(s => s.Id == sId).FirstOrDefault();
                    Matching m = new Matching() { Project = project, Student = st, ProjectScore = ProjectScore.NoScore.ToString(), StudentScore = StudentScore.NoScore.ToString() };
                    db.Matchings.Add(m);
                    StudentFeedback studentFeedbackToRemove = st.StudentFeedbacks.Where(sf => sf.Project.Id == project.Id).FirstOrDefault();
                    if(studentFeedbackToRemove!=null)
                        db.StudentFeedbacks.Remove(studentFeedbackToRemove);
                }
                #endregion
                #region Clear the collection for the students replaced off the db.
                foreach (ProjectReject pr in projectRejectsToRemove)
                    db.ProjectRejects.Remove(pr);
                #endregion

                db.SaveChanges();
                // Not needed to delete constructive and positive feedback because only non-matching students should be providing Positive|Constructive Feedback StudentService.DeleteStudentFeedbacksReferencingProjectForStudents(projectId, studentsRemovedFromProject);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates matchings for a student with the user selections on Student Details screen
        /// </summary>
        /// <param name="projectIdsToAdd">List of project identifiers that will constitute the new matching list of the given student</param>
        public static void ReplaceMatchingsForStudentWith(int studentId, int[] projectIdsToAdd)
        {
            using (MatchingDB db = new MatchingDB())
            {
                Student student = db.Students.Include("Matchings.Project").Include("StudentFeedbacks.Project").Where(s => s.Id == studentId).FirstOrDefault();
                if (student.Matchings == null)
                    student.Matchings = new List<Matching>();
                IList<Matching> existingStudentMatchings = student.Matchings.ToList();
                IList<Matching> matchingsToRemove = existingStudentMatchings.Where(m => !projectIdsToAdd.Contains(m.Project.Id)).ToList();
                int[] projectIdsToRemove = matchingsToRemove.Select(m => m.Project.Id).ToArray();
                int[] newProjectIds = projectIdsToAdd.Where(pId => !existingStudentMatchings.Select(m => m.Project.Id).Contains(pId)).ToArray();
                int[] projectsRemovedFromStudent = matchingsToRemove.Where(m => m.Student.Id == studentId && !projectIdsToAdd.Contains(m.Project.Id)).Select(m => m.Project.Id).ToArray();
                IList<StudentFeedback> studentFeedbacksToBeDeleted = student.StudentFeedbacks.Where(sf => newProjectIds.Contains(sf.Project.Id)).ToList();

                //Remove projects that do not appear in the list of projects to add
                foreach (var m in matchingsToRemove)
                    db.Matchings.Remove(m);
                // Add projects that did not exist before
                foreach (var pId in newProjectIds)
                {
                    Project project = db.Projects.Where(p => p.Id == pId).FirstOrDefault();
                    Matching m = new Matching() { Project = project, Student = student, ProjectScore = ProjectScore.NoScore.ToString(), StudentScore = StudentScore.NoScore.ToString() };
                    db.Matchings.Add(m);
                }
                foreach (var sf in studentFeedbacksToBeDeleted)
                    db.StudentFeedbacks.Remove(sf);

                db.SaveChanges();
                ProjectService.DeleteProjectRejectsReferencingStudentForProjects(studentId, projectsRemovedFromStudent);
            }
        }