Пример #1
0
 public Contact(Student s)
 {
     this.Id = s.Id;
     this.FirstName = s.FirstName;
     this.LastName = s.LastName;
     this.Email = s.Email;
     this.Guid = s.Guid;
     this.ContactType = ContactType.Student;
 }
 public ActionResult Create(Student st)
 {
     if (!ValidateStudent(st))
         this.ModelState.AddModelError("UniqueName", uniqueNameErrorMsg);
     if (ModelState.IsValid)
     {
         MatchingDB db = new MatchingDB();
         st.Guid = Guid.NewGuid();
         db.Students.Add(st);
         db.SaveChanges();
         TempData["message"] = "Student \"" + st.FirstName+" "+st.LastName + "\" is added!";
         db.Dispose();
         return RedirectToAction("Index");
     }
     setViewDataForListOfDegrees();
     return View(st);
 }
        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);
        }
Пример #4
0
        /// <summary>
        /// Extracts all matching projects from student and group them by the scores assigned to the projects by the student in a dictionary whose key is the score and the value is the list of rpojects who got that score.
        /// </summary>
        /// <param name="project">Detached student object which should have had its all properties eagerly loaded, otherwise an exception will be thrown.</param>
        /// <returns>A dictionary whose key is the score assigned to the list of students in the dictionary's value.</returns>
        public static IDictionary<ScoreDetail, IList<Project>> GetProjectsForStudentGroupedByScore(Student student)
        {
            if (student.Matchings == null || student.Matchings.Count == 0 || student.Matchings.Select(m => m.Student).Count() == 0)
                throw new ArgumentException("There are no matching projects for the student. Make sure all properties of your student was eagerly loaded before it was passed as parameter.", "student");

            var unsortedDict = student.Matchings.GroupBy(m => UIParamsAndMessages.StudentScoreDetails.Where(sd => sd.Score == m.StudentScore).FirstOrDefault()).ToDictionary(key => key.Key, value => value.Select(m => m.Project).ToList() as IList<Project>);

            System.Collections.Generic.SortedDictionary<ScoreDetail, IList<Project>> dict = new System.Collections.Generic.SortedDictionary<ScoreDetail, IList<Project>>(unsortedDict);

            foreach (ScoreDetail sd in UIParamsAndMessages.StudentScoreDetails)
            {
                if (!dict.Keys.Contains(sd))
                    dict.Add(sd, new List<Project>());
            }
            return dict;
        }
 private bool ValidateStudent(Student s)
 {
     return GetStudentCountByUniqueName(s.UniqueName) == 0;
 }
        public ActionResult Edit(Student st)
        {
            if (!ModelState.IsValid)
                return View(st);
            MatchingDB db = new MatchingDB();
            Student student = db.Students.FirstOrDefault(s => s.Id == st.Id);
            if (student.UniqueName.ToLower() != st.UniqueName.ToLower() && !ValidateStudent(st))
            {
                setViewDataForListOfDegrees();
                this.ModelState.AddModelError("UniqueName", uniqueNameErrorMsg);
                return View(st);
            }

            student.UniqueName = st.UniqueName;
            student.LastName = st.LastName;
            student.FirstName = st.FirstName;
            student.Email = st.Email;
            student.Degree = st.Degree;
            student.Comments = st.Comments;
            db.SaveChanges();
            TempData["message"] = "Student \"" + student.FirstName+" "+student.LastName + "\" is updated.";
            db.Dispose();
            return RedirectToAction("Index");
        }