コード例 #1
0
        /// <summary>
        /// Implementation of <see cref="ICustomerCommands.RegisterNewPerson(string, string, string, Gender, DateTime)"/>
        /// </summary>
        /// <param name="firstName">The first name</param>
        /// <param name="lastName">The last name</param>
        /// <param name="nationalIdentificationNumber">The national identification number</param>
        /// <param name="gender">The gender</param>
        /// <param name="birthDate">The birth date</param>
        /// <returns></returns>
        public async Task RegisterNewPerson(string firstName, string lastName, string nationalIdentificationNumber, Gender gender, DateTime birthDate)
        {
            if (string.IsNullOrWhiteSpace(firstName))
            {
                throw new ArgumentException("value cannot be empty", nameof(firstName));
            }

            if (string.IsNullOrWhiteSpace(lastName))
            {
                throw new ArgumentException("value cannot be empty", nameof(lastName));
            }

            if (birthDate >= DateTime.Today)
            {
                throw new ArgumentException("Birth date cannot be after today", nameof(birthDate));
            }

            var person = Person.Register(firstName, lastName, gender, birthDate);

            if (!string.IsNullOrWhiteSpace(nationalIdentificationNumber))
            {
                person.SetNationalIdentificationNumber(nationalIdentificationNumber);
            }

            Repository.Add(person);
            await Repository.SaveChangesAsync();

            var @event = new PersonRegisteredEvent(person.Id, firstName, lastName, gender, birthDate);

            EventBus.RaiseEvent(@event);
        }
コード例 #2
0
            /// <summary>
            /// Creates an instance of the Person aggregate
            /// </summary>
            /// <param name="personId">The aggregate Id</param>
            /// <param name="registrationDate">The date in which the person was registered</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, DateTime registrationDate, 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, 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(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, registrationDate, firstName, lastName, nationalIdentificationNumber, vatNumber, address, city, postalCode, province, country, address, city, postalCode, province, country, address, city, postalCode, province, country, phoneNumber, mobileNumber, faxNumber, websiteAddress, emailAddress, instantMessaging, userId);
                var p = new Person();

                p.RaiseEvent(e);
                return(p);
            }
コード例 #3
0
        public async Task Handle(PersonRegisteredEvent message)
        {
            var p = new Party()
            {
                OriginalId  = message.PersonId,
                DisplayName = $"{message.FirstName} {message.LastName}",
                NationalIdentificationNumber = message.NationalIdentificationNumber,
                VatIndex     = message.VatNumber,
                Type         = Party.PartyType.Person,
                LegalAddress = new PostalAddress
                {
                    Address    = message.LegalAddressAddress,
                    City       = message.LegalAddressCity,
                    Country    = message.LegalAddressCountry,
                    PostalCode = message.LegalAddressPostalCode,
                    Province   = message.LegalAddressProvince
                },
                //ContactInfo = new ContactInfo
                //{
                PhoneNumber      = message.PhoneNumber,
                MobileNumber     = message.MobileNumber,
                FaxNumber        = message.FaxNumber,
                WebsiteAddress   = message.WebsiteAddress,
                EmailAddress     = message.EmailAddress,
                InstantMessaging = message.InstantMessaging
                                   //}
            };

            using (var context = new RegistryDbContext(Options))
            {
                context.Parties.Add(p);
                await context.SaveChangesAsync();
            }
        }
コード例 #4
0
            public static Person CreateNewEntry(string firstName, string lastName, DateTime?dateOfBirth)
            {
                var e = new PersonRegisteredEvent(Guid.NewGuid(), firstName, lastName);
                var p = new Person();

                p.RaiseEvent(e);
                return(p);
            }
コード例 #5
0
 /// <summary>
 /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/>
 /// </summary>
 /// <param name="event"></param>
 public void Handle(PersonRegisteredEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
コード例 #6
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);
            }
コード例 #7
0
ファイル: Person.cs プロジェクト: emanbuc/M.NetAAE2
            public static Person CreateNewEntry(string firstName, string lastName, DateTime?dateOfBirth)
            {
                var p = new Person()
                {
                    Id        = Guid.NewGuid(),
                    FirstName = firstName,
                    LastName  = lastName
                };
                var e = new PersonRegisteredEvent(p.Id, p.FirstName, p.LastName);

                p.RaiseEvent(e);
                return(p);
            }
コード例 #8
0
        public void ToString_Should_Return_Event_Formatted_As_String()
        {
            Guid     personId  = Guid.NewGuid();
            string   firstName = "firstname";
            string   lastName  = "lastname";
            Gender   gender    = Gender.Female;
            DateTime birthDate = new DateTime(1980, 1, 1);

            var ev = new PersonRegisteredEvent(personId, firstName, lastName, gender, birthDate);

            string eventAsString = $"Person {firstName} {lastName}, gender {gender.ToString()}, birth date {birthDate.ToShortDateString()} registered";

            Assert.Equal(eventAsString, ev.ToString());
        }
コード例 #9
0
ファイル: Person.cs プロジェクト: mtemel123/Merp
            public static Person CreateNewEntry(string firstName, string lastName, DateTime?dateOfBirth)
            {
                if (string.IsNullOrWhiteSpace(firstName))
                {
                    throw new ArgumentException("The first name must be specified", nameof(firstName));
                }
                if (string.IsNullOrWhiteSpace(lastName))
                {
                    throw new ArgumentException("The first name must be specified", nameof(lastName));
                }

                var e = new PersonRegisteredEvent(Guid.NewGuid(), firstName, lastName);
                var p = new Person();

                p.RaiseEvent(e);
                return(p);
            }
コード例 #10
0
        static void Main(string[] args)
        {
            var container = new Container();

            BootStrapper.RegisterServices(container);

            var person = new Person
            {
                PersonId = new Guid(),
                Name     = "Tiago Pariz"
            };

            var save = new PersonRegisteredEvent(person.PersonId, person.Name);

            BootStrapper.Raise(container, save);

            Console.ReadKey();
        }
コード例 #11
0
        public void Ctor_Should_Set_All_Values_Correctly()
        {
            Guid     personId  = Guid.NewGuid();
            string   firstName = "firstname";
            string   lastName  = "lastname";
            Gender   gender    = Gender.Female;
            DateTime birthDate = new DateTime(1980, 1, 1);

            var ev = new PersonRegisteredEvent(personId, firstName, lastName, gender, birthDate);

            Assert.Equal(personId, ev.PersonId);
            Assert.Equal(firstName, ev.FirstName);
            Assert.Equal(lastName, ev.LastName);
            Assert.Equal(gender, ev.Gender);
            Assert.Equal(birthDate, ev.BirthDate);

            Assert.Equal(personId, ev.AggregateId);
            Assert.Equal(typeof(Registries.Models.Customer), ev.AggregateType);
            Assert.Equal(DateTime.Today, ev.FiredOn.Date);
        }
コード例 #12
0
        static void Main(string[] args)
        {
            // Referência: http://blog.tiagopariz.com/c-ddd-domain-events/

            var container = new Container();

            BootStrapper.RegisterServices(container);

            var person = new Person
            {
                PersonId = new Guid(),
                Name     = "Jairo Bionez"
            };

            var save = new PersonRegisteredEvent(person.PersonId, person.Name);

            BootStrapper.Raise(container, save);

            Console.ReadKey();
        }
コード例 #13
0
ファイル: Person.cs プロジェクト: pixelia-es/Merp
            /// <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)
            {
                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))
                {
                    throw new ArgumentException("The National Identification Number", nameof(nationalIdentificationNumber));
                }

                var e = new PersonRegisteredEvent(personId, firstName, lastName, nationalIdentificationNumber, vatNumber);
                var p = new Person();

                p.RaiseEvent(e);
                return(p);
            }
コード例 #14
0
 public void Apply(PersonRegisteredEvent evt)
 {
     Id        = evt.PersonId;
     FirstName = evt.FirstName;
     LastName  = evt.LastName;
 }
コード例 #15
0
ファイル: Person.cs プロジェクト: stalla/NAAE
 public void Apply(PersonRegisteredEvent evt)
 {
     this.Id        = evt.PersonId;
     this.FirstName = evt.FirstName;
     this.LastName  = evt.LastName;
 }
コード例 #16
0
 private Person(PersonRegisteredEvent createdEvent)
     : this()
 {
     Apply(createdEvent);
 }