Got most of admin panel working. Data issues fixed
This commit is contained in:
@@ -6,11 +6,11 @@ namespace OpenArchival.DataAccess;
|
||||
|
||||
public class ArtifactGroupingProvider : IArtifactGroupingProvider
|
||||
{
|
||||
private readonly ArchiveDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly ILogger<ArtifactGroupingProvider> _logger;
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public ArtifactGroupingProvider(ArchiveDbContext context, ILogger<ArtifactGroupingProvider> logger)
|
||||
public ArtifactGroupingProvider(ApplicationDbContext context, ILogger<ArtifactGroupingProvider> logger)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
@@ -18,12 +18,18 @@ public class ArtifactGroupingProvider : IArtifactGroupingProvider
|
||||
|
||||
public async Task<ArtifactGrouping?> GetGroupingAsync(int id)
|
||||
{
|
||||
return await _context.ArtifactGroupings.Where(g => g.Id == id).FirstOrDefaultAsync();
|
||||
return await _context.ArtifactGroupings
|
||||
.Where(g => g.Id == id)
|
||||
.Include(g => g.Category)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<ArtifactGrouping?> GetGroupingAsync(string artifactGroupingIdentifier)
|
||||
{
|
||||
return await _context.ArtifactGroupings.Where(g => g.ArtifactGroupingIdentifier == artifactGroupingIdentifier).FirstOrDefaultAsync();
|
||||
return await _context.ArtifactGroupings
|
||||
.Where(g => g.ArtifactGroupingIdentifier == artifactGroupingIdentifier)
|
||||
.Include(g => g.Category)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task CreateGroupingAsync(ArtifactGrouping grouping)
|
||||
@@ -38,9 +44,37 @@ public class ArtifactGroupingProvider : IArtifactGroupingProvider
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteGroupingAsync(int id)
|
||||
{
|
||||
await _context.ArtifactGroupings
|
||||
.Where(p => p.Id == id)
|
||||
.ExecuteDeleteAsync();
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteGroupingAsync(ArtifactGrouping grouping)
|
||||
{
|
||||
_context.ArtifactGroupings.Remove(grouping);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ArtifactGrouping>> GetGroupingsPaged(int pageNumber, int resultsCount)
|
||||
{
|
||||
if (pageNumber < 1 || resultsCount < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException($"Either page number or number of results was less than or equal to 0. {nameof(pageNumber)}={pageNumber} {nameof(resultsCount)}={resultsCount}");
|
||||
}
|
||||
|
||||
var totalCount = await _context.ArtifactGroupings.CountAsync();
|
||||
|
||||
var items = await _context.ArtifactGroupings
|
||||
.Include(g => g.Category)
|
||||
.OrderBy(g => g.Id)
|
||||
.Skip((pageNumber - 1) * resultsCount)
|
||||
.Take(resultsCount)
|
||||
.ToListAsync();
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user