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);
        }
Beispiel #2
0
        public async Task <IActionResult> ModeratorRejectedJoin(ModeratorRejected input)
        {
            var token = GetToken();

            if (!String.IsNullOrEmpty(token))
            {
                var loggedUserId = LoginHelper.GetClaim(token, "UserId");
                input.ModeratorId = Guid.Parse(loggedUserId);
            }

            var isAdmin = await _communityUserRepository.GetAll()
                          .FirstOrDefaultAsync(x =>
                                               x.IsDeleted == false && x.IsAdmin && x.UserId == input.ModeratorId && x.Community.Slug == input.Slug);

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

            await _userService.ModeratorRejectedJoin(input);

            return(Ok());
        }