public Student(string firstName, string lastName)
        {
            CorrectName(firstName, lastName);

            registrations = new HashedSet<Registration>();
            passedClasses = new HashedSet<Guid>();
            failedClasses = new HashedSet<Guid>();
            registrationSequence = new IdSequence(0);
            credits = 0;
            HasGraduated = false;
        }
 private void Apply(StudentRegisteredToClassEvent evt)
 {
     registrationSequence = registrationSequence.Next();
     registrations.Add(new Registration(this, registrationSequence.ToId(), evt.ClassId, evt.Credits));
 }
        public virtual void RegisterTo(Class @class)
        {
            // Business rules
            @class.Validation().NotNull("class");
            if (registrations.Where(x => x.Class.Id == @class.Id).Count() > 0)
            {
                throw new InvalidOperationException("You can not register a student to a class he already registered");
            }
            if (passedClasses.Where(x => x == @class.Id).Count() > 0)
            {
                throw new InvalidOperationException("You can not register a student to a class he already passed");
            }

            // State changes
            registrationSequence = registrationSequence.Next();
            registrations.Add(new Registration(this, registrationSequence.ToId(), @class));
        }
 private void Apply(StudentCreatedEvent evt)
 {
     // Only set defaults here.
     registrationSequence = new IdSequence(0);
     hasGraduated = false;
     credits = 0;
 }