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

49 lines
1.7 KiB
C#

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