Beispiel #1
0
        public void Register(ICitizen citizen)
        {
            if (checkIfExist(citizen.VatId))
            {
                throw new InvalidOperationException();
            }

            if (string.IsNullOrEmpty(citizen.VatId))
            {
                citizen.VatId = registerVatID(citizen);
            }

            citizens[countNow++] = citizen;
            lastDate             = SystemDateTime.Now();
        }
Beispiel #2
0
        public string Stats()
        {
            int countOfMen = this.registry.Count((x) => x.Gender == Gender.Male);

            string res = string.Format(
                "{0} and {1}",
                "man".ToQuantity(countOfMen),
                "woman".ToQuantity(this.registry.Length - countOfMen));

            if (this.lastUpdate != null)
            {
                res += string.Format(
                    ". Last registration was {0}",
                    this.lastUpdate.Humanize(true, SystemDateTime.Now()));
            }

            return(res);
        }
Beispiel #3
0
        public void Register(ICitizen citizen)
        {
            this.CheckForRepeats(citizen);
            if (this.Count == this.registry.Length)
            {
                Array.Resize(ref this.registry, this.FindNewCapacity());
            }

            if (string.IsNullOrWhiteSpace(citizen.VatId))
            {
                citizen.VatId = this.CalculateValidVatID(citizen);
            }

            this.registry[this.Count] =
                new Citizen(citizen.FirstName, citizen.LastName, citizen.BirthDate, citizen.Gender)
            {
                VatId = citizen.VatId
            };
            this.lastUpdate = SystemDateTime.Now();
            this.Count++;
        }
        private void AddCitizenToArray(ICitizen citizen)
        {
            if (citizen == null)
            {
                throw new ArgumentNullException("citizen");
            }

            if (allCitizens.Length == 0)
            {
                Array.Resize<ICitizen>(ref allCitizens, 1);
            }

            if (registeredCitizensCount == allCitizens.Length)
            {
                Array.Resize<ICitizen>(ref allCitizens, allCitizens.Length * 2);
            }

            allCitizens[registeredCitizensCount] = new Citizen(citizen.FirstName, citizen.LastName, citizen.BirthDate, citizen.Gender);
            allCitizens[registeredCitizensCount].VatId = citizen.VatId;
            lastRegisterTime = SystemDateTime.Now();
            registeredCitizensCount++;
        }
Beispiel #5
0
        public void Register(ICitizen citizen)
        {
            if (count >= length)
            {
                throw new IndexOutOfRangeException("Registry is full!");
            }

            if (Contains(citizen.VatId))
            {
                throw new InvalidOperationException("This citizen is already exist!");
            }
            else
            {
                if (string.IsNullOrEmpty(citizen.VatId))
                {
                    citizen.VatId = GenerateVatId(citizen.BirthDate, citizen.Gender);
                }

                citizens[count++]    = (ICitizen)citizen.Clone();
                lastRegistrationTime = SystemDateTime.Now();
            }
        }
        public string Stats()
        {
            int female = 0;
            int male = 0;
            for (int i = 0; i < registeredCitizensCount; i++)
            {
                if (allCitizens[i].Gender == Gender.Female)
                {
                    female++;
                }
                else
                {
                    male++;
                }
            }

            if (female == 0 && male == 0)
            {
                return "0 men and 0 women";
            }

            return "man".ToQuantity(male) + " and " + "woman".ToQuantity(female)
            + ". Last registration was " + lastRegisterTime.Humanize(dateToCompareAgainst: SystemDateTime.Now());
        }
        public string Stats()
        {
            var s = this.lastRegistrationDateTime.HasValue ? ". Last registration was " + this.lastRegistrationDateTime.Value.Humanize(dateToCompareAgainst: SystemDateTime.Now()) : string.Empty;

            return($"{this.genderCounts[(int)Gender.Male]} m{(char)(97 + (Convert.ToInt32(this.genderCounts[(int)Gender.Male] != 1) * 4))}n and {this.genderCounts[(int)Gender.Female]} wom{(char)(97 + (Convert.ToInt32(this.genderCounts[(int)Gender.Female] != 1) * 4))}n" + s);
        }
Beispiel #8
0
        private bool isValidDateOfBirth(DateTime dateOfBirth)
        {
            DateTime dtNow = SystemDateTime.Now(); // Not compare without this

            return(dateOfBirth.CompareTo(dtNow) > 0);
        }
        public void Register(ICitizen citizen)
        {
            int sum = 0;
            int sn  = 0;

            int[] mul = { -1, 5, 7, 9, 4, 6, 10, 5, 7 };

            string serNString;
            string checkNumber;
            string dateString;

            TimeSpan livedPeriod;

            if (String.IsNullOrEmpty(citizen.VatId))
            {
                switch (citizen.Gender)
                {
                case Gender.Female:
                {
                    sn = 0;
                    break;
                }

                case Gender.Male:
                {
                    sn = 1;
                    break;
                }
                }

                livedPeriod = citizen.BirthDate - this.refDate;

                dateString = livedPeriod.Days.ToString().PadLeft(5, '0');

                do
                {
                    serNString = sn.ToString().PadLeft(4, '0');

                    var charArr = string.Concat(dateString, serNString);

                    for (int i = 0; i < charArr.Length; i++)
                    {
                        sum += int.Parse(charArr[i].ToString()) * mul[i];
                    }
                    checkNumber = ((sum % 11) % 10).ToString();
                    sn         += 2;
                }while (this[string.Concat(dateString, serNString, checkNumber)] != null);

                citizen.VatId = string.Concat(dateString, serNString, checkNumber);
            }

            if (this[citizen.VatId] == null)
            {
                for (int i = 0; i < this.citizenArray.Length; i++)
                {
                    var item = this.citizenArray[i];
                    if (item == null)
                    {
                        item             = new Citizen(citizen);
                        this.lastRegDate = SystemDateTime.Now();
                        break;
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Same person cannot be added twice");
            }
        }