0
0
RhSolutions-Api/RhSolutions.Api/Services/CouplingModifier.cs

40 lines
1.0 KiB
C#
Raw Normal View History

2023-10-01 22:14:47 +03:00
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.Api.Services
{
2023-10-01 22:36:14 +03:00
public class CouplingModifier : IProductQueryModifier
2023-10-01 22:14:47 +03:00
{
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();
2023-10-01 22:36:14 +03:00
if (matches.Count < 2 || matches.Count > 1 && matches[0].Value == matches[1].Value)
2023-10-01 22:14:47 +03:00
{
qb.Add("query", $"Муфта соединительная равнопроходная {matches[0]}");
}
else
{
qb.Add("query", $"Муфта соединительная переходная {matches[0]}-{matches[1]}");
}
queryString = qb.ToQueryString();
return true;
}
}
}
}