public static void addPost(DTO.Post post) { using (ReloadEntities db = new ReloadEntities()) { db.TBL_POSTS.Add(new TBL_POSTS { POST_TITULO = post.titulo, POST_CATEGORIA = post.categoria.id, POST_CANT_COMENTARIOS = 0, POST_CONTENIDO_EDIT = post.contenido, POST_COTENIDO = post.contenido, POST_DEBAJA = false, POST_FAVORITOS = 0, POST_FECALT = DateTime.Now, POST_FECMOD = DateTime.Now, POST_PROPIETARIO = post.propietario.id, POST_IMAGEN = post.imagen, POST_PUNTOS = 0, POST_SEGUIDORES = 0, POST_SE_COMENTA = post.seComenta, POST_STICKY = post.sticky, POST_TAGS = post.etiquetas, POST_VISITAS = 0 }); db.SaveChanges(); } }
protected void btnAddRelatedPost_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(DropDownList1.SelectedValue)) { Guid postID = Guid.Parse(Request.QueryString.Get("postid")); Guid relatedPostID = Guid.Parse(DropDownList1.SelectedValue); DTO.Post post = Post_BUS.GetEntityByID <DTO.Post>(postID); List <string> lstPost = (List <string>)Session["RelatedPosts"]; bool isAdd = true; if (post.RelatedPosts != null) { if (lstPost.Contains(relatedPostID.ToString().ToLower()) || post.PostID.Equals(relatedPostID)) { isAdd = false; } } if (!isAdd) { Response.Write("<script>" + "sessionStorage['ReloadImg'] = true;" + "alert('Bài viết liên quan muốn thêm đã có trong danh sách bài viết liên quan hoặc trùng với bài viết hiện tại'); </script>"); } else { lstPost.Add(relatedPostID.ToString()); string str = string.Join(";", lstPost.ToArray()); SetSessionForRelatedPost(str); BindRelatedPosts(GetRelatedPosts(str)); BindDropDownList(new Post_BUS().GetAllPost(post.PostID, str)); Response.Write("<script>sessionStorage['ReloadImg'] = 'true';</script>"); } } }
private void BindData() { Post_BUS pb = new Post_BUS(); Guid postID = Guid.Parse(Request.QueryString.Get("postid")); DTO.Post post = pb.GetPostByID(postID); lblPostName.Text = post.PostName; lblPostSummary.Text = HttpUtility.UrlDecode(post.Summary); ImgPost.ImageUrl = "../../../Admin/Img/images/" + (string.IsNullOrEmpty(post.Image) ? "noimg.png" : HttpUtility.UrlDecode(post.Image)); lblPostContent.Text = HttpUtility.UrlDecode(post.Content); List <DTO.Post> relatedPost = pb.GetRelatedPosts(post.RelatedPosts); if (relatedPost != null && relatedPost.Count != 0) { var source = relatedPost.Select((item) => { return(new { ImageRelatedPost = "../../../Admin/Img/images/" + (string.IsNullOrEmpty(item.Image) ? "noimg.png" : HttpUtility.UrlDecode(item.Image)), LinkDetail = "ChiTietBaiViet.aspx?postid=" + item.PostID, RelatedPostName = item.PostName }); }); dataListRelatedPost.DataSource = source; dataListRelatedPost.DataBind(); } }
private string GetPostInfo(DTO.Post post) { string msg = ""; msg += string.Format("<b><a class='PostName' href=\"PostDetail.aspx?postid={1}\">{0}</a></b><br/>", post.PostName.ToUpper(), post.PostID); msg += string.Format("<b>Ngày tạo: </b><i>{0}</i><br/>", post.CreatedDate.ToString("HH:mm:ss dd/MM/yyyy")); msg += "<i>" + new Post_BUS().GetRateString(post.PostID) + "</i><br/>"; msg += string.Format("<b>Tóm tắt:</b><br/>{0}", HttpUtility.UrlDecode(post.Summary)); return(msg); }
protected void btnDeleteRelatedPost_Click(object sender, EventArgs e) { // xóa bài viết liên quan List <string> lstPost = (List <string>)Session["RelatedPosts"]; Guid relatedPostID = Guid.Parse(sender.GetType().GetProperty("CommandArgument").GetValue(sender).ToString()); Guid postID = Guid.Parse(Request.QueryString.Get("postid")); DTO.Post post = Post_BUS.GetEntityByID <DTO.Post>(postID); lstPost.Remove(relatedPostID.ToString()); string str = string.Join(";", lstPost.ToArray()); SetSessionForRelatedPost(str); BindRelatedPosts(GetRelatedPosts(str)); BindDropDownList(new Post_BUS().GetAllPost(post.PostID, str)); }
private void BindData() { Guid postID = Guid.Parse(Request.QueryString.Get("postid")); DTO.Post post = Post_BUS.GetEntityByID <DTO.Post>(postID); txtTenBaiViet.Text = post.PostName.Trim(); txtNgayTao.Text = post.CreatedDate.ToString("HH:mm:ss dd/MM/yyyy"); imgProduct.ImageUrl = "../../Img/images/" + (string.IsNullOrEmpty(HttpUtility.UrlDecode(post.Image)) ? "noimg.png" : HttpUtility.UrlDecode(post.Image)); txtImgURL.Text = (string.IsNullOrEmpty(HttpUtility.UrlDecode(post.Image)) ? "" : "/Admin/Img/images/" + HttpUtility.UrlDecode(post.Image)); txtSummary.Text = string.IsNullOrEmpty(post.Summary) ? "" : HttpUtility.UrlDecode(post.Summary.Trim()); txtDetail.Text = string.IsNullOrEmpty(post.Content) ? "" : HttpUtility.UrlDecode(post.Content.Trim()); BindRelatedPosts(GetRelatedPosts(post.RelatedPosts)); lblEmpty.Text = GetRelatedPosts(post.RelatedPosts).Count == 0 ? "Không có bài viết liên quan" : ""; BindDropDownList(new Post_BUS().GetAllPost(post.PostID, post.RelatedPosts)); SetSessionForRelatedPost(post.RelatedPosts); Response.Write(string.Format("<script>sessionStorage['ImageURL'] = '{0}' </script>", string.IsNullOrEmpty(HttpUtility.UrlDecode(post.Image)) ? "noimg.png" : HttpUtility.UrlDecode(post.Image))); }
protected void btnSave_Click(object sender, EventArgs e) { try { Post_BUS bus = new Post_BUS(); DTO.Post newPost = new DTO.Post(); newPost.PostID = Guid.NewGuid(); string postName = txtTenBaiViet.Text.Trim(), imgURL = Request.Form.Get("ctl00$ContentPlaceHolder$txtImgURL"), summary = txtSummary.Text.Trim(), content = txtDetail.Text.Trim(); if (string.IsNullOrEmpty(postName)) { txtTenBaiViet.Focus(); throw new Exception("Tên bài viết không được để trống"); } if (bus.IsDuplicatePostName(Guid.Empty, postName)) { txtTenBaiViet.Focus(); throw new Exception("Tên bài viết bị trùng"); } if (string.IsNullOrEmpty(imgURL)) { throw new Exception("Bài viết chưa có ảnh"); } newPost.PostName = postName; newPost.Image = imgURL.Substring(imgURL.LastIndexOf('/') + 1, imgURL.Length - imgURL.LastIndexOf('/') - 1); newPost.Content = content; newPost.Summary = summary; newPost.RelatedPosts = string.Join(";", ((List <string>)Session["RelatedPosts"])); bus.InsertPost(newPost); Response.Write("<script>alert('Thêm thành công')</script>"); } catch (Exception ex) { Response.Write("<script>alert(\"" + ex.Message + "\")</script>"); } }