protected void ButtonDetailSimpan_Click(object sender, EventArgs e) { using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext()) { PenggunaLogin PenggunaLogin = (PenggunaLogin)Session["PenggunaLogin"]; Post_Class Post_Class = new Post_Class(db); TBPost Post = Post_Class.GetData(Request.QueryString["id"].ToInt()); PostDetail_Class PostDetail_Class = new PostDetail_Class(db); if (string.IsNullOrEmpty(HiddenFieldIDPostDetail.Value)) { PostDetail_Class.InsertData(Post.IDPost, PenggunaLogin.IDPengguna, Post.TBPostDetails.Count + 1, DateTime.Now, TextBoxDetailNama.Text, DropDownListDetailJenis.SelectedValue.ToInt(), (DropDownListDetailJenis.SelectedValue.ToInt() == (int)EnumJenisPostDetail.Text ? TextBoxDetailKonten.Text : null)); } else { TBPostDetail PostDetail = PostDetail_Class.GetData(HiddenFieldIDPostDetail.Value.ToInt()); PostDetail.Nama = TextBoxDetailNama.Text; if (DropDownListDetailJenis.SelectedValue.ToInt() == (int)EnumJenisPostDetail.Text) { PostDetail.Konten = HttpUtility.HtmlDecode(TextBoxDetailKonten.Text); } } db.SubmitChanges(); MultiViewPage.SetActiveView(ViewPost); LoadPost(); } }
public ReturnData AJAX_Updates(int idPost, string postTitle, string postShortContent, string postContent) { try { DataClassesDataContext db = new DataClassesDataContext(); TBPost post = db.TBPosts.Where(x => !x.Deflag && x.IDPost == idPost).FirstOrDefault(); if (post == null) { return(ReturnData.MessageFailed("Post not found", null)); } post.Post_Title = postTitle; post.Post_ShortContent = postShortContent; post.Post_Content = postContent; post.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 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); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext()) { MultiViewPage.SetActiveView(ViewPost); //PageTemplate_Class PageTemplate_Class = new PageTemplate_Class(db); //PageTemplate_Class.DropDownList(DropDownListTemplate, "-Pilih Template-"); if (string.IsNullOrEmpty(Request.QueryString["id"])) { LabelKeterangan.Text = "Tambah"; } else { TBPost Post = db.TBPosts.FirstOrDefault(item => item.IDPost == Request.QueryString["id"].ToInt()); TextBoxJudul.Text = Post.Judul; DropDownListAlign.SelectedValue = Post.Align.ToString(); TextBoxDeskripsi.Text = Post.Deskripsi; DivDetail.Visible = true; LoadPost(); LabelKeterangan.Text = "Ubah"; } } } Page.Form.Attributes.Add("enctype", "multipart/form-data"); }
protected void ButtonUploadSingleImage_Click(object sender, EventArgs e) { if (FileUploadSingleImage.HasFile) { using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext()) { PenggunaLogin PenggunaLogin = (PenggunaLogin)Session["PenggunaLogin"]; string Folder = Server.MapPath("/images/PostDetail/"); if (!Directory.Exists(Folder)) { Directory.CreateDirectory(Folder); } Post_Class Post_Class = new Post_Class(db); TBPost Post = Post_Class.GetData(Request.QueryString["id"].ToInt()); PostDetail_Class PostDetail_Class = new PostDetail_Class(db); TBPostDetail PostDetail = null; if (string.IsNullOrEmpty(HiddenFieldIDPostDetail.Value)) { PostDetail = PostDetail_Class.InsertData(Post.IDPost, PenggunaLogin.IDPengguna, Post.TBPostDetails.Count + 1, DateTime.Now, TextBoxDetailNama.Text, DropDownListDetailJenis.SelectedValue.ToInt(), (DropDownListDetailJenis.SelectedValue.ToInt() == (int)EnumJenisPostDetail.Text ? TextBoxDetailKonten.Text : null)); db.SubmitChanges(); } else { PostDetail = PostDetail_Class.GetData(HiddenFieldIDPostDetail.Value.ToInt()); } PostDetailImage_Class PostDetailImage_Class = new PostDetailImage_Class(db); TBPostDetailImage PostDetailImage = PostDetail.TBPostDetailImages.FirstOrDefault(); if (PostDetailImage == null) { PostDetailImage = PostDetailImage_Class.InsertData(PostDetail.IDPostDetail, 0, string.Empty, null, null, null, null); db.SubmitChanges(); } FileUploadSingleImage.SaveAs(Folder + (PostDetailImage.IDPostDetail + "-" + PostDetailImage.IDPostDetailImage) + ".jpg"); PostDetailImage.DefaultURL = "/images/PostDetail/" + (PostDetailImage.IDPostDetail + "-" + PostDetailImage.IDPostDetailImage) + ".jpg"; db.SubmitChanges(); HiddenFieldIDPostDetail.Value = PostDetail.IDPostDetail.ToString(); DropDownListDetailJenis.Enabled = false; } LoadDataFoto(); } }
public TBPost InsertData(int IDPage, int IDPengguna, int Urutan, DateTime Tanggal, string Judul, string Deskripsi, string Align, string Tags) { TBPost Data = new TBPost() { IDPage = IDPage, IDPengguna = IDPengguna, Urutan = Urutan, Tanggal = Tanggal, Judul = Judul, Deskripsi = Deskripsi, Align = Align, Tags = Tags }; db.TBPosts.InsertOnSubmit(Data); return(Data); }
public ReturnData AJAX_Insert(string postTitle, string postShortContent, string postContent, int idPage, bool active) { try { using (DataClassesDataContext db = new DataClassesDataContext()) { if (!ValidationName_Insert(db, postTitle)) { return(ReturnData.MessageFailed(postTitle + " already exists.", null)); } TBPost _newData = new TBPost { Post_Title = postTitle, IDPage = idPage, Post_ShortContent = postShortContent, Post_Content = postContent, Active = active, Deflag = false, DateInsert = DateTime.Now, DateLastUpdate = DateTime.Now }; db.TBPosts.InsertOnSubmit(_newData); db.SubmitChanges(); if (_newData != null) { return(ReturnData.MessageSuccess(postTitle + " has been successfully inserted.", _newData.IDPost)); } else { return(ReturnData.MessageFailed(postTitle + " 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)); } }
private string GetAllPostDetail(TBPost Post) { string hasil = string.Empty; bool awal = true; foreach (var item in Post.TBPostDetails) { if (awal) { hasil += item.Nama; awal = false; } else { hasil += ", " + item.Nama; } } return(hasil); }
public ReturnData AJAX_Delete(int idPost) { try { DataClassesDataContext db = new DataClassesDataContext(); TBPost post = db.TBPosts.Where(x => x.IDPost == idPost).FirstOrDefault(); if (post == null) { return(ReturnData.MessageFailed("Post not found", null)); } post.Deflag = true; post.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(TBPost Data) { db.TBPosts.DeleteOnSubmit(Data); }
public void InsertData(TBPost Data) { db.TBPosts.InsertOnSubmit(Data); }
protected void ButtonUploadMultipleImage_Click(object sender, EventArgs e) { using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext()) { PenggunaLogin PenggunaLogin = (PenggunaLogin)Session["PenggunaLogin"]; string Folder = Server.MapPath("/images/PostDetail/"); if (!Directory.Exists(Folder)) { Directory.CreateDirectory(Folder); } Post_Class Post_Class = new Post_Class(db); TBPost Post = Post_Class.GetData(Request.QueryString["id"].ToInt()); PostDetail_Class PostDetail_Class = new PostDetail_Class(db); TBPostDetail PostDetail = null; if (string.IsNullOrEmpty(HiddenFieldIDPostDetail.Value)) { PostDetail = PostDetail_Class.InsertData(Post.IDPost, PenggunaLogin.IDPengguna, Post.TBPostDetails.Count + 1, DateTime.Now, TextBoxDetailNama.Text, DropDownListDetailJenis.SelectedValue.ToInt(), (DropDownListDetailJenis.SelectedValue.ToInt() == (int)EnumJenisPostDetail.Text ? TextBoxDetailKonten.Text : null)); db.SubmitChanges(); } else { PostDetail = PostDetail_Class.GetData(HiddenFieldIDPostDetail.Value.ToInt()); } PostDetailImage_Class PostDetailImage_Class = new PostDetailImage_Class(db); TBPostDetailImage PostDetailImage = null; if (ButtonUploadMultipleImage.Text == "Tambah") { PostDetailImage = PostDetailImage_Class.InsertData(PostDetail.IDPostDetail, PostDetail.TBPostDetailImages.Count + 1, string.Empty, TextBoxImageJudul.Text, HttpUtility.HtmlDecode(TextBoxImageDeskripsi.Text), TextBoxImageLink.Text, TextBoxImageAlt.Text); } else { PostDetailImage = PostDetailImage_Class.GetData(HiddenFieldPostDetailImage.Value.ToInt()); PostDetailImage.Judul = TextBoxImageJudul.Text; PostDetailImage.Deskripsi = HttpUtility.HtmlDecode(TextBoxImageDeskripsi.Text); PostDetailImage.Link = TextBoxImageLink.Text; PostDetailImage.Alt = TextBoxImageAlt.Text; } db.SubmitChanges(); if (FileUploadMultipleImage.HasFile) { FileUploadMultipleImage.SaveAs(Folder + (PostDetailImage.IDPostDetail + "-" + PostDetailImage.IDPostDetailImage) + ".jpg"); } PostDetailImage.DefaultURL = "/images/PostDetail/" + (PostDetailImage.IDPostDetail + "-" + PostDetailImage.IDPostDetailImage) + ".jpg"; db.SubmitChanges(); HiddenFieldIDPostDetail.Value = PostDetail.IDPostDetail.ToString(); HiddenFieldPostDetailImage.Value = string.Empty; DropDownListDetailJenis.Enabled = false; TextBoxImageJudul.Text = string.Empty; TextBoxImageLink.Text = string.Empty; TextBoxImageAlt.Text = string.Empty; TextBoxImageDeskripsi.Text = string.Empty; ButtonUploadMultipleImage.Text = "Tambah"; } LoadDataFoto(); }