Ejemplo n.º 1
0
        public static bool?CheckVotingRights(PeselData peselData)
        {
            //check if user is over 18 years old
            DateTime dateTurns18 = peselData.BirthDate.AddYears(18);

            if (DateTime.Compare(dateTurns18, DateTime.Today) > 0)
            {
                return(false);
            }
            //check if user is on blocked list
            const string blockedPeselsUrl = "http://webtask.future-processing.com:8069/blocked";

            try
            {
                using (System.Net.WebClient wc = new System.Net.WebClient())
                {
                    var             json             = wc.DownloadString(blockedPeselsUrl);
                    var             disallowedPesels = ParsingUtility.JsonParser.GetData <JsonDisallowedPesels>(json);
                    DisallowedPesel mathingPesel     = disallowedPesels.disallowed.person.Find(x => ParsingUtility.HashCreator.GetHash(x.pesel) == peselData.Pesel);
                    if (mathingPesel != null)
                    {
                        //user is on disallowed list
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
            return(true);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("START");

            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "pesels.txt");

            var validator  = new PeselDataValidator();
            var calculator = new PeselDataControlSum();

            var gen    = new PeselData(calculator, validator);
            var result = gen.Run(new DateTime(1977, 6, 4), GenderEnum.Male);

            Console.WriteLine($"PESEL: {result.Pesel}");

            var validation = validator.Validate("77060407272", calculator);

            Console.WriteLine($"Valid: {validation.IsValid}");

            Console.WriteLine("END");
            Console.Read();
        }