PlotDirector/PlotLine/Data/NameManuscriptRepository.cs

20 lines
1.2 KiB
C#

using System.Data;
using Dapper;
using PlotLine.Models;
using PlotLine.Services;
namespace PlotLine.Data;
public interface INameManuscriptRepository
{
Task<NameManuscriptScope> Scope(int user,int project);
Task<NameTextSearch> Search(int user,int project,string name);
}
public sealed class NameManuscriptRepository(ISqlConnectionFactory factory):INameManuscriptRepository
{
public async Task<NameManuscriptScope> Scope(int user,int project){using var db=factory.CreateConnection();return await db.QuerySingleAsync<NameManuscriptScope>("dbo.NameManuscript_Search",new{UserID=user,ProjectID=project},commandType:CommandType.StoredProcedure);}
public async Task<NameTextSearch> Search(int user,int project,string name)
{
using var db=factory.CreateConnection();using var rows=await db.QueryMultipleAsync("dbo.NameManuscript_Search",new{UserID=user,ProjectID=project,Name=NameTextMatcher.Prefilter(name),Take=NameTextMatcher.MaximumParagraphs},commandType:CommandType.StoredProcedure);
var scope=await rows.ReadSingleAsync<NameManuscriptScope>();var paragraphs=(await rows.ReadAsync<NameCandidateParagraph>()).ToList();return NameTextMatcher.Match(name,scope,paragraphs);
}
}