コード例 #1
0
        public async Task CreateClientAsync(CreateClientDto createClietnDto)
        {
            var addresses = new List <Address>();
            var contacts  = new List <Contact>();
            var client    = new Client
            {
                UniqueId   = Guid.NewGuid(),
                FirstName  = createClietnDto.FirstName,
                MiddleName = createClietnDto.MiddleName,
                LastName   = createClietnDto.LastName,
                Gender     = createClietnDto.Gender,
            };

            var clientId = await _clientRepository.CreateClientAsync(client);

            if (createClietnDto.AddressesDto != null)
            {
                foreach (var address in createClietnDto.AddressesDto)
                {
                    addresses.Add(new Address
                    {
                        UniqueId      = Guid.NewGuid(),
                        AddressType   = address.AddressType,
                        Line1         = address.Line1,
                        Line2         = address.Line2,
                        Line3         = address.Line3,
                        AreaCode      = address.AreaCode,
                        City          = address.City,
                        StateProvince = address.StateProvince,
                        Country       = address.Country,
                        ClientId      = clientId
                    });
                }
            }

            if (createClietnDto.ContactsDto != null)
            {
                foreach (var contact in createClietnDto.ContactsDto)
                {
                    contacts.Add(new Contact
                    {
                        UniqueId    = Guid.NewGuid(),
                        ContactType = contact.ContactType,
                        Msisdn      = contact.Msisdn,
                        ClientId    = clientId
                    });
                }
            }

            await _addressRepository.CreateAddressesAsync(addresses);

            await _contactRepository.CreateContactsAsync(contacts);
        }