public Contact(Project p) { this.Id = p.Id; this.FirstName = p.ContactFirst; this.LastName = p.ContactLast; this.Email = p.ContactEmail; this.Guid = p.Guid; this.ContactType = ContactType.Project; }
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); }
private string GetRankingConfirmationText(Project p) { StringBuilder builder = new StringBuilder(); foreach (var group in p.Matchings.Where(m=>m.ProjectScore!=ProjectScore.Reject.ToString()).OrderBy(m=>m.ProjectScore).GroupBy(m => m.ProjectScore)) { builder.Append("<b>" + _scoreDictionary[group.Key] + ": </b>"); foreach (Matching m in group) builder.Append(m.Student.FullName + ", "); builder.Remove((builder.Length - 2), 2); builder.Append("<br/>"); } builder.Append("<br/><br/>"); foreach (var reject in p.ProjectRejects) { builder.Append("<b>"+reject.Student.FullName+" is rejected. Reason is: </b>"+reject.Reason+"<br/>"); } if (p.Feedback != null && p.Feedback != "" && p.Feedback.Length > 0) builder.Append("<b>Your Comments: </b>" + p.Feedback + "<br/>"); builder.Append("<br/>"); return builder.ToString(); }
/// <summary> /// Extracts all matching students from project and group them by the scores assigned to the students by the project contact in a dictionary whose key is the score and the value is the list of students who got that score. /// </summary> /// <param name="project">Detached project 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<Student>> GetStudentsForProjectGroupedByScore(Project project) { if (project.Matchings == null || project.Matchings.Count == 0 || project.Matchings.Select(m => m.Student).Count() == 0) throw new ArgumentException("There are no matching students for the project. Make sure all properties of your project was eagerly loaded before it was passed as parameter.", "project"); var unsortedDict = project.Matchings.GroupBy(m => UIParamsAndMessages.ProjectScoreDetails.Where(sd => sd.Score == m.ProjectScore).FirstOrDefault()) .ToDictionary(key => key.Key, value => value.Select(m => m.Student).ToList() as IList<Student>); System.Collections.Generic.SortedDictionary<ScoreDetail,IList<Student>> dict = new System.Collections.Generic.SortedDictionary<ScoreDetail,IList<Student>>(unsortedDict); foreach (ScoreDetail sd in UIParamsAndMessages.ProjectScoreDetails) { if (!dict.Keys.Contains(sd)) dict.Add(sd, new List<Student>()); } return dict; }
public static IDictionary<StudentDegree, int> GetStudentsCountForProjectGroupedByDegree(Project project) { if (project.Matchings == null || project.Matchings.Count == 0 || project.Matchings.Select(m => m.Student).Count() == 0) throw new ArgumentException("project", "There are no matching students for the project. Make sure all properties of your project was eagerly loaded before it was passed as parameter."); var dict = project.Matchings.GroupBy(m => m.Student.Degree).ToDictionary(key => (StudentDegree)Enum.Parse(typeof(StudentDegree), key.Key), value => value.Select(m => m.Student).ToList().Count); foreach (StudentDegree sd in Enum.GetValues(typeof(StudentDegree))) { if (!dict.Keys.Contains(sd)) dict.Add(sd, 0); } return dict; }
private void SendConfirmationMessage(Project p) { Contact c = new Contact(p); EmailQueueMessage eqm = new EmailQueueMessage(c, EmailType.ProjectSubmit, GetRankingConfirmationText(p), c.Email + "," + _confMesgReceipents); EmailQueueService.QueueMessage(eqm); }