示例#1
0
        protected void btnSubmit_Click(Object sender, EventArgs e)
        {
            Comment comment = new Comment();
            comment.NewsID = hdfNewsID.Value;
            comment.CommentID = Guid.NewGuid();
            comment.CommentItem = txtComment.Text;
            comment.Name = txtName.Text;
            comment.CommentAdded = DateTime.Now;
            comment.UserName = txtName.Text;
            comment.Email = txtEmail.Text;
            comment.Publish = true;

            GetNewsFromAmazon.SaveComments(Settings.Default.DomainNameComment,comment);
        }
 public ActionResult Comment(string NewsID, string CommentItem)
 {
     Comment comment = new Comment();
     comment.CommentID = Guid.NewGuid();
     comment.NewsID = NewsID;
     comment.CommentItem = CommentItem;
     comment.UserName = HttpContext.User.Identity.Name;
     comment.CommentAdded = DateTime.Now;
     if (news.Comment.Count > 0)
         news.Comment.Clear();
     news.Comment.Add(comment);
     GetNewsFromAmazon.SaveComments(Settings.Default.DomainNameComment, comment);
     return View(news);
 }
        public static List<Comment> GetComments(string domainName)
        {
            List<Comment> comments = new List<Comment>();
            Comment comment;

            String selectExpression = "Select * From " + domainName;
            SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression);
            SelectResponse selectResponse = sdbClient.Select(selectRequestAction);
            if (selectResponse.IsSetSelectResult())
            {
                SelectResult selectResult = selectResponse.SelectResult;
                foreach (Item item in selectResult.Item)
                {
                    comment = new Comment();
                    if (item.IsSetName())
                    {

                    }
                    int i = 0;
                    foreach (Amazon.SimpleDB.Model.Attribute attribute in item.Attribute)
                    {

                        if (attribute.IsSetName())
                        {
                            string name = attribute.Name;
                        }
                        if (attribute.IsSetValue())
                        {
                            switch (attribute.Name)
                            {
                                case "NewsID":
                                    comment.NewsID = attribute.Value;
                                    break;

                                case "UserName":
                                    comment.UserName = attribute.Value;
                                    break;
                                case "CommentID":
                                    comment.CommentID = Guid.Parse(attribute.Value);
                                    break;
                                case "CommentAdded":
                                    comment.CommentAdded = Convert.ToDateTime(attribute.Value);
                                    break;
                                case "Likes":
                                    comment.Likes = Convert.ToInt32(attribute.Value);
                                    break;
                                case "CommentItem":
                                    comment.CommentItem = attribute.Value.Contains("/") ? GetTheHtml(attribute.Value) : "";
                                    break;
                                case "CommentReplyID":
                                    comment.CommentReplyID = attribute.Value;
                                    break;

                            }
                            i++;
                        }
                    }
                    comments.Add(comment);
                }
            }
            return comments;
        }
        public static void SaveLikes(string domainName, Comment comment)
        {
            PutAttributesRequest putAttrRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(Convert.ToString(comment.CommentID));
            putAttrRequest.WithAttribute(new ReplaceableAttribute
            {
                Name = "Likes",
                Value = Convert.ToString(comment.Likes),
                Replace = true
            }

               );
            sdbClient.PutAttributes(putAttrRequest);
        }
        public static void SaveComments(string domainName, Comment comment)
        {
            PutAttributesRequest putAttrRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(Convert.ToString(comment.CommentID));
            putAttrRequest.WithAttribute(new ReplaceableAttribute
            {
                Name = "NewsID",
                Value = Convert.ToString(comment.NewsID),
                Replace = false
            },

            new ReplaceableAttribute
            {
                Name = "UserName",
                Value = comment.UserName,
                Replace = false
            },
            new ReplaceableAttribute
            {
                Name = "CommentID",
                Value = Convert.ToString(comment.CommentID),
                Replace = false
            },
             new ReplaceableAttribute
             {
                 Name = "CommentAdded",
                 Value = Convert.ToString(comment.CommentAdded),
                 Replace = false
             }
             ,
             new ReplaceableAttribute
             {
                 Name = "CommentItem",
                 Value = SaveHtml(comment.CommentItem),
                 Replace = false
             }
              ,
             new ReplaceableAttribute
             {
                 Name = "CommentReplyID",
                 Value = comment.CommentReplyID,
                 Replace = false
             }
              ,
             new ReplaceableAttribute
             {
                 Name = "Likes",
                 Value = Convert.ToString(comment.Likes),
                 Replace = true
             }
               );
            sdbClient.PutAttributes(putAttrRequest);
        }
        public static List<Comment> GetComments(string domainName)
        {
            List<Comment> comments = new List<Comment>();
            Comment comment;

            String selectExpression = "Select * From " + domainName + " LIMIT 1000";
            SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression);
            SelectResponse selectResponse = sdbClient.Select(selectRequestAction);
            if (selectResponse.IsSetSelectResult())
            {
                SelectResult selectResult = selectResponse.SelectResult;
                foreach (Item item in selectResult.Item)
                {
                    comment = new Comment();
                    if (item.IsSetName())
                    {

                    }
                    int i = 0;
                    foreach (Amazon.SimpleDB.Model.Attribute attribute in item.Attribute)
                    {

                        if (attribute.IsSetName())
                        {
                            string name = attribute.Name;
                        }
                        if (attribute.IsSetValue())
                        {
                            switch (attribute.Name)
                            {
                                case "NewsID":
                                    comment.NewsID = attribute.Value;
                                    break;

                                case "UserName":
                                    comment.UserName = attribute.Value;
                                    break;
                                case "CommentID":
                                    comment.CommentID = Guid.Parse(attribute.Value);
                                    break;
                                case "CommentAdded":
                                    comment.CommentAdded = Convert.ToDateTime(attribute.Value);
                                    break;
                                case "Likes":
                                    comment.Likes = Convert.ToInt32(attribute.Value);
                                    break;
                                case "CommentItem":
                                    comment.CommentItem = GetTheHtml(attribute.Value);
                                    break;
                                case "CommentReplyID":
                                    comment.CommentReplyID = attribute.Value;
                                    break;
                                case "Publish":
                                    comment.Publish = Convert.ToBoolean(attribute.Value);
                                    break;
                                case "Email":
                                    comment.Email = attribute.Value;
                                    break;

                            }
                            i++;
                        }
                    }
                    var coment = (from c in comments
                                  where c.CommentItem == comment.CommentItem
                                  select c).FirstOrDefault();
                    if (coment == null)
                        comments.Add(comment);
                }
            }
            return comments;
        }
 public ActionResult CommentReply(string newsId, string commentreply, string username, string commentID)
 {
     Comment comment = new Comment();
     comment.CommentReplyID = commentID;
     comment.NewsID = newsId;
     comment.CommentItem = commentreply;
     comment.CommentID = Guid.NewGuid();
     comment.UserName = username;
     comment.CommentAdded = DateTime.Now;
     if (news.Comment.Count > 0)
         news.Comment.Clear();
     news.Comment.Add(comment);
     GetNewsFromAmazon.SaveComments(Settings.Default.DomainNameComment, comment);
     return View(news);
 }
 public ActionResult Like(int like, string commentId)
 {
     //likes = Convert.ToInt32(HttpContext.Request.QueryString["like"]);
     //commentID = Convert.ToString(HttpContext.Request.QueryString["Comment"]);
     like = like + 1;
     Comment comment = new Comment();
     comment.Likes = Convert.ToInt32(like);
     comment.CommentID = Guid.Parse(commentId);
     GetNewsFromAmazon.SaveLikes(Settings.Default.DomainNameComment, comment);
     if (news.Comment.Count > 0)
         news.Comment.Clear();
     news.Comment.Add(comment);
     return Json(new
     {
         like = like
     });
 }