
* Added way more logging for debugging issue #163. Fixed #175 * Removed some comment that isn't needed * Fixed a enumeration issue due to removing while enumerating
32 lines
No EOL
1,008 B
C#
32 lines
No EOL
1,008 B
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using API.Interfaces;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace API.Data
|
|
{
|
|
public class AppUserProgressRepository : IAppUserProgressRepository
|
|
{
|
|
private readonly DataContext _context;
|
|
|
|
public AppUserProgressRepository(DataContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
/// <summary>
|
|
/// This will remove any entries that have chapterIds that no longer exists. This will execute the save as well.
|
|
/// </summary>
|
|
public async Task<int> CleanupAbandonedChapters()
|
|
{
|
|
var chapterIds = _context.Chapter.Select(c => c.Id);
|
|
|
|
var rowsToRemove = await _context.AppUserProgresses
|
|
.Where(progress => !chapterIds.Contains(progress.ChapterId))
|
|
.ToListAsync();
|
|
|
|
_context.RemoveRange(rowsToRemove);
|
|
return await _context.SaveChangesAsync() > 0 ? rowsToRemove.Count : 0;
|
|
}
|
|
}
|
|
} |