Ejemplo n.º 1
0
    protected void btnXoa_Click(object sender, EventArgs e)
    {
        cls_News      cls;
        List <object> selectedKey = grvList.GetSelectedFieldValues(new string[] { "news_id" });

        if (selectedKey.Count > 0)
        {
            foreach (var item in selectedKey)
            {
                cls = new cls_News();
                tbNew  checkImage  = (from i in db.tbNews where i.news_id == Convert.ToInt32(item) select i).SingleOrDefault();
                string pathToFiles = Server.MapPath(checkImage.news_image);
                delete(pathToFiles);
                if (cls.Linq_Xoa(Convert.ToInt32(item)))
                {
                    alert.alert_Success(Page, "Xóa thành công", "");
                    loadData();
                }
                else
                {
                    alert.alert_Error(Page, "Xóa thất bại", "");
                }
            }
        }
        else
        {
            alert.alert_Warning(Page, "Bạn chưa chọn dữ liệu", "");
        }
    }
Ejemplo n.º 2
0
    public bool Linq_Them(string news_title, string news_summary, string image, string content, string SEO_KEYWORD, string SEO_TITLE, string SEO_LINK, string SEO_DEP, string SEO_IMAGE)
    {
        tbNew insert = new tbNew();

        insert.news_title    = news_title;
        insert.news_image    = image;
        insert.news_summary  = news_summary;
        insert.news_content  = content;
        insert.active        = true;
        insert.newcate_id    = 1;
        insert.news_datetime = DateTime.Now;
        if (SEO_KEYWORD != "")
        {
            insert.meta_keywords = SEO_KEYWORD;
        }
        else
        {
            insert.meta_keywords = news_title + " , " + cls_ToAscii.ToAscii(news_title.ToLower());
        }
        if (SEO_TITLE != "")
        {
            insert.meta_title = SEO_TITLE;
        }
        else
        {
            insert.meta_title = news_title + " | " + cls_ToAscii.ToAscii(news_title.ToLower());
        }
        if (SEO_DEP != "")
        {
            insert.meta_description = SEO_DEP;
        }
        else
        {
            insert.meta_description = news_title + " | " + cls_ToAscii.ToAscii(news_title.ToLower());
        }
        if (SEO_LINK != "")
        {
            insert.link_seo = SEO_LINK;
        }
        else
        {
            insert.link_seo = "tin-tuc/" + cls_ToAscii.ToAscii(news_title.ToLower()) + "-" + insert.news_id;
        }
        insert.seo_image = SEO_IMAGE;
        db.tbNews.InsertOnSubmit(insert);
        db.SubmitChanges();
        try
        {
            db.SubmitChanges();
            return(true);
        }
        catch
        {
            return(false);
        }
    }
Ejemplo n.º 3
0
    public bool Linq_Sua(int news_id, string title, string summary, string images, string content, string SEO_KEYWORD, string SEO_TITLE, string SEO_LINK, string SEO_DEP, string SEO_IMAGE)
    {
        tbNew update = db.tbNews.Where(x => x.news_id == news_id).FirstOrDefault();

        update.news_title = title;
        if (images != null)
        {
            update.news_image = images;
        }
        update.news_summary = summary;
        update.news_content = content;
        if (SEO_KEYWORD != "")
        {
            update.meta_keywords = SEO_KEYWORD;
        }
        else
        {
            update.meta_keywords = title + " , " + cls_ToAscii.ToAscii(title.ToLower());
        }
        if (SEO_TITLE != "")
        {
            update.meta_title = SEO_TITLE;
        }
        else
        {
            update.meta_title = title + " | " + cls_ToAscii.ToAscii(title.ToLower());
        }
        if (SEO_DEP != "")
        {
            update.meta_description = SEO_DEP;
        }
        else
        {
            update.meta_description = title + " | " + cls_ToAscii.ToAscii(title.ToLower());
        }
        if (SEO_LINK != "")
        {
            update.link_seo = SEO_LINK;
        }
        else
        {
            update.link_seo = "tin-tuc/" + cls_ToAscii.ToAscii(title.ToLower()) + "-" + update.news_id;
        }
        update.seo_image = SEO_IMAGE;
        try
        {
            db.SubmitChanges();
            return(true);
        }
        catch
        {
            return(false);
        }
    }
Ejemplo n.º 4
0
    public bool Linq_Xoa(int news_id)
    {
        tbNew delete = db.tbNews.Where(x => x.news_id == news_id).FirstOrDefault();

        db.tbNews.DeleteOnSubmit(delete);
        try
        {
            db.SubmitChanges();
            return(true);
        }
        catch
        {
            return(false);
        }
    }