public async Task <IActionResult> ModeratorDelete(ModeratorDeleteDto 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 _postAppService.DeleteModerator(input); return(Ok()); }
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); }