示例#1
0
        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));
        }
示例#3
0
 private void Apply(StudentRegisteredToClassEvent evt)
 {
     registrationSequence = registrationSequence.Next();
     registrations.Add(new Registration(this, registrationSequence.ToId(), evt.ClassId, evt.Credits));
 }