Files
parr_api/PARR.BLL/Services/Implementations/TemplateMaskValidator.cs

42 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using PARR.BLL.Services.Interfaces;
using System.Text.RegularExpressions;
namespace PARR.BLL.Services.Implementations
{
internal class TemplateMaskValidator : ITemplateMaskValidator
{
public bool IsValid(string mask)
{
if (!mask.Contains("ПАРР"))
return false;
var shortcodePattern = "%[^%\\s]+%";
var shortcodesInMask = Regex.Matches(mask, shortcodePattern).ToList();
if (shortcodesInMask.Count() == 0)
return false;
var validShortcodes = GetShortcodesNames();
foreach (var shortcode in shortcodesInMask)
{
if (!validShortcodes.Contains(shortcode.ToString().ToUpper()))
return false;
}
return true;
}
private List<string> GetShortcodesNames()//TODO Ну ты опять этот метод дублируешь?!
{
var result = new List<string> {
"%ЭК%",
"%ЗО%",
"%РАБОТА%"
};
return result;
}
}
}