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

39 lines
1.0 KiB
C#
Raw Normal View History

2023-10-10 22:26:16 +03:00
using System.Text.RegularExpressions;
using System.Text;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Http;
namespace RhSolutions.QueryModifiers;
public class SleeveQueryModifier : IProductQueryModifier
{
private readonly string pattern = @"\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);
StringBuilder sb = new();
sb.Append("Монтажная гильза ");
if (matches.Count > 0)
{
sb.Append(matches.First());
}
else
{
return false;
}
QueryBuilder qb = new()
{
{"query", sb.ToString() }
};
queryString = qb.ToQueryString();
return true;
}
}