diff options
Diffstat (limited to 'RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes')
5 files changed, 138 insertions, 0 deletions
diff --git a/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/BlackPipe.cs b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/BlackPipe.cs new file mode 100644 index 0000000..272568e --- /dev/null +++ b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/BlackPipe.cs @@ -0,0 +1,16 @@ +namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes; + +public class BlackPipe : DrinkingWaterHeatingPipe +{ + protected override string _title => "Black"; + protected override Dictionary<int, string> _diameterNames => new() + { + [16] = "162,2", + [20] = "202,8", + [25] = "253,5", + [32] = "324,4", + [40] = "405,5", + [50] = "506,9", + [63] = "638,6" + }; +} diff --git a/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs new file mode 100644 index 0000000..e7a18d6 --- /dev/null +++ b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs @@ -0,0 +1,77 @@ +using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; + +namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes; + +public class DrinkingWaterHeatingPipe : IProductQueryModifier +{ + protected static readonly Regex _diameter = + new(@"([\b\D]|^)?(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)"); + protected static readonly Regex _type = + new(@"([\b\W])(?<Type>бухт|отр|штанг)([\b\w.])"); + protected virtual string _title { get; } = string.Empty; + + protected virtual Dictionary<int, string> _diameterNames { get; } = new() + { + [16] = "16x2,2", + [20] = "20x2,8", + [25] = "25x3,5", + [32] = "32x4,4", + [40] = "40x5,5", + [50] = "50x6,9", + [63] = "63x8,6" + }; + + protected virtual Dictionary<string, string> _makeUp { get; } = new() + { + ["бухт"] = "бухта", + ["штанг"] = "прям.отрезки", + ["отр"] = "прям.отрезки" + }; + + public bool TryQueryModify(IQueryCollection collection, out QueryString queryString) + { + queryString = QueryString.Empty; + string query = collection["query"].ToString(); + if (string.IsNullOrEmpty(query)) + { + return false; + } + string? result = BuildRhSolutionsName(query); + if (result != null) + { + QueryBuilder qb = new() + { + { "query", result } + }; + queryString = qb.ToQueryString(); + return true; + } + return false; + } + + protected virtual string? BuildRhSolutionsName(string query) + { + var diameterMatch = _diameter.Match(query); + if (!diameterMatch.Success) + { + return null; + } + var diameter = int.Parse(diameterMatch.Groups["Diameter"].Value); + var typeMatch = _type.Match(query); + if (typeMatch.Success) + { + var type = typeMatch.Groups["Type"].Value; + return $"Труба {_title} {_diameterNames[diameter]} {_makeUp[type]}"; + } + else if (diameter < 32) + { + return $"Труба {_title} {_diameterNames[diameter]} {_makeUp["бухт"]}"; + } + else + { + return $"Труба {_title} {_diameterNames[diameter]} {_makeUp["отр"]}"; + } + } +} diff --git a/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/FlexPipe.cs b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/FlexPipe.cs new file mode 100644 index 0000000..4294a9a --- /dev/null +++ b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/FlexPipe.cs @@ -0,0 +1,6 @@ +namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes; + +public class FlexPipe : DrinkingWaterHeatingPipe +{ + protected override string _title => "Flex"; +}
\ No newline at end of file diff --git a/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/PinkPipe.cs b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/PinkPipe.cs new file mode 100644 index 0000000..284e466 --- /dev/null +++ b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/PinkPipe.cs @@ -0,0 +1,23 @@ +namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes; + +public class PinkPipe : DrinkingWaterHeatingPipe +{ + protected override string _title => "Pink+"; + + protected override Dictionary<string, string> _makeUp => new() + { + ["бухт"] = "бухта", + ["штанг"] = "прямые отрезки", + ["отр"] = "прямые отрезки" + }; + protected override Dictionary<int, string> _diameterNames => new() + { + [16] = "16х2,2", + [20] = "20х2,8", + [25] = "25х3,5", + [32] = "32х4,4", + [40] = "40х5,5", + [50] = "50х6,9", + [63] = "63х8,6" + }; +} diff --git a/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/StabilPipe.cs b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/StabilPipe.cs new file mode 100644 index 0000000..49dde86 --- /dev/null +++ b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/StabilPipe.cs @@ -0,0 +1,16 @@ +namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes; + +public class StabilPipe : DrinkingWaterHeatingPipe +{ + protected override string _title => "Stabil -PLATINUM"; + protected override Dictionary<int, string> _diameterNames => new() + { + [16] = "16,2х2,6", + [20] = "20х2,9", + [25] = "25х3,7", + [32] = "32х4,7", + [40] = "40х6,0", + [50] = "50x6,9", + [63] = "63x8,6" + }; +} |