private async Task ProcessMovieRequests(DateTime date) { var requestsToDelete = await _movieRequests.GetAll().Where(x => x.Available && x.MarkedAsAvailable.HasValue && x.MarkedAsAvailable.Value < date).ToListAsync(); _logger.LogInformation($"Deleting {requestsToDelete.Count} movie requests that have now been scheduled for deletion, All available requests before {date::MM/dd/yyyy} will be deleted"); foreach (var r in requestsToDelete) { _logger.LogInformation($"Deleting movie title {r.Title} as it was approved on {r.MarkedAsApproved:MM/dd/yyyy hh:mm tt}"); } await _movieRequests.DeleteRange(requestsToDelete); }
public async Task <IdentityResult> DeleteUser(OmbiUser userToDelete) { var userId = userToDelete.Id; // We need to delete all the requests first var moviesUserRequested = _movieRepository.GetAll().Where(x => x.RequestedUserId == userId); var tvUserRequested = _tvRepository.GetChild().Where(x => x.RequestedUserId == userId); var musicRequested = _musicRepository.GetAll().Where(x => x.RequestedUserId == userId); var notificationPreferences = _userNotificationPreferences.GetAll().Where(x => x.UserId == userId); var userQuality = await _userQualityProfiles.GetAll().FirstOrDefaultAsync(x => x.UserId == userId); if (moviesUserRequested.Any()) { await _movieRepository.DeleteRange(moviesUserRequested); } if (tvUserRequested.Any()) { await _tvRepository.DeleteChildRange(tvUserRequested); } if (musicRequested.Any()) { await _musicRepository.DeleteRange(musicRequested); } if (notificationPreferences.Any()) { await _userNotificationPreferences.DeleteRange(notificationPreferences); } if (userQuality != null) { await _userQualityProfiles.Delete(userQuality); } // Delete any issues and request logs var issues = _issuesRepository.GetAll().Where(x => x.UserReportedId == userId); var issueComments = _issueCommentsRepository.GetAll().Where(x => x.UserId == userId); var requestLog = _requestLogRepository.GetAll().Where(x => x.UserId == userId); if (issueComments.Any()) { await _issueCommentsRepository.DeleteRange(issueComments); } if (issues.Any()) { var extraComments = new List <IssueComments>(); var issueIds = issues.Select(x => x.Id).Distinct(); foreach (var issue in issueIds) { // Get all the comments for this issue and delete them, since the issue will be deleted var extra = _issueCommentsRepository.GetAll().Where(x => x.IssuesId == issue); extraComments.AddRange(extra.ToList()); } await _issuesRepository.DeleteRange(issues); } if (requestLog.Any()) { await _requestLogRepository.DeleteRange(requestLog); } // Delete the Subscriptions and mobile notification ids var subs = _requestSubscriptionRepository.GetAll().Where(x => x.UserId == userId); var mobileIds = _notificationRepository.GetAll().Where(x => x.UserId == userId); var votes = _voteRepository.GetAll().Where(x => x.UserId == userId); var newMobiles = _mobileDevicesRepository.GetAll().Where(x => x.UserId == userId); if (subs.Any()) { await _requestSubscriptionRepository.DeleteRange(subs); } if (mobileIds.Any()) { await _notificationRepository.DeleteRange(mobileIds); } if (votes.Any()) { await _voteRepository.DeleteRange(votes); } if (newMobiles.Any()) { await _mobileDevicesRepository.DeleteRange(newMobiles); } var result = await _userManager.DeleteAsync(userToDelete); return(result); }