PalacePal/Pal.Client/Floors/Tasks/MarkLocalSeen.cs

38 lines
1.4 KiB
C#
Raw Normal View History

2023-02-18 20:12:36 +00:00
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
2023-02-18 20:12:36 +00:00
using Pal.Client.Database;
namespace Pal.Client.Floors.Tasks
{
internal sealed class MarkLocalSeen : DbTask<MarkLocalSeen>
2023-02-18 20:12:36 +00:00
{
private readonly MemoryTerritory _territory;
private readonly IReadOnlyList<PersistentLocation> _locations;
public MarkLocalSeen(IServiceScopeFactory serviceScopeFactory, MemoryTerritory territory,
2023-02-18 20:12:36 +00:00
IReadOnlyList<PersistentLocation> locations)
: base(serviceScopeFactory)
{
_territory = territory;
_locations = locations;
}
protected override void Run(PalClientContext dbContext, ILogger<MarkLocalSeen> logger)
2023-02-18 20:12:36 +00:00
{
lock (_territory.LockObj)
{
logger.LogInformation("Marking {Count} locations as seen locally in territory {Territory}", _locations.Count,
_territory.TerritoryType);
2023-02-26 16:54:15 +00:00
List<int> localIds = _locations.Select(l => l.LocalId).Where(x => x != null).Cast<int>().ToList();
2023-02-18 20:12:36 +00:00
dbContext.Locations
2023-02-26 16:54:15 +00:00
.Where(loc => localIds.Contains(loc.LocalId))
2023-02-18 20:12:36 +00:00
.ExecuteUpdate(loc => loc.SetProperty(l => l.Seen, true));
dbContext.SaveChanges();
}
}
}
}