0
0
RhSolutions-Api/RhSolutions.QueryModifiers/ElbowModifier.cs

37 lines
1003 B
C#
Raw Normal View History

2023-10-03 21:58:17 +03:00
using System.Text.RegularExpressions;
2023-10-10 22:26:16 +03:00
using Microsoft.AspNetCore.Http;
2023-10-03 21:58:17 +03:00
using Microsoft.AspNetCore.Http.Extensions;
2023-10-10 22:26:16 +03:00
namespace RhSolutions.QueryModifiers
2023-10-03 21:58:17 +03:00
{
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;
}
}
}
}