public override bool ApplyEvent(IEvent @event, EnvelopeHeaders headers) { switch (@event) { case ContentCreated e: { Id = e.ContentId; SimpleMapper.Map(e, this); CurrentVersion = new ContentVersion(e.Status, e.Data); break; } case ContentDraftCreated e: { NewVersion = new ContentVersion(e.Status, e.MigratedData ?? CurrentVersion.Data); ScheduleJob = null; break; } case ContentDraftDeleted _: { NewVersion = null; ScheduleJob = null; break; } case ContentStatusChanged e: { ScheduleJob = null; if (NewVersion != null) { if (e.Status == Status.Published) { CurrentVersion = new ContentVersion(e.Status, NewVersion.Data); NewVersion = null; } else { NewVersion = NewVersion.WithStatus(e.Status); } } else { CurrentVersion = CurrentVersion.WithStatus(e.Status); } break; } case ContentSchedulingCancelled _: { ScheduleJob = null; break; } case ContentStatusScheduled e: { ScheduleJob = ScheduleJob.Build(e.Status, e.Actor, e.DueTime); break; } case ContentUpdated e: { if (NewVersion != null) { NewVersion = NewVersion.WithData(e.Data); } else { CurrentVersion = CurrentVersion.WithData(e.Data); } break; } case ContentDeleted _: { IsDeleted = true; break; } } return(true); }