Ejemplo n.º 1
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new RequestImpl();

                var siteId        = request.GetPostInt("siteId");
                var channelId     = request.GetPostInt("channelId");
                var contentIdList = TranslateUtils.StringCollectionToIntList(request.GetPostString("contentIds"));
                var isRetainFiles = request.GetPostBool("isRetainFiles");

                if (!request.IsUserLoggin ||
                    !request.UserPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                       ConfigManager.ChannelPermissions.ContentDelete))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                if (!isRetainFiles)
                {
                    DeleteManager.DeleteContents(siteInfo, channelId, contentIdList);
                }

                var tableName = ChannelManager.GetTableName(siteInfo, channelInfo);

                if (contentIdList.Count == 1)
                {
                    var contentId    = contentIdList[0];
                    var contentTitle = DataProvider.ContentDao.GetValue(tableName, contentId, ContentAttribute.Title);
                    request.AddSiteLog(siteId, channelId, contentId, "删除内容",
                                       $"栏目:{ChannelManager.GetChannelNameNavigation(siteId, channelId)},内容标题:{contentTitle}");
                }
                else
                {
                    request.AddSiteLog(siteId, "批量删除内容",
                                       $"栏目:{ChannelManager.GetChannelNameNavigation(siteId, channelId)},内容条数:{contentIdList.Count}");
                }

                DataProvider.ContentDao.UpdateTrashContents(siteId, channelId, tableName, contentIdList);

                CreateManager.TriggerContentChangedEvent(siteId, channelId);

                return(Ok(new
                {
                    Value = contentIdList
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
        public void Delete_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            try
            {
                var channelIdList = TranslateUtils.StringCollectionToIntList(AuthRequest.GetQueryString("ChannelIDCollection"));
                channelIdList.Sort();
                channelIdList.Reverse();

                var channelIdListToDelete = new List <int>();
                foreach (var channelId in channelIdList)
                {
                    if (channelId == SiteId)
                    {
                        continue;
                    }
                    if (HasChannelPermissions(channelId, ConfigManager.ChannelPermissions.ChannelDelete))
                    {
                        channelIdListToDelete.Add(channelId);
                    }
                }

                var builder = new StringBuilder();
                foreach (var channelId in channelIdListToDelete)
                {
                    builder.Append(ChannelManager.GetChannelName(SiteId, channelId)).Append(",");
                }

                if (builder.Length > 0)
                {
                    builder.Length -= 1;
                }

                if (_deleteContents)
                {
                    SuccessMessage(bool.Parse(RblRetainFiles.SelectedValue) == false
                        ? "成功删除内容以及生成页面!"
                        : "成功删除内容,生成页面未被删除!");

                    foreach (var channelId in channelIdListToDelete)
                    {
                        var tableName     = ChannelManager.GetTableName(SiteInfo, channelId);
                        var contentIdList = DataProvider.ContentDao.GetContentIdList(tableName, channelId);
                        DeleteManager.DeleteContents(SiteInfo, channelId, contentIdList);
                        DataProvider.ContentDao.UpdateTrashContents(SiteId, channelId, tableName, contentIdList);
                    }

                    AuthRequest.AddSiteLog(SiteId, "清空栏目下的内容", $"栏目:{builder}");
                }
                else
                {
                    if (bool.Parse(RblRetainFiles.SelectedValue) == false)
                    {
                        DeleteManager.DeleteChannels(SiteInfo, channelIdListToDelete);
                        SuccessMessage("成功删除栏目以及相关生成页面!");
                    }
                    else
                    {
                        SuccessMessage("成功删除栏目,相关生成页面未被删除!");
                    }

                    foreach (var channelId in channelIdListToDelete)
                    {
                        var tableName = ChannelManager.GetTableName(SiteInfo, channelId);
                        DataProvider.ContentDao.UpdateTrashContentsByChannelId(SiteId, channelId, tableName);
                        DataProvider.ChannelDao.Delete(SiteId, channelId);
                    }

                    AuthRequest.AddSiteLog(SiteId, "删除栏目", $"栏目:{builder}");
                }

                AddWaitAndRedirectScript(ReturnUrl);
            }
            catch (Exception ex)
            {
                FailMessage(ex, _deleteContents ? "删除内容失败!" : "删除栏目失败!");

                LogUtils.AddErrorLog(ex);
            }
        }
Ejemplo n.º 3
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            try
            {
                foreach (var channelId in _idsDictionary.Keys)
                {
                    var tableName     = ChannelManager.GetTableName(SiteInfo, channelId);
                    var contentIdList = _idsDictionary[channelId];

                    if (!_isDeleteFromTrash)
                    {
                        if (bool.Parse(RblRetainFiles.SelectedValue) == false)
                        {
                            DeleteManager.DeleteContents(SiteInfo, channelId, contentIdList);
                            SuccessMessage("成功删除内容以及生成页面!");
                        }
                        else
                        {
                            SuccessMessage("成功删除内容,生成页面未被删除!");
                        }

                        if (contentIdList.Count == 1)
                        {
                            var contentId    = contentIdList[0];
                            var contentTitle = DataProvider.ContentDao.GetValue(tableName, contentId, ContentAttribute.Title);
                            AuthRequest.AddSiteLog(SiteId, channelId, contentId, "删除内容",
                                                   $"栏目:{ChannelManager.GetChannelNameNavigation(SiteId, channelId)},内容标题:{contentTitle}");
                        }
                        else
                        {
                            AuthRequest.AddSiteLog(SiteId, "批量删除内容",
                                                   $"栏目:{ChannelManager.GetChannelNameNavigation(SiteId, channelId)},内容条数:{contentIdList.Count}");
                        }

                        DataProvider.ContentDao.UpdateTrashContents(SiteId, channelId, tableName, contentIdList);

                        //引用内容,需要删除
                        //var siteTableNameList = SiteManager.GetTableNameList();
                        //foreach (var siteTableName in siteTableNameList)
                        //{
                        //    var targetContentIdList = DataProvider.ContentDao.GetReferenceIdList(siteTableName, contentIdList);
                        //    if (targetContentIdList.Count > 0)
                        //    {
                        //        var targetContentInfo = ContentManager.GetContentInfo(siteTableName, TranslateUtils.ToInt(targetContentIdList[0].ToString()));
                        //        DataProvider.ContentDao.DeleteContents(targetContentInfo.SiteId, siteTableName, targetContentIdList, targetContentInfo.ChannelId);
                        //    }
                        //}

                        CreateManager.TriggerContentChangedEvent(SiteId, channelId);
                    }
                    else
                    {
                        SuccessMessage("成功从回收站清空内容!");
                        DataProvider.ContentDao.DeleteContents(SiteId, tableName, contentIdList, channelId);

                        AuthRequest.AddSiteLog(SiteId, "从回收站清空内容", $"内容条数:{contentIdList.Count}");
                    }
                }


                AddWaitAndRedirectScript(_returnUrl);
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                FailMessage(ex, "删除内容失败!");
            }
        }