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

43 lines
1.3 KiB
C#
Raw Normal View History

2023-09-19 14:56:55 +03:00
using Microsoft.AspNetCore.Http.Extensions;
using System.Text;
using System.Text.RegularExpressions;
namespace RhSolutions.Api.Services
{
public class TPieceQueryModifier : IProductQueryModifier
{
2023-09-29 10:22:38 +03:00
private readonly string pattern = @"16|20|25|32|40|50|63";
2023-09-19 14:56:55 +03:00
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("Тройник RAUTITAN -PLATINUM");
if (matches.Count == 1)
{
sb.Append($" {matches.First().Value}-{matches.First().Value}-{matches.First().Value}");
}
else if (matches.Count >= 3)
{
sb.Append($" {matches[0].Value}-{matches[1].Value}-{matches[2].Value}");
}
else
{
return false;
}
QueryBuilder qb = new()
{
{ "query", sb.ToString() }
};
queryString = qb.ToQueryString();
return true;
}
}
}