summaryrefslogtreecommitdiff
path: root/RhSolutions.QueryModifiers/SleeveQueryModifier.cs
diff options
context:
space:
mode:
Diffstat (limited to 'RhSolutions.QueryModifiers/SleeveQueryModifier.cs')
-rw-r--r--RhSolutions.QueryModifiers/SleeveQueryModifier.cs38
1 files changed, 38 insertions, 0 deletions
diff --git a/RhSolutions.QueryModifiers/SleeveQueryModifier.cs b/RhSolutions.QueryModifiers/SleeveQueryModifier.cs
new file mode 100644
index 0000000..788a3a2
--- /dev/null
+++ b/RhSolutions.QueryModifiers/SleeveQueryModifier.cs
@@ -0,0 +1,38 @@
+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;
+ }
+}