public virtual void RegisterTo(Class @class) { // Business rules @class.Validation().NotNull("class"); if (registrations.Where(x => x.ClassId == @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 ApplyEvent(new StudentRegisteredToClassEvent(Id, @class.Id, registrationSequence.Next().ToId(), @class.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(StudentRegisteredToClassEvent evt) { registrationSequence = registrationSequence.Next(); registrations.Add(new Registration(this, registrationSequence.ToId(), evt.ClassId, evt.Credits)); }