diff options
author | Serghei Cebotari <serghei@cebotari.ru> | 2023-10-10 22:26:16 +0300 |
---|---|---|
committer | Serghei Cebotari <serghei@cebotari.ru> | 2023-10-10 22:26:16 +0300 |
commit | 6b9c0dfffc3ecfcfb642f696250aee8e4ed6031b (patch) | |
tree | 2d98f14ab3c194f6e5620fa375c4fd805c6b957e /RhSolutions.QueryModifiers/ThreadTPieceWall.cs | |
parent | 942c60beeac8b89643dc66235db62d4c8f739a0a (diff) |
Move Modifiers to own project
Diffstat (limited to 'RhSolutions.QueryModifiers/ThreadTPieceWall.cs')
-rw-r--r-- | RhSolutions.QueryModifiers/ThreadTPieceWall.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/RhSolutions.QueryModifiers/ThreadTPieceWall.cs b/RhSolutions.QueryModifiers/ThreadTPieceWall.cs new file mode 100644 index 0000000..8e11a91 --- /dev/null +++ b/RhSolutions.QueryModifiers/ThreadTPieceWall.cs @@ -0,0 +1,64 @@ +using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; + +namespace RhSolutions.QueryModifiers; + +public class ThreadTPieceInternal : IProductQueryModifier +{ + private string diameterPattern = "16|20|25|32|40|50|63"; + private string threadPattern = @"(\D|^)(?<Thread>1\s+1/4|1\s+1/2|1/2|3/4|2|1)(\D|$)"; + + public bool TryQueryModify(IQueryCollection collection, out QueryString queryString) + { + queryString = QueryString.Empty; + var query = collection["query"].ToString(); + if (string.IsNullOrEmpty(query)) + { + return false; + } + var diameters = Regex.Matches(query, diameterPattern); + if (diameters.Count == 0) + { + return false; + } + var thread = Regex.Match(query, threadPattern); + if (!thread.Success) + { + return false; + } + QueryBuilder qb = new() + { + {"query", ConstructName(diameters, thread)} + }; + queryString = qb.ToQueryString(); + return true; + } + + protected virtual string ConstructName(MatchCollection diameters, Match thread) + { + Capture t = thread.Groups["Thread"].Captures.First(); + if (diameters.Count == 1) + { + if (int.Parse(diameters[0].Value) < 25) + { + return $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{t}-{diameters[0]}"; + } + else + { + return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[0]}"; + } + } + else + { + if (int.Parse(diameters[0].Value) < 25) + { + return $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{t}-{diameters[1]}"; + } + else + { + return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[1]}"; + } + } + } +} |