Example #1
0
        public void AddVersion(AddVersion cmd, IValidator <AddVersion> validator)
        {
            if (cmd.Status != TextVersionStatus.Published && cmd.Status != TextVersionStatus.Draft)
            {
                throw new Exception("Status of a new version should be either Published or Draft.");
            }

            validator.ValidateCommand(cmd);

            var newVersion = new TextVersion(cmd.VersionId,
                                             Id,
                                             cmd.Content,
                                             cmd.Description,
                                             cmd.Status,
                                             GetVersionLocalisations(cmd));

            TextVersions.Add(newVersion);

            if (newVersion.Status == TextVersionStatus.Published)
            {
                var currentPublishedVersion = TextVersions.FirstOrDefault(x => x.Status == TextVersionStatus.Published);
                currentPublishedVersion?.UnPublish();
            }

            AddEvent(new VersionAdded
            {
                SiteId          = cmd.SiteId,
                ModuleId        = cmd.ModuleId,
                AggregateRootId = Id,
                VersionId       = cmd.VersionId,
                Content         = cmd.Content,
                Description     = cmd.Description,
                Status          = cmd.Status
            });
        }
Example #2
0
        private void Apply(VersionAdded @event)
        {
            var newVersion = new TextVersion(@event.VersionId,
                                             Id,
                                             @event.Content,
                                             @event.Description,
                                             @event.Status,
                                             GetVersionLocalisations(@event));

            TextVersions.Add(newVersion);

            if (newVersion.Status == TextVersionStatus.Published)
            {
                var currentPublishedVersion = TextVersions.FirstOrDefault(x => x.Status == TextVersionStatus.Published);
                currentPublishedVersion?.UnPublish();
            }
        }