public ReturnData AJAX_BE_Updates(int idPage, string pageTitle, string pageShortContent, string PageContent) { try { DataClassesDataContext db = new DataClassesDataContext(); TBPage page = db.TBPages.Where(x => !x.Deflag && x.IDPage == idPage).FirstOrDefault(); if (page == null) { return(ReturnData.MessageFailed("Page not found", null)); } page.Page_Title = pageTitle; page.Page_ShortContent = pageShortContent; page.Page_Content = PageContent; page.DateLastUpdate = DateTime.Now; db.SubmitChanges(); return(ReturnData.MessageSuccess("Data updated successfully", null)); } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }
protected void ButtonPageSimpan_Click(object sender, EventArgs e) { if (Page.IsValid) { using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext()) { if (ButtonPageSimpan.Text == "Tambah") { db.TBPages.InsertOnSubmit(new TBPage { IDPageTemplate = DropDownListPageTemplate.SelectedValue.ToInt(), Nama = TextBoxPageNama.Text, Deskripsi = null }); } else if (ButtonPageSimpan.Text == "Ubah") { TBPage data = db.TBPages.FirstOrDefault(item => item.IDPage == HiddenFieldIDPage.Value.ToInt()); data.IDPageTemplate = DropDownListPageTemplate.SelectedValue.ToInt(); data.Nama = TextBoxPageNama.Text; data.Deskripsi = null; } db.SubmitChanges(); HiddenFieldIDPage.Value = null; DropDownListPageTemplate.SelectedIndex = 0; TextBoxPageNama.Text = string.Empty; ButtonPageSimpan.Text = "Tambah"; LoadData(db); } } }
protected void ButtonSimpan_Click(object sender, EventArgs e) { using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext()) { PenggunaLogin PenggunaLogin = (PenggunaLogin)Session["PenggunaLogin"]; Page_Class Page_Class = new Page_Class(db); TBPage Halaman = Page_Class.GetData(Request.QueryString["idPage"].ToInt()); Post_Class Post_Class = new Post_Class(db); TBPost Post = Post_Class.GetData(Request.QueryString["id"].ToInt()); if (Post == null) { Post = Post_Class.InsertData(Request.QueryString["idPage"].ToInt(), PenggunaLogin.IDPengguna, Halaman.TBPosts.Count + 1, DateTime.Now, TextBoxJudul.Text, TextBoxDeskripsi.Text, DropDownListAlign.SelectedValue, TextBoxTags.Text); } else { Post.IDPengguna = PenggunaLogin.IDPengguna; Post.Urutan = Post.Urutan; Post.Tanggal = DateTime.Now; Post.Judul = TextBoxJudul.Text; Post.Deskripsi = TextBoxDeskripsi.Text; Post.Align = DropDownListAlign.SelectedValue; Post.Tags = TextBoxTags.Text; } db.SubmitChanges(); Response.Redirect("Pengaturan.aspx?idPage=" + Request.QueryString["idPage"] + "&id=" + Post.IDPost); } }
public TBPage InsertData(int IDPageTemplate, string Nama, string Deskripsi) { TBPage Data = new TBPage() { IDPageTemplate = IDPageTemplate, Nama = Nama, Deskripsi = Deskripsi }; db.TBPages.InsertOnSubmit(Data); return(Data); }
public ReturnData AJAX_Insert(string pageTitle, string pageShortContent, string pageContent, bool active) { try { using (DataClassesDataContext db = new DataClassesDataContext()) { if (!ValidationName_Insert(db, pageTitle)) { return(ReturnData.MessageFailed(pageTitle + " already exists.", null)); } TBPage _newData = new TBPage { Page_Title = pageTitle, Page_ShortContent = pageShortContent, Page_Content = pageContent, Active = active, Deflag = false, DateInsert = DateTime.Now, DateLastUpdate = DateTime.Now }; db.TBPages.InsertOnSubmit(_newData); db.SubmitChanges(); if (_newData != null) { return(ReturnData.MessageSuccess(pageTitle + " has been successfully inserted.", _newData.IDPage)); } else { return(ReturnData.MessageFailed(pageTitle + " failed to insert.", null)); } } } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }
protected void RepeaterPage_ItemCommand(object source, RepeaterCommandEventArgs e) { using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext()) { if (e.CommandName == "Ubah") { TBPage Page = db.TBPages.FirstOrDefault(item => item.IDPage == e.CommandArgument.ToInt()); HiddenFieldIDPage.Value = Page.IDPage.ToString(); DropDownListPageTemplate.SelectedValue = Page.IDPageTemplate.ToString(); TextBoxPageNama.Text = Page.Nama; TextBoxPageNama.Focus(); ButtonPageSimpan.Text = "Ubah"; } else if (e.CommandName == "Hapus") { Page_Class Page_Class = new Page_Class(db); Page_Class.DeleteData(e.CommandArgument.ToInt()); db.SubmitChanges(); LoadData(db); } } }
public ReturnData AJAX_BE_Delete(int idPage) { try { DataClassesDataContext db = new DataClassesDataContext(); TBPage page = db.TBPages.Where(x => x.IDPage == idPage).FirstOrDefault(); if (page == null) { return(ReturnData.MessageFailed("Page not found", null)); } page.Deflag = true; page.DateLastUpdate = DateTime.Now; db.SubmitChanges(); return(ReturnData.MessageSuccess("Data deleted successfully", null)); } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }
public void DeleteData(TBPage Data) { db.TBPages.DeleteOnSubmit(Data); }
public void InsertData(TBPage Data) { db.TBPages.InsertOnSubmit(Data); }