private CommentBM GetCommentInfo(Comment comment) { CommentBM commentBM = new CommentBM(); commentBM.Id = comment.ID; commentBM.Rate = comment.Rate; commentBM.Text = comment.Text; commentBM.Blocked = comment.Blocked; commentBM.UserName = context.Users.Where(x => x.ID == comment.GuestID).FirstOrDefault().UserName; return(commentBM); }
public IHttpActionResult GetCommentsForApartment(int apartmentID) { List <CommentBM> commentInfos = new List <CommentBM>(); ICollection <Comment> comments = context.Comments.Where(x => x.ApartmanID == apartmentID && x.Deleted == false && x.Blocked == false).ToList(); foreach (var comment in comments) { CommentBM commentBM = GetCommentInfo(comment); commentInfos.Add(commentBM); } return(Ok(commentInfos)); }
public ActionResult Create(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Post post = this.db.Posts.Find(id); if (post == null) { return(this.HttpNotFound()); } CommentBM comment = new CommentBM { PostId = post.Id }; return(this.View(comment)); }
public ActionResult Create([Bind(Include = "Content, PostId, YoutubeUrl")] CommentBM commentBm) { if (this.ModelState.IsValid) { Post post = this.db.Posts.Find(commentBm.PostId); Comment comment = new Comment { Post = post, Author = this.db.Users.First(x => x.UserName == this.User.Identity.Name), Content = commentBm.Content, CreatedOn = DateTime.Now, YoutubeUrl = "https://youtube.com/embed/" + commentBm.YoutubeUrl.Substring(commentBm.YoutubeUrl.Length - 11) }; this.db.Comments.Add(comment); this.service.AddLog("Wrote a comment", User.Identity.Name); this.db.SaveChanges(); return(this.RedirectToAction("Details", "Posts", new { id = commentBm.PostId })); } return(this.View(commentBm)); }
public IHttpActionResult GetAllCommentsForApartment(int apartmentID) { if (CheckRole("Admin")) { if (CheckRole("Host")) { return(StatusCode(HttpStatusCode.Unauthorized)); } } List <CommentBM> commentInfos = new List <CommentBM>(); ICollection <Comment> comments = context.Comments.Where(x => x.ApartmanID == apartmentID && x.Deleted == false).ToList(); foreach (var comment in comments) { if (comment.Deleted == false) { CommentBM commentBM = GetCommentInfo(comment); commentInfos.Add(commentBM); } } return(Ok(commentInfos)); }