Пример #1
0
 public ActionResult AddComment(EntitiesViewModels model)
 {
     if (model.UserName != null && model.Text != null)
     {
         commentService.AddNewComment(model);
     }
     model.Comments = commentService.GetComments(model.Article.Id);
     return(PartialView(model));
 }
Пример #2
0
        public IActionResult Add([FromBody] Comment value)
        {
            var comment = _commentService.AddNewComment(value);

            if (comment == null)
            {
                return(NotFound("Bad Request"));
            }
            else
            {
                return(Ok("New comment is added"));
            }
        }
Пример #3
0
 public void AddComment()
 {
     using (var context = Context.CreateContext())
     {
         Post testPost = new Post
         {
             Header = "Test"
         };
         context.Posts.Add(testPost);
         CommentService commentService = new CommentService(context);
         commentService.AddNewComment("Test", testPost, "TestUser");
         context.Posts.Remove(testPost);
         context.SaveChanges();
         Assert.Equal(0, 0);
     }
 }
Пример #4
0
 public void ReadPostsComments()
 {
     using (var context = Context.CreateContext())
     {
         Post testPost = new Post
         {
             Header = "Test"
         };
         context.Posts.Add(testPost);
         CommentService commentService = new CommentService(context);
         commentService.AddNewComment("Test", testPost, "TestUser");
         var comments = commentService.GetComments(testPost);
         Assert.Equal("TestUser", comments.FirstOrDefault().Sender);
         context.Posts.Remove(testPost);
         context.SaveChanges();
     }
 }
        public async Task <IActionResult> OnPostCommentAsync([FromServices] UserManager <User> userManager, int PostId)
        {
            //var post = _postService.GetPost(PostId);
            User = await userManager.GetUserAsync(HttpContext.User);

            var CommentContent = Request.Form["NewComment"];

            if (CommentContent != "")
            {
                Comment comment = new Comment()
                {
                    PostId  = PostId,
                    UserId  = User.Id,
                    Content = CommentContent,
                };
                _commentService.AddNewComment(comment);
            }
            return(RedirectToPage("./Index"));
        }
Пример #6
0
        public ActionResult AddComment(ProductViewModel model)
        {
            Comment comment = new Comment
            {
                UserName = model.UserName,
                Email    = model.Email,
                Text     = model.CommentText
            };

            CommentService.AddNewComment(comment);

            var commentInProduct = new CommentInProduct();

            commentInProduct.ProductId = model.Id;
            commentInProduct.CommentId = comment.Id;
            CommentInProductService.AddNewCommentInProduct(commentInProduct);

            var commentInProductList = CommentInProductService.GetCommentInProduct().Where(x => x.ProductId == model.Id).ToList();
            var commentList          = CommentService.GetComments();
            var comments             = new List <Comment>();

            foreach (var item in commentInProductList)
            {
                comments.AddRange(commentList.Where(x => x.Id == item.CommentId).ToList());
            }
            var product = ProductService.GetProductByID(model.Id);

            ProductViewModel = new ProductViewModel
            {
                Id          = product.Id,
                Name        = product.Name,
                Price       = product.Price,
                Picture     = product.Picture,
                Description = product.Description,
                KindOfGoods = product.KindOfGoods,
                Brand       = product.Brand,
                Comments    = comments
            };
            return(PartialView("AddComment", ProductViewModel));
        }
Пример #7
0
        public IHttpActionResult AddComment(NewCommentViewModel vm)
        {
            _service.AddNewComment(vm);

            return(Ok());
        }