Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. namespace Mvc_Shop.Models
  2.  
  3. public class Comment
  4. {
  5. public Comment()
  6. {
  7. this.Children = new HashSet<Comment>();
  8.  
  9. }
  10. public int Id { set; get; }
  11.  
  12. public string Body { set; get; }
  13.  
  14. public System.DateTime CommentDate { get; set; }
  15.  
  16. public int? ReplyId { get; set; }
  17.  
  18. public ICollection<Comment> Children { get; set; }
  19. public virtual Comment Reply { set; get; }
  20.  
  21. public string User_Id { get; set; }
  22. [ForeignKey("User_Id")]
  23. public virtual User User { get; set; }
  24. public int Product_Id { get; set; }
  25. [ForeignKey("Product_Id")]
  26. public virtual Product Product { get; set; }
  27.  
  28. }
  29.  
  30. @helper TreeView(IEnumerable<Mvc_Shop.Models.Comment> Comments)
  31.  
  32. foreach (var item in Comments)
  33.  
  34. {
  35. <div class="media">
  36. <div class="media-body" id="Comment_@(item.Id)" style="padding: 3px;width: 100%;">
  37. <h4 class="media-heading">
  38. @item.User.UserName
  39. <label class="badge pull-left" style="font-weight: normal">@item.CommentDate.ToString("dddd, dd MMMM yyyy - HH:mm")</label>
  40. </h4>
  41. <div class="clearfix">
  42. @item.Body
  43. </div>
  44. <fieldset id="reply-cmnt-form_@(item.Id)" class="spr-form-review" style="display:none">
  45. <div class="spr-form-review-body">
  46. @Html.LabelFor(model => model.Comment.Body, new { @class = "spr-form-label" })
  47.  
  48. @Html.TextAreaFor(model => model.Comment.Body, new { @class = "spr-form-input spr-form-input-text", id = "commentbody" + @item.Id })
  49. @Html.ValidationMessageFor(model => model.Comment.Body)
  50. </div>
  51. </fieldset>
  52. <a id="btn-hide-div_@(item.Id)" class="btn btn-xs pull-left btn-primary" style="clear: both; display:none" onclick="opencmntdiv(@item.Id);"> بستن</a>
  53. <a id="btn-send-div_@(item.Id)" class="btn btn-xs pull-left btn-primary" style="clear: both;float:right;display:none" onclick="ReplyComment(@item.Id);"> ارسال پاسخ</a>
  54. <a id="btn-show-div_@(item.Id)" class="btn btn-xs pull-left btn-primary" style="clear: both" onclick="opencmntdiv(@item.Id);"> پاسخ</a>
  55.  
  56. </div>
  57. </div>
  58. <hr class="clearfix" />
  59. if (item.Children.Any())
  60. {
  61. @TreeView(item.Children)
  62. }
  63. }
  64.  
  65. public ActionResult ShowProducts(string ProductName)
  66. {
  67. _dbContext = HttpContext.GetOwinContext().Get<ShopContext>();
  68. var model = new UserCommentViewModel();
  69. if (string.IsNullOrEmpty(ProductName))
  70. {
  71. return RedirectToAction("Index");
  72. }
  73. else
  74. {
  75. model.Products = blproduct.Where(p => p.Name.Trim() == ProductName.Trim()).ToList();
  76. model.Comments = (from u1 in _dbContext.Users
  77. join u2 in _dbContext.Comments
  78. on u1.Id equals u2.User.Id
  79. where u2.ReplyId == null
  80. select new {
  81. Id = u2.Id, Body = u2.Body, CommentDate = u2.CommentDate, User = u1,Children = u2.Children
  82. }).ToList().Select(x => new Comment
  83. {
  84. Id = x.Id, Body = x.Body, CommentDate = x.CommentDate, User = x.User,Children = x.Children
  85. }).ToList();
  86.  
  87.  
  88. if (model != null)
  89. {
  90. return View(model);
  91. }
  92. else
  93. {
  94. return RedirectToAction("Index");
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement