40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
|
|
using System.Text.RegularExpressions;
|
|
using Microsoft.AspNetCore.Http.Extensions;
|
|
|
|
namespace RhSolutions.Api.Services
|
|
{
|
|
public class CouplingModifier : IProductQueryModifier
|
|
{
|
|
private string pattern { get; } = @"\b(16|20|25|32|40|50|63)\b";
|
|
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
|
{
|
|
queryString = QueryString.Empty;
|
|
var query = collection["query"].ToString();
|
|
if (string.IsNullOrEmpty(query))
|
|
{
|
|
return false;
|
|
}
|
|
var matches = Regex.Matches(query, pattern);
|
|
if (matches.Count < 1)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
QueryBuilder qb = new();
|
|
if (matches.Count < 2 || matches.Count > 1 && matches[0].Value == matches[1].Value)
|
|
{
|
|
qb.Add("query", $"Муфта соединительная равнопроходная {matches[0]}");
|
|
}
|
|
else
|
|
{
|
|
qb.Add("query", $"Муфта соединительная переходная {matches[0]}-{matches[1]}");
|
|
}
|
|
queryString = qb.ToQueryString();
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|