예제 #1
0
        public XElement BuildProviderElement(Provider provider)
        {
            if (provider.Names == null || !provider.Names.Any())
            {
                throw new AdfException("A name is required for the provider.");
            }

            var providerElement = new XElement("provider");

            var idElements = GetIdElements(provider.Ids, IdXElementBuilder);

            if (idElements.Any())
            {
                providerElement.Add(idElements);
            }

            providerElement.Add(NameXElementBuilder.BuildNameElements(provider.Names));

            if (!string.IsNullOrEmpty(provider.Service))
            {
                providerElement.Add(new XElement("service", provider.Service));
            }

            if (!string.IsNullOrEmpty(provider.Url))
            {
                providerElement.Add(new XElement("url", provider.Url));
            }

            if (provider.Email != null)
            {
                providerElement.Add(EmailXElementBuilder.BuildEmailElement(provider.Email));
            }

            if (provider.Phone != null)
            {
                providerElement.Add(PhoneXElementBuilder.BuildPhoneElement(provider.Phone));
            }

            if (provider.Contact != null)
            {
                providerElement.Add(ContactXElementBuilder.BuildContactElement(provider.Contact));
            }

            return(providerElement);
        }
예제 #2
0
        public XElement BuildContactElement(Contact contact)
        {
            var hasEmail = contact.Email != null && !string.IsNullOrEmpty(contact.Email.Value);
            var hasPhone = contact.PhoneNumbers != null && contact.PhoneNumbers.Any(p => !string.IsNullOrEmpty(p.Value));

            if (contact.Names == null || !contact.Names.Any() || contact.Names.All(n => string.IsNullOrEmpty(n.Value)))
            {
                throw new AdfException("A name is required for contact.");
            }

            if (!hasEmail && !hasPhone)
            {
                throw new AdfException("An email or phone number is required for contact.");
            }

            var contactElement = new XElement("contact");

            if (contact.PrimaryContact.HasValue)
            {
                contactElement.Add(new XAttribute("primarycontact", contact.PrimaryContact.Value ? "1" : "0"));
            }

            contactElement.Add(NameXElementBuilder.BuildNameElements(contact.Names));

            if (hasEmail)
            {
                contactElement.Add(EmailXElementBuilder.BuildEmailElement(contact.Email));
            }

            if (hasPhone)
            {
                contactElement.Add(PhoneXElementBuilder.BuildPhoneElements(contact.PhoneNumbers));
            }

            if (contact.Address != null)
            {
                contactElement.Add(GetAddressElement(contact.Address));
            }

            return(contactElement);
        }