LANCommander/LANCommander.Server.Services/ActionService.cs
2026-07-02 20:01:04 -05:00

51 lines
1.8 KiB
C#

using AutoMapper;
using LANCommander.Server.Data;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using ZiggyCreatures.Caching.Fusion;
using LANCommander.Server.Services.Extensions;
using Action = LANCommander.Server.Data.Models.Action;
namespace LANCommander.Server.Services
{
public sealed class ActionService(
ILogger<ActionService> logger,
SettingsProvider<Settings.Settings> settingsProvider,
IFusionCache cache,
IMapper mapper,
IHttpContextAccessor httpContextAccessor,
IDbContextFactory<DatabaseContext> contextFactory) : BaseDatabaseService<Action>(logger, settingsProvider, cache, mapper, httpContextAccessor, contextFactory)
{
public override async Task<Action> AddAsync(Action entity)
{
await cache.ExpireGameCacheAsync();
return await base.AddAsync(entity, async context =>
{
await context.UpdateRelationshipAsync(a => a.Game);
await context.UpdateRelationshipAsync(a => a.Server);
await context.UpdateRelationshipAsync(a => a.Tool);
});
}
public async override Task<Action> UpdateAsync(Action entity)
{
await cache.ExpireGameCacheAsync();
return await base.UpdateAsync(entity, async context =>
{
await context.UpdateRelationshipAsync(a => a.Game);
await context.UpdateRelationshipAsync(a => a.Server);
await context.UpdateRelationshipAsync(a => a.Tool);
});
}
public override async Task DeleteAsync(Action entity)
{
await cache.ExpireGameCacheAsync();
await base.DeleteAsync(entity);
}
}
}