示例#1
0
        public ActionResult Reply(NewPost form)
        {
            string val     = Convert.ToString(Request.Params["CmtId"]);
            var    comment = Database.Session.Load <Comment>(Int32.Parse(val));

            if (comment == null)
            {
                return(HttpNotFound());
            }

            var reply = new CommentReply()
            {
                comment = comment,
                author  = Database.Session.Query <User>().FirstOrDefault(x => x.pseudo == User.Identity.Name),
                content = form.newReply,
                date    = DateTime.Now
            };

            if (reply.content != null)
            {
                Database.Session.Save(reply);
                Database.Session.Flush();
            }

            return(RedirectToAction("display", new { id = comment.post.id }));
        }
示例#2
0
        public async Task <IActionResult> PostCommentReply(CommentReply reply)
        {
            if (reply == null)
            {
                return(BadRequest(new { message = "Reply is null!" }));
            }

            if (string.IsNullOrEmpty(reply.Content))
            {
                return(BadRequest(new { message = "Missing comment content" }));
            }

            if (string.IsNullOrEmpty(reply.Role))
            {
                return(Unauthorized(new { message = "User is unauthorized!" }));
            }

            var newReply = await _commentService.PostCommentReplyAsync(reply);

            return(Ok(new
            {
                status = "success",
                message = "Reply posted"
            }));
        }
示例#3
0
        public async Task <IActionResult> PutCommentReply(int id, CommentReply commentReply)
        {
            if (id != commentReply.CommentReplyId)
            {
                return(BadRequest());
            }

            _context.Entry(commentReply).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentReplyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#4
0
        public async Task <ActionResult <CommentReply> > PostCommentReply(CommentReply commentReply)
        {
            _context.CommentReply.Add(commentReply);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCommentReply", new { id = commentReply.CommentReplyId }, commentReply));
        }
        public async Task <IActionResult> Get(int id)
        {
            ModelResult <CommentInfo> result;
            Comment commentResult = await _context.Comments
                                    .FirstOrDefaultAsync(c => c.CommentId == id);

            if (commentResult == null)
            {
                result = new ModelResult <CommentInfo>(404, null, "Comment Not Exists");
                return(BadRequest(result));
            }

            CommentInfo  commentInfo  = new CommentInfo(commentResult);
            CommentReply commentReply = await _context.CommentReplies
                                        .FirstOrDefaultAsync(cr => cr.CommentId == commentInfo.CommentId);

            if (commentReply != null)
            {
                commentInfo.IsReply          = true;
                commentInfo.RepliedCommentId = commentReply.RepliedCommentId;
            }
            else
            {
                commentInfo.IsReply          = false;
                commentInfo.RepliedCommentId = 0;
            }

            result = new ModelResult <CommentInfo>(400, commentInfo, null);
            return(Ok(result));
        }
示例#6
0
        public async Task <IHttpActionResult> PostCommentReply(CommentReply comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!(HttpContext.Current.Request.IsAuthenticated))
            {
                return(BadRequest());
            }
            comment.time     = DateTime.UtcNow;
            comment.postedBy = User.Identity.GetUserId();
            db.CommentReplies.Add(comment);
            await db.SaveChangesAsync();

            var ret = db.CommentReplies.Where(x => x.Id == comment.Id).Select(x => new
            {
                description    = x.description,
                postedById     = x.postedBy,
                postedByName   = x.AspNetUser.Email,
                time           = x.time,
                imageExtension = x.AspNetUser.dpExtension,
                id             = x.Id,
            }).FirstOrDefault();

            return(Ok(ret));
        }
示例#7
0
        public IActionResult CreateReplyForCommentById(int id, [FromBody] CommentReplyDto commentReply, [FromHeader] int UserID, [FromHeader] string UserRole)
        {
            var comment = _context.Comments.Find(id);

            if (comment == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }

            if (_user.GetUserById(UserID) == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }

            var newCommentReply = new CommentReply()
            {
                Text    = commentReply.Text,
                UserId  = UserID,
                Comment = comment
            };

            _context.CommentReplies.Add(newCommentReply);
            var success = _context.SaveChanges();

            if (success < 1)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }

            return(StatusCode(StatusCodes.Status201Created, new JsonResult(newCommentReply)));
        }
示例#8
0
        public ActionResult CommentReply()
        {
            int          id           = Convert.ToInt32(Request.Params["PostId"]);
            int          commentID    = Convert.ToInt32(Request.Params["CommentID"]);
            CommentReply commentReply = new CommentReply();

            commentReply.Content        = Request.Params["NewReply"];
            commentReply.CommentID      = commentID;
            commentReply.CommentReplyID = 2;
            commentReply.AuthorID       = User.Identity.Name;
            commentReply.PostID         = 1;
            commentReply.PersonID       = id;
            commentReply.MovieID        = 0;
            db.CommentReply.Add(commentReply);
            db.SaveChanges();
            //-----------------
            List <Comment> lstComment = db.Comment.Where(c => c.PostID == id).ToList();

            Forum forum = db.Forums.Find(id);

            forum.Comment = lstComment;
            int numerosoby = forum.PostID;


            if (forum == null)
            {
                return(HttpNotFound());
            }
            return(RedirectToAction("Details/" + id));
        }
        public async Task NotifyCommentReplyAsync(CommentReply model, string postLink)
        {
            if (!_isEnabled)
            {
                _logger.LogWarning($"Skipped {nameof(NotifyCommentReplyAsync)} because Email sending is disabled.");
                return;
            }

            try
            {
                var req = new CommentReplyPayload(
                    model.Email,
                    model.CommentContent,
                    model.Title,
                    model.ReplyContentHtml,
                    postLink);

                await SendAsync(
                    new NotificationRequest <CommentReplyPayload>(MailMesageTypes.AdminReplyNotification, req));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
            }
        }
示例#10
0
        public ActionResult CommentReply()
        {
            int          id           = Convert.ToInt32(Request.Params["MovieID"]);
            int          commentID    = Convert.ToInt32(Request.Params["CommentID"]);
            CommentReply commentReply = new CommentReply();

            commentReply.Content   = Request.Params["NewReply"];
            commentReply.CommentID = commentID;
            //commentReply.CommentReplyID = 2;
            commentReply.AuthorID = User.Identity.Name;
            commentReply.PostID   = 0;
            commentReply.PersonID = 0;
            commentReply.MovieID  = id;
            db.CommentReply.Add(commentReply);
            db.SaveChanges();
            //-----------------
            List <Comment> lstComment = db.Comment.Where(c => c.PersonID == id).ToList();

            Movie movie = db.Movies.Find(id);

            movie.Comment = lstComment;
            int numerosoby = movie.MovieID;

            List <MoviePerson> mp = db.MoviePerson.Where(i => i.personID == numerosoby).ToList();

            if (movie == null)
            {
                return(HttpNotFound());
            }
            return(RedirectToAction("Details/" + id));
        }
示例#11
0
        public ActionResult Create([Bind(Include = "Text,CommentId, CardId")] CommentReply commentReply, int cardId)
        {
            commentReply.CreatedOn = DateTime.Now;

            if (commentReply.Text.Contains("@Reply:"))
            {
                commentReply.Text = commentReply.Text.Replace("@Reply:", "");
            }
            else
            {
                commentReply.Text = commentReply.Text;
            }


            commentReply.AspNetUserId = HttpContext.User.Identity.GetUserId();

            db.CommentReplies.Add(commentReply);
            db.SaveChanges();

            ViewBag.Comments = db.Comments
                               .Where((i) => i.CardId == cardId)
                               .OrderByDescending((i) => i.CreatedOn).Include((i) => i.CommentReplies.Select((j) => j.AspNetUser)).ToList();


            return(PartialView("../../Views/Comments/_CommentsList"));
        }
        public CommentReplyConfirmationDto Create(CommentReplyCreateDto dto)
        {
            User user = MockedData.Users.FirstOrDefault(e => e.Id == dto.UserId);

            if (user == null)
            {
                throw new BusinessException("User does not exit");
            }

            CommentReply commentReply = new CommentReply()
            {
                Id        = Guid.NewGuid(),
                Content   = dto.Content,
                CreatedAt = DateTime.UtcNow,
                UserId    = dto.UserId,
                CommentId = dto.CommentId
            };

            _context.CommentReplies.Add(commentReply);
            _context.SaveChanges();

            _logger.Log("Comment reply created");

            return(_mapper.Map <CommentReplyConfirmationDto>(commentReply));
        }
        public void InstanceOk()
        {
            //create an instance of the calss we want to create
            CommentReply AReply = new CommentReply();

            //test to see that it exists
            Assert.IsNotNull(AReply);
        }
        public async Task <CommentReply> PostCommentReplyAsync(CommentReply reply)
        {
            await _context.CommentReplies.AddAsync(reply);

            await _context.SaveChangesAsync();

            return(reply);
        }
        public ActionResult DeleteConfirmed(long id)
        {
            CommentReply commentreply = db.CommentReplies.Find(id);

            db.CommentReplies.Remove(commentreply);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#16
0
 public void AddCommentReply(CommentReply commentReply)
 {
     using (var db = new CooksContext())
     {
         db.Entry(commentReply).State = Microsoft.EntityFrameworkCore.EntityState.Added;
         db.SaveChanges();
     }
 }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            CommentReply commentReply = await db.CommentReplies.FindAsync(id);

            db.CommentReplies.Remove(commentReply);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
示例#18
0
        public ActionResult Details(int?id)
        {
            ViewBag.UserId = User.Identity.Name; //impletemnt
            Movie movie = db.Movies.Find(id);    //

            List <Comment> Allcomment = db.Comment.ToList();

            ViewBag.isban = false;
            foreach (Comment test in Allcomment)
            {
                if (test.isBlocked == true && User.Identity.Name == test.AuthorID)
                {
                    ViewBag.isban = true;
                }
            }

            List <Comment> lstComment    = db.Comment.Where(c => c.MovieID == id).ToList();
            float          averageRating = movie.Rating;
            int            count         = 1;

            foreach (Comment item in lstComment)
            {
                CommentReply        commentReply    = new CommentReply();
                List <CommentReply> lstCommentReply = new List <CommentReply>();
                if (db.CommentReply.Where(c => c.CommentID == item.CommentID).ToList() != null)//
                {
                    lstCommentReply = db.CommentReply.Where(c => c.CommentID == item.CommentID).ToList();
                }
                averageRating += item.UserRating;
                count++;
            }


            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            movie.Comment = lstComment;
            int numerFilmu = movie.MovieID;//

            movie.Rating = averageRating / count;
            List <MoviePerson> mp = db.MoviePerson.Where(i => i.MovieID == numerFilmu).ToList();

            foreach (MoviePerson movpers in mp)
            {
                Person p2 = db.People.Find(movpers.personID);
                movie.People.Add(p2);
            }

            if (movie == null)
            {
                return(HttpNotFound());
            }
            return(View(movie));
        }
        //
        // GET: /CommentReply/Details/5

        public ActionResult Details(long id = 0)
        {
            CommentReply commentreply = db.CommentReplies.Find(id);

            if (commentreply == null)
            {
                return(HttpNotFound());
            }
            return(View(commentreply));
        }
        //
        // GET: /CommentReply/Edit/5

        public ActionResult Edit(long id = 0)
        {
            CommentReply commentreply = db.CommentReplies.Find(id);

            if (commentreply == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CommentID = new SelectList(db.Comments, "CommentID", "Username", commentreply.CommentID);
            return(View(commentreply));
        }
 public ActionResult Edit(CommentReply commentreply)
 {
     if (ModelState.IsValid)
     {
         db.Entry(commentreply).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CommentID = new SelectList(db.Comments, "CommentID", "Username", commentreply.CommentID);
     return(View(commentreply));
 }
        public void PostIdPropertyOk()
        {
            //create an instance of the class we want to create
            CommentReply AReply = new CommentReply();
            //create some test data to assign to the property
            int TestData = 10;

            AReply.PostID = TestData;
            //test to see that the two values are the same
            Assert.AreEqual(AReply.PostID, TestData);
        }
        public void ContentPropertyOk()
        {
            //create an instance of the class we want to create
            CommentReply AReply = new CommentReply();
            //create some test data to assign to the property
            string TestData = "aaa";

            AReply.Content = TestData;
            //test to see that the two values are the same
            Assert.AreEqual(AReply.Content, TestData);
        }
示例#24
0
        public Response <CommentReplySummary> NewReply(Guid commentId, string replyContent, string ipAddress, string userAgent)
        {
            try
            {
                if (!_blogConfig.EnableComments)
                {
                    return(new FailedResponse <CommentReplySummary>((int)ResponseFailureCode.CommentDisabled));
                }

                var cmt = _commentRepository.Get(commentId);

                if (null == cmt)
                {
                    return(new FailedResponse <CommentReplySummary>((int)ResponseFailureCode.CommentNotFound));
                }

                var id    = Guid.NewGuid();
                var model = new CommentReply
                {
                    Id           = id,
                    ReplyContent = replyContent,
                    IpAddress    = ipAddress,
                    UserAgent    = userAgent,
                    ReplyTimeUtc = DateTime.UtcNow,
                    CommentId    = commentId
                };

                _commentReplyRepository.Add(model);

                var summary = new CommentReplySummary
                {
                    CommentContent = cmt.CommentContent,
                    CommentId      = commentId,
                    Email          = cmt.Email,
                    Id             = model.Id,
                    IpAddress      = model.IpAddress,
                    PostId         = cmt.PostId,
                    PubDateUTC     = cmt.Post.PostPublish.PubDateUtc,
                    ReplyContent   = model.ReplyContent,
                    ReplyTimeUtc   = model.ReplyTimeUtc,
                    Slug           = cmt.Post.Slug,
                    Title          = cmt.Post.Title,
                    UserAgent      = model.UserAgent
                };

                return(new SuccessResponse <CommentReplySummary>(summary));
            }
            catch (Exception e)
            {
                Logger.LogError(e, $"Error {nameof(NewReply)}");
                return(new FailedResponse <CommentReplySummary>((int)ResponseFailureCode.GeneralException));
            }
        }
        public IActionResult AddCommentReply(CommentReply commentReply)
        {
            commentReply.ID        = Guid.NewGuid();
            commentReply.AddedDate = DateTime.Now;
            var result = _commentService.AddCommentReply(commentReply);

            if (result.Succes)
            {
                return(Ok(result.Message));
            }
            return(NotFound(result.Message));
        }
示例#26
0
        public ActionResult DeleteConfirmed(int id, int cardId)
        {
            CommentReply commentReply = db.CommentReplies.Find(id);

            db.CommentReplies.Remove(commentReply);
            db.SaveChanges();
            ViewBag.Comments = db.Comments
                               .Where((i) => i.CardId == cardId)
                               .OrderByDescending((i) => i.CreatedOn).Include((i) => i.CommentReplies.Select((j) => j.AspNetUser)).ToList();

            return(PartialView("../../Views/Comments/_CommentsList"));
        }
示例#27
0
        /// <summary>
        /// 获取评论集合
        /// </summary>
        public ResponseModel GetCommentList(Expression <Func <NewsComment, bool> > where)
        {
            var comments = _db.NewsComment.Include("News").Where(where).OrderBy(c => c.AddTime).ToList();
            var response = new ResponseModel();

            response.code   = 200;
            response.result = "评论获取成功";
            response.data   = new List <CommentModel>();
            int        floor   = 1;
            HtmlToText convert = new HtmlToText();

            foreach (var comment in comments)
            {
                CommentModel cm = new CommentModel();
                cm.Id        = comment.Id;
                cm.NewsId    = comment.NewsId;
                cm.NewsName  = comment.News.Title;
                cm.UserName  = _userService.GetOneUsers(comment.UserId).data.F_RealName;
                cm.UserId    = comment.UserId;
                cm.UserImage = _userService.GetOneUsers(comment.UserId).data.F_Image;
                cm.Contents  = convert.ConvertImgByFace(comment.Contents);
                cm.AddTime   = comment.AddTime;
                cm.Love      = comment.Love;
                cm.Remark    = comment.Remark;
                cm.Floor     = "#" + floor;

                List <NewsComment>  nc    = GetRaplyComment(comment.Id);
                List <CommentReply> crlst = new List <CommentReply>();
                if (nc.Count() > 0)
                {
                    foreach (var item in nc)
                    {
                        CommentReply cr = new CommentReply();
                        cr.NewsId         = item.NewsId;
                        cr.OldId          = item.OldId;
                        cr.UserName       = _userService.GetOneUsers(item.UserId).data.F_RealName;
                        cr.ReplyUserId    = item.ReplyUserId;
                        cr.ReplyUserName  = _userService.GetOneUsers(item.ReplyUserId).data.F_RealName;
                        cr.ReplyUserImage = _userService.GetOneUsers(item.ReplyUserId).data.F_Image;
                        cr.Id             = item.Id;
                        cr.Love           = item.Love;
                        cr.Contents       = convert.ConvertImgByFace(item.Contents);
                        cr.AddTime        = item.AddTime;
                        crlst.Add(cr);
                    }
                }
                cm.crLst = crlst;
                response.data.Add(cm);
                floor++;
            }
            response.data.Reverse();
            return(response);
        }
示例#28
0
        public async Task <ActionResult <PostsDTO> > CommentReply(CommentReply reply)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _context.Replies.Add(reply);

            var success = await _context.SaveChangesAsync();

            return(Ok("reply successfully saved"));
        }
        public IActionResult ReplyToComment(int courseModuleId, string reply, int commentId, int memberId)
        {
            Comment      comment    = _courseModuleRepository.GetComment(courseModuleId, commentId);
            Member       member     = _memberRepository.GetById(memberId);
            CommentReply replyToAdd = new CommentReply {
                ReplyText = reply, Comment = comment, Member = member
            };

            _courseModuleRepository.AddCommentReply(replyToAdd, commentId, courseModuleId);
            _courseModuleRepository.SaveChanges();

            return(RedirectToAction("Index", new { memberId = memberId, courseModuleId = courseModuleId }));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,AuthorId,Body,Created,Updated,BlogPostId")] CommentReply commentReply)
        {
            if (ModelState.IsValid)
            {
                db.Entry(commentReply).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.AuthorId   = new SelectList(db.Users, "Id", "FirstName", commentReply.AuthorId);
            ViewBag.BlogPostId = new SelectList(db.BlogPosts, "Id", "Title", commentReply.BlogPostId);
            return(View(commentReply));
        }