Exemplo n.º 1
0
        public IActionResult Comments(SubmitCommentViewModel comment)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.CommentListModel = _commentService.GetComments();
                return(View(comment));
            }
            bool isSuccess = _commentService.AddComment(comment);

            if (isSuccess)
            {
                return(Redirect("/Comments?Success=true"));
            }
            else
            {
                return(View(comment));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SubmitComment(SubmitCommentViewModel model)
        {
            try
            {
                var comment = new EditCommentViewModel()
                {
                    CenterId = model.CenterId,
                    Message  = model.Message
                };
                await _commentService.Save(comment);

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Exemplo n.º 3
0
        public ActionResult PostComment(SubmitCommentViewModel comment)
        {
            var username = this.User.Identity.GetUserName();
            var userId   = this.User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                this.Data.Comments.Add(new Comment()
                {
                    AuthorId = userId,
                    Content  = comment.Content,
                    MovieId  = comment.MovieId,
                });

                this.Data.SaveChanges();
            }

            var viewModel = new CommentViewModel {
                AuthorUsername = username, Content = comment.Content
            };

            return(PartialView("_CommentPartial", viewModel));
        }
Exemplo n.º 4
0
        public bool AddComment(SubmitCommentViewModel comment)
        {
            if (comment.Email.Length > 9 && comment.FullName.Length > 3)
            {
                Comment newComment = new Comment()
                {
                    Text = comment.Text.SanitizeText(),
                    FullName = comment.FullName.SanitizeText(),
                    PhoneNumber = comment.PhoneNumber.SanitizeText(),
                    Email = comment.Email.SanitizeText(),
                    Date = DateTime.Now,
                    isPublic = false,
                    isDelete = false
                };
                db.comments.Add(newComment);
                db.SaveChanges();
                return true;
            }
            else
            {
                return false;

            }
        }