Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Mvc_Shop.Models
- {
- public class Comment
- {
- public Comment()
- {
- this.Children = new HashSet<Comment>();
- }
- public int Id { set; get; }
- public string Body { set; get; }
- public System.DateTime CommentDate { get; set; }
- public int? ReplyId { get; set; }
- public ICollection<Comment> Children { get; set; }
- public virtual Comment Reply { set; get; }
- public string User_Id { get; set; }
- [ForeignKey("User_Id")]
- public virtual User User { get; set; }
- public int Product_Id { get; set; }
- [ForeignKey("Product_Id")]
- public virtual Product Product { get; set; }
- }
- }
- @helper TreeView(IEnumerable<Mvc_Shop.Models.Comment> Comments)
- {
- foreach (var item in Comments)
- {
- <div class="media">
- <div class="media-body" id="Comment_@(item.Id)" style="padding: 3px;width: 100%;">
- <h4 class="media-heading">
- @item.User.UserName
- <label class="badge pull-left" style="font-weight: normal">@item.CommentDate.ToString("dddd, dd MMMM yyyy - HH:mm")</label>
- </h4>
- <div class="clearfix">
- @item.Body
- </div>
- <fieldset id="reply-cmnt-form_@(item.Id)" class="spr-form-review" style="display:none">
- <div class="spr-form-review-body">
- @Html.LabelFor(model => model.Comment.Body, new { @class = "spr-form-label" })
- @Html.TextAreaFor(model => model.Comment.Body, new { @class = "spr-form-input spr-form-input-text", id = "commentbody" + @item.Id })
- @Html.ValidationMessageFor(model => model.Comment.Body)
- </div>
- </fieldset>
- <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>
- <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>
- <a id="btn-show-div_@(item.Id)" class="btn btn-xs pull-left btn-primary" style="clear: both" onclick="opencmntdiv(@item.Id);"> پاسخ</a>
- </div>
- </div>
- <hr class="clearfix" />
- if (item.Children.Any())
- {
- @TreeView(item.Children)
- }
- }
- }
- @TreeView(Model.Comments)
- public ActionResult ShowProducts(string ProductName)
- {
- _dbContext = HttpContext.GetOwinContext().Get<ShopContext>();
- var model = new UserCommentViewModel();
- if (string.IsNullOrEmpty(ProductName))
- {
- return RedirectToAction("Index");
- }
- else
- {
- model.Products = blproduct.Where(p => p.Name.Trim() == ProductName.Trim()).ToList();
- model.Comments = (from u1 in _dbContext.Users
- join u2 in _dbContext.Comments
- on u1.Id equals u2.User.Id
- where u2.ReplyId == null
- select new {
- Id = u2.Id, Body = u2.Body, CommentDate = u2.CommentDate, User = u1,Children = u2.Children
- }).ToList().Select(x => new Comment
- {
- Id = x.Id, Body = x.Body, CommentDate = x.CommentDate, User = x.User,Children = x.Children
- }).ToList();
- if (model != null)
- {
- return View(model);
- }
- else
- {
- return RedirectToAction("Index");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement