Exemplo n.º 1
0
        public static int DeleteArticles(IList <int> articles)
        {
            if (articles == null || articles.Count == 0)
            {
                return(0);
            }
            int        num        = 0;
            ArticleDao articleDao = new ArticleDao();

            foreach (int article in articles)
            {
                if (articleDao.Delete <ArticleInfo>(article))
                {
                    num++;
                }
            }
            return(num);
        }
Exemplo n.º 2
0
        public void Page_Load(object sender, EventArgs e)
        {
            var request = SiteServer.Plugin.Context.GetCurrentRequest();

            _siteId    = request.GetQueryInt("siteId");
            _contentId = request.GetQueryInt("contentId");

            if (!request.AdminPermissions.HasSitePermissions(_siteId, Main.PluginId))
            {
                Response.Write("<h1>未授权访问</h1>");
                Response.End();
                return;
            }

            if (!string.IsNullOrEmpty(Request.QueryString["delete"]) &&
                !string.IsNullOrEmpty(Request.QueryString["idCollection"]))
            {
                var list = Request.QueryString["idCollection"].Split(',').Select(s => Convert.ToInt32(s)).ToList();
                ArticleDao.Delete(list);
                LtlMessage.Text = Utils.GetMessageHtml("删除成功!", true);
            }

            SpArticles.ControlToPaginate = RptArticles;
            SpArticles.ItemsPerPage      = 30;
            SpArticles.SelectCommand     = ArticleDao.GetSelectString(_siteId, _contentId);
            SpArticles.SortField         = nameof(ArticleInfo.Taxis);
            SpArticles.SortMode          = "ASC";
            RptArticles.ItemDataBound   += RptArticles_ItemDataBound;

            if (IsPostBack)
            {
                return;
            }

            SpArticles.DataBind();

            BtnAdd.Attributes.Add("onclick",
                                  $"location.href = '{GetRedirectUrl(_siteId, _contentId)}&addArticle={true}';return false;");

            BtnDelete.Attributes.Add("onclick", Utils.ReplaceNewline($@"
var ids = [];
$(""input[name='idCollection']:checked"").each(function () {{
    ids.push($(this).val());}}
);
if (ids.length > 0){{
    {Utils.SwalWarning("删除文章", "此操作将删除所选文章,确定吗?", "取 消", "删 除",
	            $"location.href='{GetRedirectUrl(_siteId, _contentId)}&delete={true}&idCollection=' + ids.join(',')")}
}} else {{
    {Utils.SwalError("请选择需要删除的文章!", string.Empty)}
}}
;return false;", string.Empty));

            BtnTaxis.Attributes.Add("onclick", Utils.ReplaceNewline($@"
var ids = [];
$(""input[name='idCollection']:checked"").each(function () {{
    ids.push($(this).val());}}
);
if (ids.length > 0){{
    location.href = '{GetRedirectUrl(_siteId, _contentId)}&taxis={true}&idCollection=' + ids.join(',')
}} else {{
    {Utils.SwalError("请选择需要排序的文章!", string.Empty)}
}}
;return false;", string.Empty));

            if (!string.IsNullOrEmpty(Request.QueryString["addArticle"]))
            {
                PhModalAdd.Visible = true;

                var articleId = Convert.ToInt32(Request.QueryString["articleId"]);

                var jsUrl = SiteServer.Plugin.Context.PluginApi.GetPluginUrl(Main.PluginId, "assets/script.js");

                LtlModalAddTitle.Text  = articleId > 0 ? "编辑表单内容" : "新增表单内容";
                LtlModalAddTitle.Text += $@"<script type=""text/javascript"" src=""{jsUrl}""></script>";
                if (articleId > 0)
                {
                    var articleInfo = ArticleDao.GetArticleInfo(articleId);
                    TbTitle.Text = articleInfo.Title;
                    Utils.SelectListItems(DdlIsFree, articleInfo.IsFree.ToString());
                    TbContent.Text = articleInfo.Content;
                }
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["taxis"]) &&
                     !string.IsNullOrEmpty(Request.QueryString["idCollection"]))
            {
                PhModalTaxis.Visible = true;
            }
        }
Exemplo n.º 3
0
        public ActionResult DeleteArticle( int id )
        {
            try
            {
                ArticleDao articleDao = new ArticleDao();
                Article article = articleDao.GetById( id );

                if( article.ImageName != null )
                    System.IO.File.Delete( Server.MapPath( "~/uploads/articleImage/" + article.ImageName ) );

                articleDao.Delete( article );

                TempData["message-success"] = "Článek" + article.Title + "byla smazan.";
            }
            catch( Exception exception )
            {

                throw;
            }

            return RedirectToAction( "Index" );
        }