MapEdgeRepository.cs 1.93 KB
using Microsoft.EntityFrameworkCore;
using Rcs.Domain.Entities;
using Rcs.Domain.Repositories;
using Rcs.Infrastructure.DB.MsSql;

namespace Rcs.Infrastructure.DB.Repositories
{
    /// <summary>
    /// 地图资源仓储实现
    /// </summary>
    public class MapEdgeRepository : Repository<MapEdge>, IMapEdgeRepository
    {
        public MapEdgeRepository(AppDbContext context) : base(context)
        {
        }


        public async Task<IEnumerable<MapEdge>> GetByMapIdAsync(Guid mapId, CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(r => r.MapId == mapId && r.Active)
                .ToListAsync(cancellationToken);
        }

        public async Task<MapEdge?> GetByMapIdAndEdgeCodeAsync(Guid mapId, string edgeCode, CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(r => r.MapId == mapId && r.Active)
                .Where(e => e.EdgeCode == edgeCode)
                .FirstOrDefaultAsync(cancellationToken);
        }

        public async Task<IEnumerable<MapEdge>> GetByFromNodeAsync(Guid fromNode, CancellationToken cancellationToken = default)
        {
            return  await _dbSet
                .Where(e => e.FromNode == fromNode)
                .ToListAsync(cancellationToken);
        }

        public async Task<IEnumerable<MapEdge>> GetByToNodeAsync(Guid toNode, CancellationToken cancellationToken = default)
        {
            return  await _dbSet
                .Where(e => e.ToNode == toNode)
                .ToListAsync(cancellationToken);
        }

        public async Task<IEnumerable<MapEdge>> GetByFromAndToNodeAsync(Guid fromNode, Guid toNode, CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(e => e.FromNode == fromNode)
                .Where(e => e.ToNode == toNode)
                .ToListAsync(cancellationToken);
        }
    }
}