Example #1
0
        public IActionResult AddCommentToPost(Guid Id)
        {
            try
            {
                var CurrentUser = _context.Users.Find(userManager.GetUserId(User));
                if (CurrentUser is null)
                {
                    return(RedirectToAction("Login", "Accounts"));
                }
                var existingAccount = _userStore.GetByIdentityUserId(CurrentUser.Id);
                if (existingAccount.AccountStatus.Equals(Status.Suspended))
                {
                    signInManager.SignOutAsync();
                }
                _currentpost.Id = Id;

                var existingPost  = _postStore.ViewPost(Id);
                var addCommentDTO = new AddCommentDTO
                {
                    UserId = CurrentUser.Id,
                    PostId = existingPost.Id
                };
                return(View(addCommentDTO));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(RedirectToAction(ActionName.ServerError, ControllerName.Accounts));
            }
        }
Example #2
0
        public IHttpActionResult AddComment(AddCommentDTO comment)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(User.Identity.Name).UserID;
            }
            var newComment = new CommentThread
            {
                UserId      = CurrenUser,
                ThreadId    = comment.ThreadId,
                Content     = comment.CommentContent,
                Status      = true,
                CommentDate = DateTime.Now
            };

            using (var db = new ThreadDAL())
            {
                newComment = db.AddNewComment(newComment);
            }
            return(Ok(new HTTPMessageDTO {
                Status = WsConstant.HttpMessageType.SUCCESS, Data = newComment
            }));
        }
Example #3
0
        public async Task <Comment> AddComment(AddCommentDTO addCommentDTO)
        {
            var eventDB = await _context.Events.FirstOrDefaultAsync(x => x.Id == addCommentDTO.EventId);

            if (eventDB == null)
            {
                return(null);
            }

            var userDB = await _context.Users.FirstOrDefaultAsync(x => x.Id == addCommentDTO.UserId);

            if (userDB == null)
            {
                return(null);
            }

            var newComment = new Comment()
            {
                CommentText = addCommentDTO.CommentText,
                CreatedOn   = DateTime.Now,
                User        = userDB
            };


            await _context.Comments.AddAsync(newComment);


            eventDB.Comments.Add(newComment);

            await _context.SaveChangesAsync();

            return(newComment);
        }
        public async Task AddComment(AddCommentDTO model)
        {
            var comment = _mapper.Map <AddCommentDTO, Comment>(model);

            await _unitOfWork.Comment.Add(comment);

            await _unitOfWork.Commit();
        }
Example #5
0
        public IActionResult AddComment(AddCommentDTO dto)
        {
            this.itemService.AddComment(dto.UserId, dto.ItemId, dto.Content, dto.Rating, DateTime.Now);
            TempData["message"] = "Kommentedet sikeresen rögzítettük";
            var url = this.Request.Headers["Referer"].ToString();

            return(Redirect(url));
        }
        public async Task <ActionResult <CommentDTO> > Post(AddCommentDTO postCommentDto)
        {
            var postComment = await _commentRepository.AddCommentAsync(postCommentDto);

            var result = new CommentDTO(postComment, new List <CommentDTO>());
            await _mediator.Send(new AddCommentCommand(result));

            return(CreatedAtAction(nameof(Get), new { id = postComment.Id }, postComment));
        }
Example #7
0
        public IActionResult AddCommentToPost(AddCommentDTO addCommentDTO)
        {
            try
            {
                var CurrentUser = _context.Users.Find(userManager.GetUserId(User));
                if (CurrentUser is null)
                {
                    return(RedirectToAction("Login", "Accounts"));
                }
                var existingAccount = _userStore.GetByIdentityUserId(CurrentUser.Id);


                if (ModelState.IsValid)
                {
                    var existingPost = _postStore.ViewPost(_currentpost.Id);
                    if (existingPost is null)
                    {
                        return(RedirectToAction("NotFound", "Accounts"));
                    }

                    var comment = new Comment()
                    {
                        Content    = addCommentDTO.Content,
                        PostId     = _currentpost.Id,
                        UserId     = CurrentUser.Id,
                        DatePosted = DateTime.Now
                    };

                    existingPost.Comments.Add(comment);
                    _commentStore.AddComment(comment);
                    if (existingPost.UserId != CurrentUser.Id)
                    {
                        var Notification = new Notification()
                        {
                            Message           = $"{CurrentUser.UserName} has commented on your post '{existingPost.Content}' ",
                            NotificationBoxId = _notificationBox.GetNotificationBoxByUserId(existingPost.UserId).Id,
                            RecieverUsername  = _userStore.GetByIdentityUserId(existingPost.UserId).Username,
                            NotificationDate  = DateTime.Now
                        };
                        _notificationBox.SendNotifcation(Notification);
                    }

                    _context.SaveChanges();
                    return(RedirectToAction("ViewPost", "Posts", new { id = existingPost.Id }));
                }
                else
                {
                    return(View(addCommentDTO));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(RedirectToAction(ActionName.ServerError, ControllerName.Accounts));
            }
        }
        public async Task <IActionResult> AddComment([FromBody] AddCommentDTO commentDto)
        {
            User user = await GetCurrentUserAsync();

            commentDto.UserId = user.Id;
            var comment = await _commentService.AddComment(commentDto);

            if (commentDto != null)
            {
                return(CreatedAtRoute("GetEventById", new { id = comment.Id }, comment));
            }

            return(BadRequest());
        }
Example #9
0
        public async Task <IActionResult> AddComment(AddCommentDTO addCommentDto)
        {
            var commnetDB = await _repo.AddComment(addCommentDto);

            if (commnetDB == null)
            {
                return(BadRequest());
            }

            var commentToReturn = _mapper.Map <CommentToReturnDTO>(commnetDB);


            return(Ok(commentToReturn));
        }
        public async Task <PostComment> AddCommentAsync(AddCommentDTO item)
        {
            List <string> parents = new List <string>();

            if (!string.IsNullOrWhiteSpace(item.ParentId))
            {
                var parentComment = await GetCommentAsync(item.ParentId);

                parents = parentComment.Parents.ToList();
                parents.Add(parentComment.Id);
            }

            var postComment = new PostComment {
                PostedDate = item.PostedDate, Content = item.Content, PostId = item.PostId, Author = item.Author, Parents = parents
            };

            await _context.PostComments.InsertOneAsync(postComment);

            return(postComment);
        }
Example #11
0
        public async Task <CommentDTO> AddCommentAsync(AddCommentDTO comment)
        {
            var Film = _unitOfWork.Films.Get(comment.FilmId);

            if (Film == null)
            {
                throw new FilmNotExistsException("Film not exists!")
                      {
                          FilmId = comment.FilmId
                      }
            }
            ;

            var user = _unitOfWork.Users.Get(comment.UserId);

            if (user == null)
            {
                throw new UserNotExistsException("User not exists!")
                      {
                          Id = comment.UserId
                      }
            }
            ;

            var commentEntity = new Comment()
            {
                Likes   = 0,
                Disikes = 0,
                Text    = comment.Text,
                Date    = DateTime.Now,
                Film    = Film,
                User    = user
            };
            var addedComment = _unitOfWork.Comments.Add(commentEntity);
            await _unitOfWork.SaveAsync();

            return(Mapper.Map <Comment, CommentDTO>(addedComment));
        }
Example #12
0
 public Task AddCommentToRenterer([FromBody] AddCommentDTO addCommentDto)
 {
     return(_renteeService.AddCommentToRenterer(addCommentDto.Comment, addCommentDto.Username, addCommentDto.UsernameRentee));
 }
Example #13
0
        public async Task <CommentDTO> AddComment(AddCommentDTO comment)
        {
            var commentResult = _mapper.Map <CommentDTO>(await _commentRepository.AddComment(_mapper.Map <Comment>(comment)));

            return(commentResult);
        }