37 lines
969 B
C#
37 lines
969 B
C#
|
|
||
|
using System.Text.RegularExpressions;
|
||
|
using Microsoft.AspNetCore.Http.Extensions;
|
||
|
|
||
|
namespace RhSolutions.Api.Services
|
||
|
{
|
||
|
public class ElbowModifier : IProductQueryModifier
|
||
|
{
|
||
|
private string diameterPattern { get; } = @"\b(16|20|25|32|40|50|63)\b";
|
||
|
private string anglePattern { get; } = @"\b(45|90)";
|
||
|
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
||
|
{
|
||
|
queryString = QueryString.Empty;
|
||
|
var query = collection["query"].ToString();
|
||
|
if (string.IsNullOrEmpty(query))
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
var diameter = Regex.Match(query, diameterPattern);
|
||
|
if (diameter.Success)
|
||
|
{
|
||
|
var angle = Regex.Match(query, anglePattern);
|
||
|
QueryBuilder qb = new()
|
||
|
{
|
||
|
{"query", $"Угольник RAUTITAN -PLATINUM {(angle.Success ? angle.Captures.First() : 90)} {diameter.Captures.First()}"}
|
||
|
};
|
||
|
queryString = qb.ToQueryString();
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|