summaryrefslogtreecommitdiff
path: root/RhSolutions.QueryModifiers/TPieceQueryModifier.cs
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2023-10-10 22:26:16 +0300
committerSerghei Cebotari <serghei@cebotari.ru>2023-10-10 22:26:16 +0300
commit6b9c0dfffc3ecfcfb642f696250aee8e4ed6031b (patch)
tree2d98f14ab3c194f6e5620fa375c4fd805c6b957e /RhSolutions.QueryModifiers/TPieceQueryModifier.cs
parent942c60beeac8b89643dc66235db62d4c8f739a0a (diff)
Move Modifiers to own project
Diffstat (limited to 'RhSolutions.QueryModifiers/TPieceQueryModifier.cs')
-rw-r--r--RhSolutions.QueryModifiers/TPieceQueryModifier.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/RhSolutions.QueryModifiers/TPieceQueryModifier.cs b/RhSolutions.QueryModifiers/TPieceQueryModifier.cs
new file mode 100644
index 0000000..87c5b61
--- /dev/null
+++ b/RhSolutions.QueryModifiers/TPieceQueryModifier.cs
@@ -0,0 +1,42 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace RhSolutions.QueryModifiers;
+
+public class TPieceQueryModifier : IProductQueryModifier
+{
+ private readonly string pattern = @"16|20|25|32|40|50|63";
+
+ 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;
+ }
+}