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

38 lines
1.3 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;
2023-03-30 20:01:43 +00:00
namespace Pal.Client.Floors.Tasks;
internal sealed class MarkLocalSeen : DbTask<MarkLocalSeen>
2023-02-18 20:12:36 +00:00
{
2023-03-30 20:01:43 +00:00
private readonly MemoryTerritory _territory;
private readonly IReadOnlyList<PersistentLocation> _locations;
2023-02-18 20:12:36 +00:00
2023-03-30 20:01:43 +00:00
public MarkLocalSeen(IServiceScopeFactory serviceScopeFactory, MemoryTerritory territory,
IReadOnlyList<PersistentLocation> locations)
: base(serviceScopeFactory)
{
_territory = territory;
_locations = locations;
}
2023-02-18 20:12:36 +00:00
2023-03-30 20:01:43 +00:00
protected override void Run(PalClientContext dbContext, ILogger<MarkLocalSeen> logger)
{
lock (_territory.LockObj)
2023-02-18 20:12:36 +00:00
{
2023-10-03 20:05:19 +00:00
logger.LogInformation("Marking {Count} locations as seen locally in territory {Territory}",
_locations.Count,
2023-03-30 20:01:43 +00:00
_territory.TerritoryType);
List<int> localIds = _locations.Select(l => l.LocalId).Where(x => x != null).Cast<int>().ToList();
dbContext.Locations
.Where(loc => localIds.Contains(loc.LocalId))
.ExecuteUpdate(loc => loc.SetProperty(l => l.Seen, true));
dbContext.SaveChanges();
2023-02-18 20:12:36 +00:00
}
}
}