public virtual ValidationResult Validate(string rawPesel, IPeselDataControlSum controlSumCalculator)
        {
            var result = new ValidationResult();

            int[] pesel   = rawPesel.Select(ch => int.Parse(ch.ToString())).ToArray();
            int   origSum = pesel[pesel.Length - 1];

            pesel[pesel.Length - 1] = -1;

            controlSumCalculator.CalculateControlSum(pesel);

            if (origSum != pesel[pesel.Length - 1])
            {
                result.Massages.Add(TXT.ValidationFailed);
            }

            if (!result.Massages.Any())
            {
                result.IsValid = true;
            }

            return(result);
        }
Esempio n. 2
0
        public Result Run(DateTime birthDate, GenderEnum sex)
        {
            var result = new Result();

            var validation = _validator.ValidateInput(birthDate);

            if (!validation.IsValid)
            {
                result.Pesel      = "";
                result.Validation = validation;
                return(result);
            }

            ApplyCenturies();
            ApplyYear(birthDate);
            ApplyMonth(birthDate);
            ApplyDay(birthDate);
            ApplyGender(sex);
            _sumCalculator.CalculateControlSum(_pesel);

            return(new Result {
                Pesel = string.Join("", _pesel)
            });
        }