public static ArticleVersion GetMergedVersion(int[] ids, int parentId) { if (ids == null) { throw new ArgumentNullException(nameof(ids)); } if (ids.Length != 2) { throw new ArgumentException("Wrong ids length"); } var parent = ArticleRepository.GetById(parentId); if (parent == null) { throw new Exception(string.Format(ArticleStrings.ArticleNotFound, parentId)); } var(item1, item2) = GetOrderedIds(ids); ArticleVersion version1, version2; if (item1 == ArticleVersion.LiveVersionId) { var liveArticle = ArticleService.ReadLive(parentId, parent.ContentId); version1 = CreateVersionFromArticle(liveArticle); version1.Id = ArticleVersion.LiveVersionId; } else { version1 = ArticleVersionRepository.GetById(item1, parentId); if (version1 == null) { throw new Exception(string.Format(ArticleStrings.ArticleVersionNotFoundForArticle, item1, parentId)); } } if (item2 == ArticleVersion.CurrentVersionId) { version2 = CreateVersionFromArticle(parent); version2.Id = ArticleVersion.CurrentVersionId; } else { version2 = ArticleVersionRepository.GetById(item2, parentId); if (version2 == null) { throw new Exception(string.Format(ArticleStrings.ArticleVersionNotFoundForArticle, item2, parentId)); } } version1.MergeToVersion(version2); version1.Article.ViewType = ArticleViewType.CompareVersions; version1.AggregatedArticles.ForEach(x => { x.ViewType = ArticleViewType.CompareVersions; }); return(version1); }
public static ArticleVersion Read(int id, int articleId = 0) { var result = ArticleVersionRepository.GetById(id, articleId); if (result == null) { throw new Exception(string.Format(ArticleStrings.ArticleVersionNotFoundForArticle, id, articleId)); } result.Article.ViewType = ArticleViewType.PreviewVersion; return(result); }
public static IEnumerable <BackendActionStatus> ResolveStatusesForArticleVersion(this IEnumerable <BackendActionStatus> statuses, int entityId, bool?boundToExternal) { var version = ArticleVersionRepository.GetById(entityId); if (!version.Article.IsArticleChangingActionsAllowed(boundToExternal)) { var excluded = statuses.Where(s => ActionCode.ArticleNonChangingActionCodes.Contains(s.Code)); foreach (var excludedItem in excluded) { excludedItem.Visible = false; } } return(statuses); }
public static ArticleVersion GetMergedVersion(int[] ids, int parentId) { if (ids == null) { throw new ArgumentNullException(nameof(ids)); } if (ids.Length != 2) { throw new ArgumentException("Wrong ids length"); } var result = GetOrderedIds(ids); var version1 = ArticleVersionRepository.GetById(result.Item1, parentId); if (version1 == null) { throw new Exception(string.Format(ArticleStrings.ArticleVersionNotFoundForArticle, result.Item1, parentId)); } ArticleVersion version2; if (result.Item2 == ArticleVersion.CurrentVersionId) { var parent = ArticleRepository.GetById(parentId); if (parent == null) { throw new Exception(string.Format(ArticleStrings.ArticleNotFound, parentId)); } version2 = new ArticleVersion { ArticleId = parent.Id, Article = parent, Id = ArticleVersion.CurrentVersionId, Modified = parent.Modified, LastModifiedBy = parent.LastModifiedBy, LastModifiedByUser = parent.LastModifiedByUser }; } else { version2 = ArticleVersionRepository.GetById(result.Item2, parentId); if (version2 == null) { throw new Exception(string.Format(ArticleStrings.ArticleVersionNotFoundForArticle, result.Item2, parentId)); } } version1.MergeToVersion(version2); version1.Article.ViewType = ArticleViewType.CompareVersions; version1.AggregatedArticles.ForEach(x => { x.ViewType = ArticleViewType.CompareVersions; }); return(version1); }
public static PathInfo GetPathInfo(int fieldId, int id) { if (id != ArticleVersion.CurrentVersionId) { var result = ArticleVersionRepository.GetById(id); if (result == null) { throw new Exception(string.Format(ArticleStrings.ArticleVersionNotFound, id)); } return(result.PathInfo); } var field = FieldRepository.GetById(fieldId); if (field == null) { throw new Exception(string.Format(FieldStrings.FieldNotFound, fieldId)); } return(field.Content.GetVersionPathInfo(ArticleVersion.CurrentVersionId)); }
public static MessageResult MultipleRemove(int[] ids, bool?boundToExternal) { if (ids == null) { throw new ArgumentNullException(nameof(ids)); } if (ids.Length == 0) { throw new ArgumentException("ids is empty"); } var version = ArticleVersionRepository.GetById(ids[0]); if (version == null) { throw new Exception(string.Format(ArticleStrings.ArticleVersionNotFound, ids[0])); } var article = version.Article; if (!article.IsUpdatable) { return(MessageResult.Error(ArticleStrings.CannotRemoveVersionsBecauseOfSecurity)); } if (!version.Article.IsArticleChangingActionsAllowed(boundToExternal)) { return(MessageResult.Error(ContentStrings.ArticleChangingIsProhibited)); } foreach (var id in ids) { article.RemoveVersionFolder(id); } ArticleVersionRepository.MultipleDelete(ids); return(null); }
public static MessageResult Remove(int id, bool?boundToExternal) { var version = ArticleVersionRepository.GetById(id); if (version == null) { throw new Exception(string.Format(ArticleStrings.ArticleVersionNotFound, id)); } if (!version.Article.IsUpdatable) { return(MessageResult.Error(ArticleStrings.CannotRemoveVersionsBecauseOfSecurity)); } if (!version.Article.IsArticleChangingActionsAllowed(boundToExternal)) { return(MessageResult.Error(ContentStrings.ArticleChangingIsProhibited)); } version.Article.RemoveVersionFolder(id); ArticleVersionRepository.Delete(id); return(null); }
public ArticleVersion() { _versionRowData = new Lazy <DataRow>(() => ArticleVersionRepository.GetData(Id, ArticleId)); }
public static List <ArticleVersion> List(int articleId, ListCommand command) { command.SortExpression = ArticleVersion.TranslateSortExpression(command.SortExpression); return(ArticleVersionRepository.GetList(articleId, command)); }