/** * <summary>This method removes a subject at a particular index position, inside the Student object.</summary> * * <param name="i">The index where the subject is to be removed from.</param> * * <example> * <code>Student sd = new Student("2608", "Bradley", "Wiley", 13, "Bronze"); * sd.AddSubjectToStudent(new Subject("FRE3", "French", "B", "A")); * sd.AddSubjectToStudent(new Subject("CHM3", "Chemistry", "A*", "A")); * sd.AddSubjectToStudent(new Subject("ENG3", "English", "C", "B")); * sd.RemoveSubject(2);</code> * The subject at index position 2 (English) will be removed.</example> */ public void RemoveSubject(int i) { if (0 <= i && i < GetSubjects.Count) { GetSubjects.RemoveAt(i); } }
/** * <summary>This method overrides the default 'ToString()' representation of the Student class.</summary> * * <example> * <code>Student sd = new Student("7142", "Ralph", "Dibney", 11, "Silver"); * sd.ToString();</code></example> * * <returns>The string representation of the Student object.</returns> */ public override string ToString() { string subjects = ""; GetSubjects.ForEach(_ => { subjects += _.ToString() + "\n"; }); return("\nID: #" + GetStudentID + "\nForename: " + GetForename + "\nSurname: " + GetSurname + "\nYear: " + GetYear + "\nClass: " + GetClassName + "\nSubjects:" + HelperMethods.DynamicSeparator("Subjects:", "+") + "\n" + subjects.Trim() + "\n"); }
/** * <summary>This method removes any duplicate subjects inside the Student object.</summary> * * <example> * <code>Student sd = new Student("5001", "Tom", "Curry", 10, "Purple"); * sd.AddSubjectToStudent(new Subject("GEO3", "Geography", "A", "B")); * sd.AddSubjectToStudent(new Subject("HIS3", "History", "B", "A*")); * sd.AddSubjectToStudent(new Subject("GEO3", "Geography", "A", "B")); * sd.RemoveDuplicateSubjects();</code> * The second occurence of 'Geography' will be removed as it already exists once. * </example> */ public void RemoveDuplicateSubjects() { for (int i = 0; i < GetSubjects.Count; i++) { for (int j = i + 1; j < GetSubjects.Count; j++) { if (GetSubject(i).GetSubjectID == GetSubject(j).GetSubjectID) { RemoveSubject(j); j--; } } } GetSubjects.Sort(); // Sorts the subjects inside GetSubjects into a natural order. }
public async Task <object> Get(GetSubjects request) { Expression <Func <Subject, bool> > filter = null; if (!request.Name.IsNullOrEmpty()) { filter = x => x.Name.Contains(request.Name); } var subjectEntities = await _subjectService.GetAll(filter : filter); var dtos = subjectEntities.ToList().ConvertAll(x => x.ConvertTo <SubjectDto>()); return(new { Success = true, StatusCode = (int)HttpStatusCode.OK, Results = dtos, ItemCount = dtos.Count }); }
// Methods. /** * <summary>This method stores a valid Subject object into the Student object.</summary> * * <param name="s">Subject object to be added to the student.</param> * * <example> * <code>Student sd = new Student("0021", "Jane", "Harper", 12, "Navy"); * sd.AddSubjectToStudent(new Subject("PSY4", "Psychology", "C", "A"));</code> * A new subject has been added to 'sd'.</example> */ public void AddSubjectToStudent(Subject s) { if (s != null) { if (GetSubjects.Count + 1 > ImportMethods.CheckNoSubjectsForYear(GetYear)) { // Throws an exception if there will be an invalid number of subjects for a student (dependent on the year). throw new ArgumentException("Invalid number of subjects for Year: " + GetYear + " student!"); } else { // Throws an exception if the subject already exists within the Student object. GetSubjects.ForEach(subject => { if (subject.GetSubjectID == s.GetSubjectID) { throw new ArgumentException("Subject already exists!"); } }); GetSubjects.Add(s); } } }
/// <summary> /// Get a List of all Subjects /// </summary> /// <returns>The <see cref="List{Subject}"/> of all returned Subjects.</returns> public async Task <List <Subject> > GetSubjects() { //Get the JSON GetSubjects subjects = new GetSubjects(); //Send and receive JSON from WebUntis string requestJson = JsonConvert.SerializeObject(subjects); string responseJson = await SendJsonAndWait(requestJson, _url, SessionId); //Parse JSON to Class SubjectsResult result = JsonConvert.DeserializeObject <SubjectsResult>(responseJson); string errorMsg = wus.LastError.Message; if (!SuppressErrors && errorMsg != null) { Logger.Append(Logger.LogLevel.Error, errorMsg); throw new WebUntisException(errorMsg); } //Return all the Subjects return(new List <Subject>(result.result)); }
/** * <summary>This method retrieves the total number of subjects that the Student exceeds, meets or falls belows their expected grades.</summary> * * <param name="type"></param> * * <example> * <code>Student sd = new Student("3650", "Oliver", "Ricardo", 9, "Copper"); * sd.AddSubjectToStudent(new Subject("MAT3", "Mathematics", "A*", "B")); * sd.AddSubjectToStudent(new Subject("BIO3", "Biology", "B", "B")); * sd.AddSubjectToStudent(new Subject("CHM3", "Chemistry", "A", "B")); * sd.AddSubjectToStudent(new Subject("PHY3", "Physics", "C", "B")); * sd.AddSubjectToStudent(new Subject("ENG3", "English", "B", "A"));</code> * </example> * * <example> * <code>sd.GetTargetCount("above");</code> * This will return '2'.</example> * * <example> * <code>sd.GetTargetCount("equal");</code> * This will return '1'.</example> * * <example> * <code>sd.GetTargetCount("below");</code> * This will return '2'.</example> * * <returns>The total number of subjects that satisfy the 'type' string parameter are returned.</returns> */ public int GetTargetCount(string type) { int count = 0; if (!string.IsNullOrWhiteSpace(type)) { if (type == "above") { count = GetSubjects.Where(_ => !_.GetExpectedGrade.Contains("*") && (_.GetActualGrade.Contains("*") || _.GetActualGrade.CompareTo(_.GetExpectedGrade) == -1)).Count(); } else if (type == "equal") { count = GetSubjects.Where(_ => _.GetActualGrade.CompareTo(_.GetExpectedGrade) == 0).Count(); } else if (type == "below") { count = GetSubjects.Where(_ => !_.GetActualGrade.Contains("*") && (_.GetExpectedGrade.Contains("*") || _.GetActualGrade.CompareTo(_.GetExpectedGrade) == 1)).Count(); } } return(count); }