Beispiel #1
0
        public static MessageResult MultipleRemove(int[] ds)
        {
            var result = CheckIdResult <Field> .Create(ds, ActionTypeCode.Remove);

            var removeMsgResults = new List <MessageResult>();

            foreach (var id in result.ValidIds)
            {
                var violationMessages = Field.Die(id).ToList();
                if (violationMessages.Any())
                {
                    removeMsgResults.Add(MessageResult.Error(string.Join(Environment.NewLine, violationMessages), new[] { id }));
                }
            }

            if (removeMsgResults.Count > 0)
            {
                var checkResult = result.GetServiceResult();
                var ids         = new List <int>(checkResult != null ? checkResult.FailedIds : new int[0]);
                foreach (var msgr in removeMsgResults)
                {
                    ids.AddRange(msgr.FailedIds);
                }

                var msg = string.Concat(checkResult != null ? checkResult.Text : string.Empty, Environment.NewLine, string.Join("", removeMsgResults.Select(r => r.Text)));
                return(MessageResult.Error(msg, ids.Distinct().ToArray()));
            }

            return(result.GetServiceResult());
        }
Beispiel #2
0
        private static MessageResult RestoreFromArchiveInternal(int contentId, int[] ids, bool?boundToExternal, bool disableNotifications)
        {
            if (ids == null)
            {
                throw new ArgumentNullException(nameof(ids));
            }

            if (ContentRepository.IsAnyAggregatedFields(contentId))
            {
                return(MessageResult.Error(ArticleStrings.OperationIsNotAllowedForAggregated));
            }

            var content = ContentRepository.GetById(contentId);

            if (!content.IsArticleChangingActionsAllowed(boundToExternal))
            {
                return(MessageResult.Error(ContentStrings.ArticleChangingIsProhibited));
            }

            if (!content.AllowItemsPermission && !SecurityRepository.IsEntityAccessible(EntityTypeCode.Content, contentId, ActionTypeCode.Update))
            {
                return(MessageResult.Error(ArticleStrings.CannotUpdateBecauseOfSecurity));
            }

            var disableSecurityCheck = !content.AllowItemsPermission;
            var result = CheckIdResult <Article> .CreateForUpdate(contentId, ids, disableSecurityCheck);

            var idsToProceed = result.ValidItems.Cast <Article>().SelectMany(a => a.SelfAndChildIds).ToArray();
            var idsToNotify  = result.ValidItems.Cast <Article>().Select(n => n.Id).ToArray();

            var repo = new NotificationPushRepository();

            repo.PrepareNotifications(contentId, idsToNotify, new[] { NotificationCode.Update }, disableNotifications);
            ArticleRepository.SetArchiveFlag(idsToProceed, false);
            repo.SendNotifications();

            return(result.GetServiceResult());
        }
Beispiel #3
0
        public static MessageResult RemoveInternal(int contentId, int[] ids, bool fromArchive, bool?boundToExternal, bool disableNotifications)
        {
            if (ContentRepository.IsAnyAggregatedFields(contentId))
            {
                return(MessageResult.Error(ArticleStrings.OperationIsNotAllowedForAggregated));
            }

            if (ids == null)
            {
                throw new ArgumentNullException(nameof(ids));
            }

            var content = ContentRepository.GetById(contentId);

            if (!content.IsArticleChangingActionsAllowed(boundToExternal))
            {
                return(MessageResult.Error(ContentStrings.ArticleChangingIsProhibited));
            }

            if (content == null)
            {
                throw new Exception(string.Format(ContentStrings.ContentNotFound, contentId));
            }

            if (!content.AllowItemsPermission && !SecurityRepository.IsEntityAccessible(EntityTypeCode.Content, contentId, ActionTypeCode.Remove))
            {
                return(MessageResult.Error(ArticleStrings.CannotRemoveBecauseOfSecurity));
            }

            var disableSecurityCheck = !content.AllowItemsPermission;
            var result = CheckIdResult <Article> .CreateForRemove(contentId, ids, disableSecurityCheck);

            var idsToProceed = result.ValidItems.Cast <Article>().SelectMany(a => a.SelfAndChildIds).ToArray();
            var idsToNotify  = result.ValidItems.Select(n => n.Id).ToArray();

            var isUpdate = content.AutoArchive && !fromArchive;
            var code     = isUpdate ? NotificationCode.Update : NotificationCode.Delete;
            var repo     = new NotificationPushRepository();

            repo.PrepareNotifications(contentId, idsToNotify, code, disableNotifications);

            if (content.AutoArchive && !fromArchive)
            {
                ArticleRepository.SetArchiveFlag(idsToProceed, true);
                repo.SendNotifications();
            }
            else
            {
                repo.SendNonServiceNotifications(true);
                foreach (var entry in result.ValidItems)
                {
                    var article = (Article)entry;
                    article.RemoveAllVersionFolders();
                }

                ArticleRepository.MultipleDelete(idsToProceed);
                repo.SendServiceNotifications();
            }

            return(result.GetServiceResult());
        }