Exemplo n.º 1
0
        // post Id ye göre tüm yorumları getirme
        public List <CommentRowVM> GetAllByPostId(int postId)
        {
            var httpUser = _httpContextAccessor.HttpContext.User;

            List <int> blockedUserIds = new List <int>();
            var        Comments       = new List <CommentRowVM>();
            //Todo: Mesela _commentRepository.GetAll(x => x.PostId == postId).Include("User"); metodunda getall sonrasına include yazmak yerine include kısmını da getall metodu içerisinde yapman doğru olur. her yerde getall çağrısı yapacaksın ve muhtemelen çoğunda da bu yorumun kullanıcısına ulaşmak isteyeceksin. Bunu da ICommentRepository'e gidip örneğin GetAllWithUser metodu yazacaksın. içerisine de  GetAll(x => x.PostId == postId).Include("User"); kısmını uygulayacaksın. Altta da sadece getallwithuser çağrısı yaparsın.
            var commentEntities = _commentRepository.GetAll(x => x.PostId == postId).Include("User");

            if (httpUser.Identity.IsAuthenticated == true)
            {
                var blockedUsers = _blockedUserService.GetBlockedUsers();

                foreach (var item in blockedUsers)
                {
                    blockedUserIds.Add(item.BlockedUserId);
                }
                commentEntities = commentEntities.Where(x => !blockedUserIds.Contains(x.UserId));
            }

            foreach (var item in commentEntities)
            {
                var result = new CommentRowVM();
                result.Text        = item.Text;
                result.UserId      = item.UserId;
                result.CommentDate = item.UpdateDate ?? item.CreateDate;
                result.UserName    = item.User.UserName;
                Comments.Add(result);
            }

            return(Comments);
        }
Exemplo n.º 2
0
        //Engelli Kullanıcıları çekme
        public IActionResult GetBlockedUsers()
        {
            var blockedUsers = _blockedUserService.GetBlockedUsers();

            return(View(blockedUsers));
        }