40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
|
|
using System.Text.RegularExpressions;
|
|
using Microsoft.AspNetCore.Http.Extensions;
|
|
|
|
namespace RhSolutions.Api.Services
|
|
{
|
|
public class CouplingModifier : IProductQueryModifier
|
|
{
|
|
private string pattern { get; } = @"([\b\D]|^)?(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)?";
|
|
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].Groups["Diameter"].Value == matches[1].Groups["Diameter"].Value)
|
|
{
|
|
qb.Add("query", $"Муфта соединительная равнопроходная {matches[0].Groups["Diameter"].Value}");
|
|
}
|
|
else
|
|
{
|
|
qb.Add("query", $"Муфта соединительная переходная {matches[0].Groups["Diameter"].Value}-{matches[1].Groups["Diameter"].Value}");
|
|
}
|
|
queryString = qb.ToQueryString();
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|