コード例 #1
0
        public IVoidResult RemoveStudent(Student student)
        {
            var result = new VoidResult();

            if (!Students.Contains(student))
            {
                return(result.AddErrorMessage(string.Format("{0}'s students collection does not contain this student ({1})", Name, student.FullName)));
            }

            if (student.Courses == null || !student.Courses.Contains(this))
            {
                return(result.AddErrorMessage(string.Format("{0}'s courses collection does not contain this course ({1})", student.FullName, Name)));
            }

            Students.Remove(student);
            student.Courses.Remove(this);

            return(result);
        }
コード例 #2
0
        public IVoidResult AddStudent(Student student)
        {
            var result = new VoidResult();

            if (Students.Any(s => s.SurName.Equals(student.SurName, StringComparison.InvariantCultureIgnoreCase)))
            {
                return(result.AddErrorMessage("Another student with this surname already exists in this course"));
            }

            Students.Add(student);
            if (student.Courses == null)
            {
                student.Courses = new Collection <Course>();
            }
            student.Courses.Add(this);

            return(result);
        }