Exemplo n.º 1
0
            /// <summary>
            /// Creates an instance of the Person aggregate
            /// </summary>
            /// <param name="personId">The aggregate Id</param>
            /// <param name="firstName">The person's first name</param>
            /// <param name="lastName">The person's last name</param>
            /// <param name="nationalIdentificationNumber">The person's National Identification Number</param>
            /// <param name="vatNumber">The person's VAT Number</param>
            /// <returns>The aggregate instance</returns>
            /// <exception cref="ArgumentException">Thrown if the firstName or the last name are null or empty</exception>
            public static Person CreateNewEntryByImport(Guid personId, string firstName, string lastName, string nationalIdentificationNumber, string vatNumber, string address, string city, string postalCode, string province, string country, string phoneNumber, string mobileNumber, string faxNumber, string websiteAddress, string emailAddress, string instantMessaging)
            {
                if (string.IsNullOrWhiteSpace(firstName))
                {
                    throw new ArgumentException("The first name must be specified", nameof(firstName));
                }
                if (string.IsNullOrWhiteSpace(lastName))
                {
                    throw new ArgumentException("The last name must be specified", nameof(lastName));
                }
                if (!string.IsNullOrWhiteSpace(nationalIdentificationNumber))
                {
                    if (!NationalIdentificationNumberHelper.IsMatchingFirstName(nationalIdentificationNumber, firstName))
                    {
                        throw new ArgumentException("National identification number is not matching with first name", nameof(nationalIdentificationNumber));
                    }
                    if (!NationalIdentificationNumberHelper.IsMatchingLastName(nationalIdentificationNumber, lastName))
                    {
                        throw new ArgumentException("National identification number is not matching with last name", nameof(nationalIdentificationNumber));
                    }
                }
                if (!PostalAddressHelper.IsValidAddress(address, city, postalCode, province, country))
                {
                    throw new ArgumentException("postal address must either be empty or comprehensive of both address and city");
                }

                var e = new PersonRegisteredEvent(personId, firstName, lastName, nationalIdentificationNumber, vatNumber, address, city, postalCode, province, country, phoneNumber, mobileNumber, faxNumber, websiteAddress, emailAddress, instantMessaging);
                var p = new Person();

                p.RaiseEvent(e);
                return(p);
            }
Exemplo n.º 2
0
            /// <summary>
            /// Creates an instance of the Person aggregate
            /// </summary>
            /// <param name="firstName">The person's first name</param>
            /// <param name="lastName">The person's last name</param>
            /// <param name="nationalIdentificationNumber">The person's National Identification Number</param>
            /// <param name="vatNumber">The person's VAT Number</param>
            /// <returns>The aggregate instance</returns>
            /// <exception cref="ArgumentException">Thrown if the firstName or the last name are null or empty</exception>
            public static Person CreateNewEntry(string firstName, string lastName, string nationalIdentificationNumber, string vatNumber,
                                                string legalAddressAddress, string legalAddressCity, string legalAddressPostalCode, string legalAddressProvince, string legalAddressCountry,
                                                string billingAddressAddress, string billingAddressCity, string billingAddressPostalCode, string billingAddressProvince, string billingAddressCountry,
                                                string shippingAddressAddress, string shippingAddressCity, string shippingAddressPostalCode, string shippingAddressProvince, string shippingAddressCountry,
                                                string phoneNumber, string mobileNumber, string faxNumber, string websiteAddress, string emailAddress, string instantMessaging, Guid userId)
            {
                if (string.IsNullOrWhiteSpace(firstName))
                {
                    throw new ArgumentException("The first name must be specified", nameof(firstName));
                }

                if (string.IsNullOrWhiteSpace(lastName))
                {
                    throw new ArgumentException("The last name must be specified", nameof(lastName));
                }

                if (!string.IsNullOrWhiteSpace(nationalIdentificationNumber))
                {
                    if (!NationalIdentificationNumberHelper.IsMatchingFirstName(nationalIdentificationNumber, firstName))
                    {
                        throw new ArgumentException("National identification number is not matching with first name", nameof(nationalIdentificationNumber));
                    }
                    if (!NationalIdentificationNumberHelper.IsMatchingLastName(nationalIdentificationNumber, lastName))
                    {
                        throw new ArgumentException("National identification number is not matching with last name", nameof(nationalIdentificationNumber));
                    }
                }
                if (!PostalAddressHelper.IsValidAddress(legalAddressAddress, legalAddressCity, legalAddressPostalCode, legalAddressProvince, legalAddressCountry))
                {
                    throw new ArgumentException("legal address must either be empty or comprehensive of both address and city");
                }

                if (!PostalAddressHelper.IsValidAddress(shippingAddressAddress, shippingAddressCity, shippingAddressPostalCode, shippingAddressProvince, shippingAddressCountry))
                {
                    throw new ArgumentException("shipping address must either be empty or comprehensive of both address and city");
                }

                if (!PostalAddressHelper.IsValidAddress(billingAddressAddress, billingAddressCity, billingAddressPostalCode, billingAddressProvince, billingAddressCountry))
                {
                    throw new ArgumentException("billing address must either be empty or comprehensive of both address and city");
                }

                var personId         = Guid.NewGuid();
                var registrationDate = DateTime.Now;
                var e = new PersonRegisteredEvent(personId, registrationDate, firstName, lastName, nationalIdentificationNumber, vatNumber,
                                                  legalAddressAddress, legalAddressCity, legalAddressPostalCode, legalAddressProvince, legalAddressCountry,
                                                  billingAddressAddress, billingAddressCity, billingAddressPostalCode, billingAddressProvince, billingAddressCountry,
                                                  shippingAddressAddress, shippingAddressCity, shippingAddressPostalCode, shippingAddressProvince, shippingAddressCountry,
                                                  phoneNumber, mobileNumber, faxNumber, websiteAddress, emailAddress, instantMessaging, userId);
                var p = new Person();

                p.RaiseEvent(e);
                return(p);
            }
Exemplo n.º 3
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var validationResults = new List <ValidationResult>();

            if (!string.IsNullOrWhiteSpace(NationalIdentificationNumber))
            {
                if (!NationalIdentificationNumberHelper.IsMatchingFirstName(NationalIdentificationNumber.Trim().ToUpper(), FirstName))
                {
                    validationResults.Add(new ValidationResult("National Identification Number is not matching with First Name", new string[] { nameof(NationalIdentificationNumber) }));
                }
                if (!NationalIdentificationNumberHelper.IsMatchingLastName(NationalIdentificationNumber.Trim().ToUpper(), LastName))
                {
                    validationResults.Add(new ValidationResult("National Identification Number is not matching with Last Name", new string[] { nameof(NationalIdentificationNumber) }));
                }
            }

            return(validationResults);
        }