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(StudentRegisteredToClassEvent evt) { registrationSequence = registrationSequence.Next(); registrations.Add(new Registration(this, registrationSequence.ToId(), evt.ClassId, evt.Credits)); }