66 lines
2.5 KiB
C#
66 lines
2.5 KiB
C#
using LANCommander.Server.Data;
|
|
using LANCommander.Server.Data.Models;
|
|
using LANCommander.Server.Services.Extensions;
|
|
using AutoMapper;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using ZiggyCreatures.Caching.Fusion;
|
|
|
|
namespace LANCommander.Server.Services
|
|
{
|
|
public sealed class RedistributableService(
|
|
ILogger<SDK.Services.RedistributableService> logger,
|
|
IFusionCache cache,
|
|
IMapper mapper,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
IDbContextFactory<DatabaseContext> contextFactory) : BaseDatabaseService<Redistributable>(logger, cache, mapper, httpContextAccessor, contextFactory)
|
|
{
|
|
public override async Task<Redistributable> AddAsync(Redistributable entity)
|
|
{
|
|
await cache.ExpireGameCacheAsync();
|
|
|
|
return await base.AddAsync(entity, async context =>
|
|
{
|
|
await context.UpdateRelationshipAsync(r => r.Archives);
|
|
await context.UpdateRelationshipAsync(r => r.Games);
|
|
await context.UpdateRelationshipAsync(r => r.Pages);
|
|
await context.UpdateRelationshipAsync(r => r.Scripts);
|
|
});
|
|
}
|
|
|
|
public override async Task<Redistributable> UpdateAsync(Redistributable entity)
|
|
{
|
|
if (entity.Games != null && entity.Games.Any())
|
|
{
|
|
foreach (var game in entity.Games)
|
|
{
|
|
await cache.ExpireGameCacheAsync(game?.Id);
|
|
}
|
|
}
|
|
|
|
return await base.UpdateAsync(entity, async context =>
|
|
{
|
|
await context.UpdateRelationshipAsync(r => r.Archives);
|
|
await context.UpdateRelationshipAsync(r => r.Games);
|
|
await context.UpdateRelationshipAsync(r => r.Pages);
|
|
await context.UpdateRelationshipAsync(r => r.Scripts);
|
|
});
|
|
}
|
|
|
|
public async Task<SDK.Models.Manifest.Redistributable> GetManifestAsync(Guid manifestId)
|
|
{
|
|
var redistributable = await AsNoTracking()
|
|
.AsSplitQuery()
|
|
.Query(q =>
|
|
{
|
|
return q
|
|
.Include(r => r.Archives)
|
|
.Include(r => r.Scripts);
|
|
})
|
|
.GetAsync<SDK.Models.Manifest.Redistributable>(manifestId);
|
|
|
|
return redistributable;
|
|
}
|
|
}
|
|
}
|