예제 #1
0
 public HomeController(IPostRepository repo, IFileManager fileManager, ICommentRepository commentRepository)
 {
     _repo              = repo;
     _fileMager         = fileManager;
     _commentRepository = commentRepository;
     var _comment = new MainComment();
 }
예제 #2
0
        public async Task <JsonResult> AddMainComment(GameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(false));
            }

            var game = await _db.Games
                       .FirstOrDefaultAsync(item => item.Id == model.Game.Id);

            if (game == null)
            {
                return(Json(false));
            }

            var user    = _userManager.GetUserAsync(HttpContext.User);
            var isAdmin = User.IsInRole("Admin");

            var mainComment = new MainComment
            {
                Message     = model.MainComment.Message,
                TimeCreated = DateTime.Now,
                Game        = game,
                IsAdmin     = isAdmin,
                User        = user.Result,
            };

            await _db.MainComments.AddAsync(mainComment);

            await _db.SaveChangesAsync();

            return(Json(true));
        }
예제 #3
0
        public void YorumSil(int id)
        {
            MainComment temp = _appDbContext.MainComments.FirstOrDefault(i => i.Id == id);

            _appDbContext.MainComments.Remove(temp);
            _appDbContext.SaveChanges();
        }
예제 #4
0
        public async Task <PostCommentDto> CreateAndReturnMainCommentAsync(NewCommentDto
                                                                           commentDto, int authorId, IFormFile file)
        {
            string imagePath;

            if (file != null)
            {
                imagePath = await _imageSaver
                            .SaveAndReturnImagePath(file, "Comment",
                                                    commentDto.PostId);
            }
            var newComment = new MainComment
            {
                Comment = new Models.Comment()
                {
                    PostId  = commentDto.PostId,
                    Content = commentDto.Content,
                    Date    = DateTime.Now,
                    UserId  = authorId
                }
            };

            _repository.MainComment.CreateMainComment(newComment);
            await _repository.SaveAsync();

            var createdComment = _repository.MainComment.FindById(newComment.Id,
                                                                  PostCommentDto.Selector(authorId));

            return(createdComment);
        }
        public List <ClientPost> GetMyPosts(string userId)
        {
            List <Post>       posts         = _graphDB.GetMyPosts(userId);
            List <ClientPost> postsToClient = new List <ClientPost>();

            foreach (var post in posts)
            {
                ClientPost         clientPost   = new ClientPost(post);
                List <Comment>     postComments = _graphDB.GetCommentsForPost(post.PostID);
                List <MainComment> mainComments = new List <MainComment>();
                foreach (var comment in postComments)
                {
                    MainComment mainComment = new MainComment
                    {
                        Comment      = comment,
                        CommentOwner = _graphDB.GetCommentOwner(comment.CommentID),
                        IsLike       = _graphDB.IsUserLikeComment(userId, comment.CommentID)
                    };

                    mainComments.Add(mainComment);
                    //comment.UsersLike = _graphDB.GetLikesForComment(comment.CommentID);
                }
                clientPost.Comments  = mainComments;
                clientPost.PostOwner = _graphDB.GetPostOwner(post.PostID);
                clientPost.IsLike    = _graphDB.IsUserLikePost(userId, post.PostID);

                List <User> usersLike = _graphDB.GetLikesForPost(post.PostID);
                clientPost.UsersLikes = _graphDB.GetLikesForPost(post.PostID);
                clientPost.LikeCount  = usersLike.Count;
                postsToClient.Add(clientPost);
            }
            return(postsToClient);
        }
        public virtual async Task <MainComment> UpdateMainCommentAsync(MainComment mainComment)
        {
            Preconditions.NotNull(mainComment, nameof(mainComment));

            _context.MainComments.Update(mainComment);

            await SaveChangesAsync();

            return(mainComment);
        }
예제 #7
0
        public void Edit()
        {
            var comment = new MainComment
            {
                Id      = this.Id,
                Message = this.Message,
                Status  = this.Status
            };

            _mainCommentService.EditComment(comment);
        }
예제 #8
0
        public void MCCreate()
        {
            var mainComment = new MainComment
            {
                Message = this.Message,
                Created = this.Created,
                BlogId  = this.BlogsId
            };

            _commentService.CreateMC(mainComment);
        }
        public virtual async Task <MainComment> InsertMainCommentAsync(MainComment mainComment)
        {
            Preconditions.NotNull(mainComment, nameof(mainComment));

            await BlogMustExist(mainComment.BlogID);
            await ApplicationUserMustExist(mainComment.ApplicationUserID);

            await _context.MainComments.AddAsync(mainComment);

            await SaveChangesAsync();

            return(mainComment);
        }
예제 #10
0
        public async Task <IActionResult> ApproveMainComment(int id)
        {
            logger.LogInformation("MainComment approval");
            MainComment mainCommentItem = _context.MainComments.Where(mcI => mcI.ID == id).FirstOrDefault();

            if (mainCommentItem != null)
            {
                mainCommentItem.Approved = true;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(CommentsShow)));
            }
            else
            {
                return(NotFound());
            }
        }
예제 #11
0
        public async Task <IActionResult> Comment(CommentsViewModel cvm)
        {
            bool approve     = false;
            User currentUser = await iSecure.GetCurrentUser(User);

            if (User.IsInRole(nameof(Roles.Admin)) || User.IsInRole(nameof(Roles.Manager)))
            {
                approve = true;
            }
            if (cvm.MainCommentId == 0)
            {
                MainComment commentItem = new MainComment()
                {
                    CommentMessage = cvm.Message,
                    UserId         = currentUser.Id,
                    ProductId      = cvm.ProductId,
                    Approved       = approve
                };

                EshopDBContext.Add(commentItem);

                await EshopDBContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Detail), new { id = commentItem.ProductId }));
            }
            else
            {
                SubComment commentItem = new SubComment()
                {
                    MainCommentId  = cvm.MainCommentId,
                    CommentMessage = cvm.Message,
                    UserId         = currentUser.Id,
                    Approved       = approve
                };
                EshopDBContext.Add(commentItem);
                await EshopDBContext.SaveChangesAsync();

                commentItem.MainComment = EshopDBContext.MainComments.Where(c => c.ID == commentItem.MainCommentId).FirstOrDefault();
                return(RedirectToAction(nameof(Detail), new { id = commentItem.MainComment.ProductId }));
            }
        }
예제 #12
0
        public async Task <Unit> Handle(CreateMainCommentCommand request, CancellationToken cancellationToken)
        {
            var userClaims = _userAccessor.GetUser();

            var userId = Guid.Parse(userClaims.FindFirst(ClaimTypes.NameIdentifier).Value);

            var user = await _context.ApplicationUsers.FirstAsync(x => x.Id == userId, cancellationToken);

            var comment = new MainComment(request.RecordId, user, request.Message);

            _context.MainComments.Add(comment);

            await _context.SaveChangesAsync(cancellationToken);


            // ----------------
            // Send email to mentioned users
            var emails = request.Message.FindEmails();

            if (emails.Count == 0)
            {
                return(Unit.Value);
            }

            var notification = new SendCommentEmail()
            {
                PrimaryEntityId = comment.RecordId,
                UserName        = comment.AuthorName,
                Recipients      = emails,
                AuthorName      = comment.AuthorName,
                Message         = comment.Message
            };

            await _mediator.Publish(notification);

            return(Unit.Value);
        }
예제 #13
0
 public static MainCommentLookupModel Create(MainComment comment)
 {
     return(Projection.Compile().Invoke(comment));
 }
예제 #14
0
 /// <summary>
 /// This is the constructor of repository
 /// </summary>
 public HomeController(IRepository repository)
 {
     _repository = repository;
     var comment = new MainComment();
 }