示例#1
0
        public void SaveCommentLevel1(ref CommentLevel1Entity commentLevel1, int IDProduct)
        {
            List <CommentOfAPost> listCommentOfAllProduct = FindAllComments();


            // nếu file rỗng thì tạo comment cho bài viết luôn
            if (listCommentOfAllProduct == null)
            {
                listCommentOfAllProduct = new List <CommentOfAPost>();
                CommentOfAPost commentOfAPost = new CommentOfAPost();
                commentOfAPost.IDProduct = IDProduct;

                // tạo id cho comment đầu tiên của bài viết
                commentLevel1.IDCommentMain = 1;
                commentOfAPost.ListComment  = new List <CommentLevel1Entity>();
                commentOfAPost.ListComment.Add(commentLevel1);
                listCommentOfAllProduct.Add(commentOfAPost);
                file.WriteFileJson(Constant.DATA_COMMENT, JsonConvert.SerializeObject(listCommentOfAllProduct));
                return;
            }
            else
            {
                // file json đã có giá trị, đi kiểm tra xem post đã có cmt chưa
                foreach (CommentOfAPost commentOfAPost in listCommentOfAllProduct)
                {
                    // nếu mà có rồi thì thêm vào thôi
                    if (commentOfAPost.IDProduct == IDProduct)
                    {
                        commentLevel1.IDCommentMain = commentOfAPost.ListComment[commentOfAPost.ListComment.Count - 1].IDCommentMain + 1;
                        commentOfAPost.ListComment.Add(commentLevel1);
                        listCommentOfAllProduct.Add(commentOfAPost);
                        file.WriteFileJson(Constant.DATA_COMMENT, JsonConvert.SerializeObject(listCommentOfAllProduct));
                        return;
                    }
                }

                // nếu mà post chưa có bình luận
                commentLevel1.IDCommentMain = 1;
                CommentOfAPost comment = new CommentOfAPost();
                comment.IDProduct   = IDProduct;
                comment.ListComment = new List <CommentLevel1Entity>();
                comment.ListComment.Add(commentLevel1);
                listCommentOfAllProduct.Add(comment);
                file.WriteFileJson(Constant.DATA_COMMENT, JsonConvert.SerializeObject(listCommentOfAllProduct));
                return;
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Request.Url.AbsolutePath;

            // đọc slug từ router
            string        slug    = (string)RouteData.Values["slug"];
            ProductEntity product = productRepository.FindProductBySlug(slug);

            // nếu tìm thấy sp thì sẽ hiển thị thông tin sản phẩm
            // nếu không tìm thấy thì sẽ cho về trang home
            if (product != null)
            {
                if (url.Contains("may-tinh"))
                {
                    url_page.Attributes.Add("href", "/may-tinh");
                    name_page.InnerText = "Máy tính";
                    slug_.Attributes.Add("href", "/may-tinh/" + product.Slug);
                }
                else
                {
                    url_page.Attributes.Add("href", "/phu-kien");
                    name_page.InnerText = "Phụ kiện";
                    slug_.Attributes.Add("href", "/phu-kien/" + product.Slug);
                }

                name_product.InnerText = product.Name;

                bigImg.Attributes.Add("src", product.ListImage[0]);

                __title.InnerText = product.Name;
                // load list image
                string html_img = @"<div class='chuyen' onclick='backImg()' style='display: none;'>
                                          <img src='/static/img/icon/click-left.png' >
                                    </div>";

                int i = 0;
                foreach (string img in product.ListImage)
                {
                    i++; // tạo biến đếm để hiển thì 3 ảnh trong list ảnh, tạm thời để none, sau đấy dùng js để thao tác
                    html_img += @"<img src='" + img + @"' class='small-img " + (i > 3 ? "none" : "") + @"' onclick='showImage(this)' num='" + i + @"'>";
                }
                html_img += @"<div class='chuyen' onclick='nextImg()'>
                                    <img src='/static/img/icon/click-right.png' >
                              </div>";


                list_anh.InnerHtml = html_img;

                name_pro.InnerText = product.Name;
                // url sản phẩm sẽ có dạng: /category-name/slug
                name_pro.Attributes.Add("href", "/" + product.Category + "/" + product.Slug);

                price_new.InnerText = String.Format("{0:0,0}", product.Price * (100 - product.Sale) / 100) + @"₫";
                price_old.InnerText = String.Format("{0:0,0}", product.Price) + @"₫";

                if (product.Quantity <= 0)
                {
                    _status.InnerText = "Hết hàng";
                    _status.Attributes.Add("style", "background: red !important");
                }

                // xử lí lại chỗ miêu tả cấu hình
                product.Info          = product.Info.Replace("\n", "<br>");
                product.Info          = product.Info.Replace("\t", ": ");
                info_detail.InnerHtml = product.Info;

                string html = @"<button id=" + "'btn-add-to-cart' onclick='addToCart(" + product.ID + @")'>Thêm vào giỏ hàng</button>";
                btn_server.InnerHtml = html;

                // load bài viết chi tiết
                PostEntity post = postRepository.FindPostByIDProduct(product.ID);
                if (post == null)
                {
                    post_details.InnerText = "Chưa có bài đánh giá sản phẩm này";
                }
                else
                {                 // gán link ảnh vào trong các thẻ img,  "src='filename'" -> "src='link-image'"
                    for (i = 0; i < post.ListImage.Count; i++)
                    {
                        post.Content = post.Content.Replace("src='filename" + i + "'", "src='" + post.ListImage[i] + "'");
                    }
                    post_details.InnerHtml = post.Content;
                }


                // đọc list comment ra
                CommentOfAPost commentInPost = commentRepository.FindListCommentsOfProduct(product.ID);
                string         htmlComment   = CommentUtils.HTMLComments(commentInPost);
                //List<CommentLevel2Entity> comments = commentRepository.FindCommentsByIDProduct(product.ID);
                //string htmlComment = CommentUtils.HTMLComments(comments);
                list_comment.InnerHtml = htmlComment;


                // add btn send cmt
                //onclick = "sendCommentLevel1(1)"
                btn_send_lv1.Attributes.Add("onclick", "sendCommentLevel1(" + product.ID + ")");
                btn_send_lv1.Attributes.Add("idxx", product.ID.ToString());
            }
            else
            {
                Response.Redirect("/");
            }
        }
示例#3
0
        public static string HTMLComments(CommentOfAPost comments)
        {
            if (comments == null)
            {
                return("");
            }
            UserRepository userRepository = new UserRepository();
            string         HTML           = "";

            foreach (CommentLevel1Entity comment in comments.ListComment)
            {
                UserEntity userLv1 = userRepository.FindUserByID(comment.CommentMain.IDUser);


                // xử lý avt, trong avt chứa tên viết tắt, lấy các chữ cái đầu của fullname
                userLv1.Fullname = userLv1.Fullname.Trim();
                string[] words   = userLv1.Fullname.Split(' ');
                string   acronym = "";
                foreach (string word in words)
                {
                    acronym += word[0];
                }

                string html = @"<div class='detail_comment flex'  id='" + comment.IDCommentMain + @"'>

                                    <!-- avatar -->
                                    <div class='avatar_comment'>"
                              + acronym +
                              @"</div>

                                    <!-- User -->
                                    <div class='user_comment'>
                                        <div class='flex'>
                                            <h4>" + userLv1.Fullname + @"</h4>";
                if (userLv1.Role == Constant.ROLE_ADMIN)
                {
                    html += @"<span class='role'>Quản trị viên</span>";
                }
                html += @"<span class='time'>" + GetDay(comment.CommentMain.TimeComment) + @"</span>
                                        </div>

                                        <!-- comment cua user -->
                                        <span class='content_comment'>"
                        + comment.CommentMain.Content +
                        @"</span>

                                        <!-- btn them comment lv2 -->
                                        <a id='xxx' class='btn_reply' onclick='addCommentLevel2(this)'>Trả lời</a>";

                // tạo 1 biến tránh null
                int num = comment.ListReply == null ? -1 : comment.ListReply.Count;

                for (int i = 0; i < num; i++)
                {
                    UserEntity userLv2 = userRepository.FindUserByID(comment.ListReply[i].IDUser);
                    if (userLv2 == null)
                    {
                        continue;
                    }
                    string htmlReply = @"<!-- reply will append to here -->
                                                                                    <div class='reply'>
                                                                                        <div class='user_comment'>
                                                                                            <div class='flex'>
                                                                                                <h4>" + userLv2.Fullname + @"</h4>";

                    if (userLv2.Role == Constant.ROLE_ADMIN)
                    {
                        htmlReply += @"<span class='role'>Quản trị viên</span>";
                    }
                    htmlReply += @"<span class='time'>" + GetDay(comment.ListReply[i].TimeComment) + @"</span>
                                                                    </div>
                                                                    <span class='content_comment'>"
                                 + comment.ListReply[i].Content +
                                 @"</span>
                                                                </div>
                                                            </div>";
                    html += htmlReply;
                }

                html += @"</div>
                                                    </div>";
                HTML += html;
            }


            return(HTML);
        }