예제 #1
0
        public async Task SeedComments()
        {
            if ((await _categoryRepo.GetCategoriesAsync()).Count > 0)
            {
                return;
            }
            var comment = new Comment
            {
                Content   = "First Comment Lorem Ipsum",
                CreatedAt = new DateTime(2020, 04, 10),
                Author    = "YunLa",
                PostId    = 2,
            };
            await _commentRepo.AddComment(comment);

            comment = new Comment
            {
                ParentCommentId = 1,
                Content         = "First Subcomment for first Comment Lorem Ipsum",
                CreatedAt       = new DateTime(2020, 04, 10),
                Author          = "YunLa",
                PostId          = 2,
            };
            await _commentRepo.AddComment(comment);

            comment = new Comment
            {
                Content   = "First Comment Lorem Ipsum",
                CreatedAt = new DateTime(2020, 04, 10),
                Author    = "YunLa",
                PostId    = 2,
            };
            await _commentRepo.AddComment(comment);
        }
예제 #2
0
        public void AddComment(CommentDto comment)
        {
            var com = _mapper.Map <Comment>(comment);

            _commentRepository.AddComment(com);
            _commentRepository.Save();
        }
예제 #3
0
        public async Task <IActionResult> PostComment([FromForm] Comment comment)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(comment.Author))
                    {
                        comment.Author = "Anonymous";
                    }
                    comment.CreatedAt = DateTime.UtcNow;
                    await _commentRepo.AddComment(comment);

                    Notification notification = new Notification
                    {
                        Title       = $"{comment.Author} { (comment.ParentCommentId != null ? "Replied to a comment on a post" : "commented on a post")}",
                        Link        = $"{comment.PostId}",
                        Description = "",
                        CreatedAt   = DateTime.Now,
                        Read        = false
                    };
                    await _notifRepo.AddNotification(notification);

                    var subject = "COMMENT NOTIFICATION";
                    var message = $"{notification.Title} \n Link: www.selahseries.com/admin";
                    await _emailService.SendEmail(subject, message);
                }
                catch { return(RedirectToAction("Post", "Blog", new { postId = comment.PostId })); }
            }
            return(RedirectToAction("Post", "Blog", new { postId = comment.PostId }));
        }
예제 #4
0
        public Comment AddComment(string blogName, string userName, string email, string comment, int?replyId = null)
        {
            var blogPost = _blogRepository.GetBlogByName(blogName);

            if (blogPost != null)
            {
                var cmt = _commentRepository.AddComment(new Comment()
                {
                    BlogItemId      = blogPost.Id,
                    Content         = comment,
                    ParentId        = replyId,
                    SubCommentCount = 0,
                    Username        = userName,
                    Email           = email,
                    DateSent        = DateTime.Now
                });
                if (replyId != null)
                {
                    UpdateSubCommentCount(replyId.Value);
                }
                _commentRepository.SaveChanges();
                return(cmt);
            }
            return(null);
        }
예제 #5
0
        public async Task <IActionResult> SaveComment(CommentFormViewModel comment)
        {
            if (!ModelState.IsValid)
            {
                return(Post(comment.PostId));
            }

            // comment
            if (comment.CommentId == 0)
            {
                _commentRepository.AddComment(comment.PostId, new Comment {
                    UserName = User.Identity.Name, Message = comment.Message
                });
                await _commentRepository.SaveChangesAsync();
            }
            // sub-comment
            else
            {
                _subCommentRepository.AddSubComment(comment.CommentId, new SubComment {
                    UserName = User.Identity.Name, Message = comment.Message
                });
                await _subCommentRepository.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Post), new { id = comment.PostId }));
        }
        public IActionResult AddComment([FromHeader(Name = "CommunicationKey")] string key, CommentCreateDto commentDto, [FromQuery] int userID)
        {
            if (productRepository.GetProductByID(commentDto.ProductID) == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Product with given ID does not exist"));
            }

            var comment  = mapper.Map <Comments>(commentDto);
            var product  = productRepository.GetProductByID(comment.ProductID);
            var sellerID = product.SellerID;

            if (!commentRepository.CheckDoIFollowSeller(userID, sellerID))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, String.Format("You are not following user with id {0} and you can not comment his products", sellerID)));
            }

            comment.UserID      = userID;
            comment.CommentDate = DateTime.Today;

            try
            {
                commentRepository.AddComment(comment);
                commentRepository.SaveChanges();
                logger.Log(LogLevel.Information, contextAccessor.HttpContext.TraceIdentifier, "", String.Format("Successfully created new comment with ID {0} in database", comment.CommentID), null);

                return(StatusCode(StatusCodes.Status201Created, "Comment is successfully created!"));
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, contextAccessor.HttpContext.TraceIdentifier, "", String.Format("Comment with ID {0} not created, message: {1}", comment.CommentID, ex.Message), null);

                return(StatusCode(StatusCodes.Status500InternalServerError, "Create error " + ex.Message));
            }
        }
        public IActionResult PostComment(PostComment postComment)
        {
            Comment comment = new Comment
            {
                Fullname   = postComment.FullName,
                Email      = postComment.Email,
                Text       = postComment.Comment,
                Type       = "visitor",
                CreateTime = DateTime.Now,
                IsActive   = false,
                BlogId     = postComment.BlogId,
                ParentId   = 0
            };

            if (postComment.CommentId != null)
            {
                comment.ParentId = Convert.ToInt32(postComment.CommentId);
            }

            if (postComment.ToName != null)
            {
                comment.AnswerToName = postComment.ToName;
            }


            return(new JsonResult(commentRepository.AddComment(comment)));
        }
예제 #8
0
        public JsonResult Create(string commentBody, int recipeId, string applicationUserId)
        {
            string  userName   = _signInManager.UserManager.GetUserAsync(User).Result.Name;
            Comment newComment = new Comment
            {
                Body                = commentBody,
                RecipeId            = recipeId,
                ApplicationUserId   = applicationUserId,
                ApplicationUserName = userName
            };

            _commentRepository.AddComment(newComment);

            string jsonString = JsonConvert.SerializeObject(new
                                                            { userId = newComment.ApplicationUserId,
                                                              userName         = newComment.ApplicationUserName,
                                                              commentBody      = newComment.Body,
                                                              commentCreatedOn = newComment.CreatedOn,
                                                              commentId        = newComment.Id.ToString() },
                                                            Formatting.Indented,
                                                            new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Json(jsonString));
        }
 public ViewResult Comment(Comment comment)
 {
     // stores contact messages
     comment.CommentTime = DateTime.Now;
     repo.AddComment(comment);
     return(View());
 }
예제 #10
0
        public IActionResult Post(string boardUrl, string postUrl, PostComment postComment)
        {
            var post          = _fetchPostService.GetPostByBoardAndUrl(boardUrl, postUrl);
            var parentComment = postComment.ParentCommentId != null?_commentRepository.GetCommentById(postComment.ParentCommentId.Value) : null;

            var user = _userRepository.GetUserByAuthId(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);

            if (user == null)
            {
                return(BadRequest("User is null."));
            }

            // If we're replying to a comment, ensure that comment is on the same post that we're attempting to comment on
            if (parentComment != null && parentComment.Post != post)
            {
                return(BadRequest("Parent comment doesn't belong to the post you're replying to!"));
            }

            var comment = new Comment
            {
                Content         = postComment.Content,
                Post            = post,
                ParentComment   = parentComment,
                CreatedBy       = user,
                CreatedDateTime = DateTime.UtcNow
            };

            _commentRepository.AddComment(comment);
            return(Json(_commentResponseMapper.MapDbToResponse(comment)));
        }
예제 #11
0
 public void AddCheck(string newsId, Comment comment)
 {
     if (newsRepo.GetByNewsAppRef(newsId) != null)
     {
         var oldNews = newsRepo.GetByNewsAppRef(newsId);
         commentRepo.AddComment(oldNews, comment);
     }
     else
     {
         News news = new News()
         {
             NewsAppRef = newsId
         };
         newsRepo.AddNews(news);
         commentRepo.AddComment(news, comment);
     }
 }
예제 #12
0
        public BaseResponse AddComment(Comment comment, string userId)
        {
            var dbComment = LocalMapper.Map <Data.Models.Comment>(comment);

            dbComment.ApplicationUserId = userId;
            dbComment = _commentRepository.AddComment(dbComment);

            return(new SuccessResponse <Comment>(LocalMapper.Map <Comment>(dbComment)));
        }
예제 #13
0
        public IActionResult AddComment(int id, string newComment)
        {
            var userIdClaim = HttpContext.User.FindFirst("Id")?.Value;
            var userId      = userIdClaim == null ? 0 : int.Parse(userIdClaim.ToString());

            _commentRepository.AddComment(id, userId, newComment);

            return(RedirectToAction("ViewPost", "Posts", new { id = id }));
        }
예제 #14
0
        public ActionResult Details(DetailsPhotoViewModel photo, FormCollection collection)
        {
            var comment = new Comment
            {
                Date    = DateTime.Now,
                Content = collection["comment"],
                UserID  = UserHelper.GetLogedInUser(userRepository).Id,
                PhotoID = photo.Id
            };

            commentRepository.AddComment(comment);

            Photo photoFromDB = photoRepository.GetPhotoFromDbById(photo.Id);

            photo = PhotoMapper.MapDetailsPhotoViewModel(photoFromDB);

            return(View(photo));
        }
예제 #15
0
 public IActionResult AddComment(Comment newComment)
 {
     newComment.Id          = Guid.NewGuid();
     newComment.DateCreated = DateTime.Now;
     _commentRepository.AddComment(newComment);
     return(RedirectToAction("EventDetails", new EventDetailsViewModel {
         EventId = newComment.EventId
     }));
 }
예제 #16
0
        public async Task<IActionResult> AddComment([FromBody] Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(comment);
            }

            await commentRepository.AddComment(comment);
            return Ok();
        }
예제 #17
0
        public IActionResult Post(Comment comment)
        {
            UserProfile userProfile = GetCurrentUserProfile();

            comment.UserProfileId  = userProfile.Id;
            comment.CreateDateTime = DateTime.Now;
            _commentRepository.AddComment(comment);
            //produces a status code of 201, which means userProfile object created sucessfully
            return(Ok());
        }
        public async Task <IActionResult> AddComment(CommentForCreationDto commentForCreationDto)
        {
            if (commentForCreationDto.NickName == null)
            {
                return(BadRequest("Nie wprowadzono Nicku"));
            }

            await _commentRepository.AddComment(commentForCreationDto);

            return(Ok());
        }
예제 #19
0
        public HttpResponseMessage AddComment(CommentDTO commentDTO)
        {
            Comment commentToAdd = mapper.CreateCommentEntity(commentDTO);

            commentToAdd = commentRepo.AddComment(commentToAdd);
            var    response = Request.CreateResponse <ListingDetailDTO>(HttpStatusCode.Created, mapper.CreateListingDetailDTO(commentToAdd.Listing));
            string uri      = Url.Link("DefaultApi", new { id = commentToAdd.ListingId });

            response.Headers.Location = new Uri(uri);
            return(response);
        }
예제 #20
0
        /// <summary>
        /// Add a new comment
        /// </summary>
        /// <param name="commentDto">Comment details</param>
        /// <returns>Comment Id</returns>
        public async Task <int> AddComment(CommentDto commentDto)
        {
            var comment = new Comment()
            {
                PostId      = commentDto.PostId,
                Text        = commentDto.Text,
                CommentDate = commentDto.CommentDate
            };

            return(await _repository.AddComment(comment));
        }
예제 #21
0
 public async Task <Comments> AddComment(Comments comment)
 {
     try
     {
         return(await _repository.AddComment(comment));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #22
0
        public IActionResult Post(Comment comment)
        {
            var currentUserProfile = GetCurrentUserProfile();

            if (currentUserProfile == null)
            {
                return(Unauthorized());
            }
            _commentRepository.AddComment(comment);
            return(NoContent());
        }
        public async Task <Comment> Add(Comment comment)
        {
            var user = _usersService.GetCurrentUser();

            comment.UserId = user.Id;
            comment        = _repository.AddComment(comment);
            await _repository.SaveChanges();

            comment.User = user;
            return(comment);
        }
예제 #24
0
 public IActionResult Comment(Comment comment)
 {
     comment = _commentRepository.AddComment(comment);
     if (comment != null)
     {
         return(new JsonResult(comment));
     }
     else
     {
         return(new BadRequestResult());
     }
 }
예제 #25
0
        public IActionResult Send(int Postid, string Name, string Message)
        {
            Comment comment = new Comment();

            comment.PostId  = Postid;
            comment.Name    = Name;
            comment.Content = Message;
            comment.Date    = DateTime.Now;
            comment.Status  = true;
            _commentRepository.AddComment(comment);
            return(RedirectToAction("detailpost", new { id = Postid }));
        }
예제 #26
0
 public IActionResult Create(Comment comment)
 {
     try
     {
         _commentRepository.AddComment(comment);
         return(RedirectToAction("Index"));
     }
     catch (Exception)
     {
         return(View(comment));
     }
 }
예제 #27
0
 public ActionResult Add(Comment comment)
 {
     if (ModelState.IsValid)
     {
         repository.AddComment(comment);
         return(RedirectToAction("Index", new { id = comment.Post.PostId }));
     }
     else
     {
         return(View("Index", new { id = comment.Post.PostId }));
     }
 }
예제 #28
0
        public async Task <IActionResult> AddComment([FromBody] CommentDto comment)
        {
            // jeżeli nie ma ekwipunku
            if (!await _repo.EquipmentExists(comment.EquipmentId))
            {
                return(BadRequest("Ekwipunek nie istnieje :C"));
            }

            var addComment = await _repo.AddComment(comment.CommentString, comment.EquipmentId, comment.UserId);

            return(StatusCode(201));
        }
예제 #29
0
        public CommentDto AddComment(AddCommentRequest addCommentRequest)
        {
            var comment = _newCommentMapper.Map(addCommentRequest);

            _commentRepository.AddComment(comment);

            var user = _userRepository.GetUserById(comment.User.Id);

            comment.User = user;

            return(_masterCommentMapper.Map(comment));
        }
예제 #30
0
        public async Task <IActionResult> CreateComment([FromBody] CommentForCreatingDto comment, [FromQuery] string fields, Guid postId)
        {
            var commentEntity = _mapper.Map <Comment>(comment);

            await _commentRepository.AddComment(commentEntity, postId, Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier))).ConfigureAwait(false);

            await _commentRepository.Save().ConfigureAwait(false);

            var commentToReturn = _mapper.Map <CommentOutputDto>(commentEntity);

            return(CreatedAtRoute("GetComment", new { commentId = commentToReturn.Id, fields }, commentToReturn.ShapeData(fields)));
        }