public void Handle(StudentGraduatedEvent evt)
 {
     persistenceManager.ExecuteNonQuery(
         "UPDATE [Student] SET hasGraduated = 1 WHERE Id = @Id",
         new
     {
         Id = evt.StudentId
     });
 }
 public void Handle(StudentCreditsChangedEvent evt)
 {
     persistenceManager.ExecuteNonQuery(
         "UPDATE [Student] SET credits = @Credits WHERE Id = @Id",
         new
     {
         Id      = evt.StudentId,
         Credits = evt.Credits
     });
 }
 public void Handle(StudentCreatedEvent evt)
 {
     persistenceManager.ExecuteNonQuery(
         "INSERT INTO [Student] (Id, version) VALUES (@Id, @Version)",
         new
     {
         Id      = evt.StudentId,
         Version = DateTime.Now,
     });
 }
 public void Handle(StudentFailedEvent evt)
 {
     persistenceManager.ExecuteNonQuery(
         "INSERT failedClasses SELECT @Id, classId FROM Registration WHERE aggregateRoot = @Id AND Id = @Registration;" +
         "DELETE FROM [Registration] WHERE aggregateRoot = @Id AND Id = @Registration;",
         new
     {
         Id           = evt.StudentId,
         Registration = evt.ClassRegistrationId
     });
 }
Esempio n. 5
0
 public void Handle(StudentNameCorrectedEvent evt)
 {
     persistenceManager.ExecuteNonQuery(
         "UPDATE [Student] SET firstName = @FirstName, lastName = @LastName WHERE Id = @Id",
         new
     {
         Id        = evt.StudentId,
         FirstName = evt.FirstName,
         LastName  = evt.LastName
     });
 }
Esempio n. 6
0
 public void Handle(ClassCreatedEvent evt)
 {
     persistenceManager.ExecuteNonQuery(
         "INSERT INTO [Class] (Id, version, name, credits) VALUES (@Id, @Version, @Name, @Credits)",
         new
     {
         Id      = evt.ClassId,
         Version = DateTime.Now,
         Name    = evt.Name,
         Credits = evt.Credits
     });
 }
 public void Handle(StudentRegisteredToClassEvent evt)
 {
     persistenceManager.ExecuteNonQuery(
         "INSERT INTO [Registration] (aggregateRoot, Id, version, classId, classCredits) VALUES (@Id, @Registration, @Version, @ClassId, @ClassCredits);" +
         "UPDATE [Student] SET registrationSequence = @Registration WHERE Id = @Id;",
         new
     {
         Id           = evt.StudentId,
         Registration = evt.RegistrationId,
         Version      = DateTime.Now,
         ClassId      = evt.ClassId,
         ClassCredits = evt.Credits
     });
 }
 public void PersistUncommitedEvents(IAggregateRoot aggregate)
 {
     try
     {
         persistenceManager.ExecuteNonQuery(
             "INSERT INTO [Events] (Id, aggregate_id, version, data) VALUES (@Id, @AggregateId, @Version, @Data)",
             new
         {
             Id          = Guid.NewGuid(),
             Version     = aggregate.Version + 1,
             AggregateId = aggregate.Id,
             Data        = Serialize(aggregate.UncommitedEvents)
         });
     }
     catch (SqlException se)
     {
         // Thanks Jonathan Oliver's CQRS Event Store
         if (se.Number == UniqueKeyViolation)
         {
             throw new ConcurrencyException();
         }
         throw;
     }
 }