예제 #1
0
        public async Task ModeratorRejectedJoin(ModeratorRejected input)
        {
            var isExist = await _communityUserRepository.GetAll()
                          .Where(x => x.Community.Slug == input.Slug && x.User.Username == input.Username && x.IsDeleted == false)
                          .FirstOrDefaultAsync();

            if (isExist == null)
            {
                throw new Exception("this relation don`t exist");
            }

            var community = await _communityRepository.GetAll()
                            .FirstOrDefaultAsync(x => x.Slug == input.Slug && !x.IsDeleted);

            var user = await _userRepository.GetAll().FirstOrDefaultAsync(x => x.Username == input.Username);

            isExist.IsDeleted = true;
            await _communityUserRepository.UpdateAsync(isExist);

            var model = new ModeratorOperation
            {
                Operation   = "USER_REJECTED",
                CommunityId = community.Id,
                ModeratorId = input.ModeratorId,
                UserId      = user.Id
            };
            await _moderatorOperationRepository.AddAsync(model);
        }
예제 #2
0
        public async Task <IActionResult> ModeratorDelete(Guid id)
        {
            var token = GetToken();

            if (!String.IsNullOrEmpty(token))
            {
                var userId = LoginHelper.GetClaim(token, "UserId");
                var reply  = await _replyRepository.GetByIdAsync(id);

                var comment = await _commentRepository.GetByIdAsync(reply.CommentId);

                var post = await _postRepository.GetByIdAsync(comment.PostId);

                var user = await _communityUserRepository.GetAll()
                           .FirstOrDefaultAsync(x =>
                                                x.IsAdmin && !x.IsDeleted && x.CommunityId == post.CommunityId &&
                                                x.UserId == Guid.Parse(userId));

                if (user == null)
                {
                    return(Unauthorized());
                }

                await _replyAppService.Delete(id);

                var operation = new ModeratorOperation
                {
                    CommunityId = post.CommunityId,
                    ModeratorId = Guid.Parse(userId),
                    PostId      = post.Id,
                    UserId      = post.UserId,
                    Operation   = "REPLY_DELETED"
                };
                await _operationRepository.AddAsync(operation);

                return(Ok(new { success = true }));
            }

            return(Unauthorized());
        }
예제 #3
0
        public async Task DeleteModerator(ModeratorDeleteDto input)
        {
            var isModerator = await _communityUserRepository.GetAll()
                              .FirstOrDefaultAsync(x =>
                                                   x.IsDeleted == false && x.IsAdmin && x.UserId == input.ModeratorId &&
                                                   x.Community.Slug == input.Slug);

            if (isModerator == null)
            {
                throw new Exception("Bu kullanicinin yetkisi yok");
            }
            ;

            var post = await _postRepository.GetAll()
                       .FirstOrDefaultAsync(x => x.IsDeleted == false && x.Id == input.PostId);

            if (post == null)
            {
                throw new Exception("Post bulunamadi");
            }


            post.IsDeleted = true;
            await _postRepository.UpdateAsync(post);

            var com = await _communityRepository.GetAll().FirstOrDefaultAsync(x => x.Slug == input.Slug);

            var model = new ModeratorOperation
            {
                Operation   = "POST_DELETED",
                ModeratorId = input.ModeratorId,
                CommunityId = com.Id,
                PostId      = input.PostId
            };
            await _moderatorOperationRepository.AddAsync(model);
        }