/// <inheritdoc /> public void Register(ICitizen citizen) { if (string.IsNullOrWhiteSpace(citizen.VatId)) { int dayNumber = (citizen.BirthDate - startDate).Days; string dateString = dayNumber.ToString("D5"); var oneDayBorned = register.Where(v => v.Key.StartsWith(dateString) && v.Key.Length == 10) .Select(v => v.Key.Substring(5, 4)); var genderSequenceNumbers = oneDayBorned.Where(v => GenderCondition(v, citizen.Gender)) .Select(v => int.Parse(v)).ToList(); int currentNumber = genderSequenceNumbers.Any() ? genderSequenceNumbers.Max() : -1; int nextSequenceNumber = GetNextAllowed(currentNumber, citizen.Gender); string stringSequenceNumber = nextSequenceNumber.ToString("D4"); int controlNumber = GetControlNumber(dateString, stringSequenceNumber); citizen.VatId = dateString + stringSequenceNumber + controlNumber; } if (!register.ContainsKey(citizen.VatId)) { citizen.RegistrationDate = SystemDateTime.Now(); register.Add(citizen.VatId, citizen.Clone() as ICitizen); } else { throw new InvalidOperationException(); } }
public void Register(ICitizen citizen) { if (citizen.VatId == null || CitizenRegistryHelper.FindCitizenById(citizens, citizenCount, citizen.VatId) == null) { if (String.IsNullOrWhiteSpace(citizen.VatId)) { int birthNumber; string id; do { birthNumber = CitizenRegistryHelper.GetBirthNumber(citizen.Gender); id = CitizenRegistryHelper.GenerateVatId(citizen.BirthDate, birthNumber, citizen.Gender); } while (CitizenRegistryHelper.FindCitizenById(citizens, citizenCount, id) != null); citizen.VatId = id; } if (citizenCount == citizens.Length) { Array.Resize(ref citizens, citizens.Length * 2); } citizens[citizenCount] = citizen.Clone() as Citizen; citizenCount++; lastRegistrationTime = SystemDateTime.Now(); } else { throw new InvalidOperationException(); } }
public void Register(ICitizen citizen) { if (String.IsNullOrEmpty(citizen.VatId)) { string serialNumber = VatIdBuilder.CalculateSerialNumberVatVatIdValue(); citizen.VatId = VatIdBuilder.GenerateVatId(citizen.BirthDate, serialNumber, citizen.Gender); } if (citizens.FirstOrDefault(c => c.VatId == citizen.VatId) != null) { throw new InvalidOperationException(); } Citizen citizenCopy = citizen.Clone() as Citizen; citizens.Add(citizenCopy); }
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(); } }