示例#1
0
        public void TestUpdatePerson()
        {
            Guid                  guid      = new Guid("2E5DA098-91D6-40C4-95BC-98B206F8A36F");
            string                updatedBy = "TsetUserupdate";
            PersonDTO             person    = new PersonDTO();
            PersonEmailDTO        email     = new PersonEmailDTO();
            PersonPhoneDTO        phone     = new PersonPhoneDTO();
            PersonAddressDTO      address   = new PersonAddressDTO();
            List <PersonPhoneDTO> phones    = new List <PersonPhoneDTO>();

            phone.PhoneType = 1;
            phone.Phone     = "9907864345";
            phones.Add(phone);

            address.AddressID     = 1234;
            address.AddressNumber = 1;
            address.AddressType   = 1;
            address.IsPrimary     = true;
            address.ShipToName    = "TestUser";

            List <PersonAddressDTO> addres = new List <PersonAddressDTO>();

            addres.Add(address);
            List <PersonEmailDTO> emails = new List <PersonEmailDTO>();

            email.Email = "*****@*****.**";
            List <EmailTypes> emailtype = new List <EmailTypes>();

            person.Emails   = emails;
            person.PersonID = 8234;


            EmailTypes type = (EmailTypes)Enum.ToObject(typeof(EmailTypes), 1);

            email.EmailType = type;
            emails.Add(email);

            emailtype.Add(type);

            person.MasterGuid = Guid.Parse("2E5DA098-91D6-40C4-95BC-98B206F8A36F");
            person.Phones     = phones;
            person.Addresses  = addres;
            person.FirstName  = "TestUserupdate";
            person.MiddleName = "TestCase";
            person.LastName   = "Kaplan123";
            person.Title      = "Miss";
            bool Republish = false;
            var  result    = MessageAdapter.Utilities.Utility.UpdatePerson(guid, person, updatedBy, Republish).Result;
        }
示例#2
0
        public void TestCreatePerson()
        {
            PersonDTO             person  = new PersonDTO();
            PersonEmailDTO        email   = new PersonEmailDTO();
            PersonPhoneDTO        phone   = new PersonPhoneDTO();
            PersonAddressDTO      address = new PersonAddressDTO();
            List <PersonPhoneDTO> phones  = new List <PersonPhoneDTO>();

            phone.PhoneType = 1;
            phone.Phone     = "9907864345";
            phones.Add(phone);

            address.AddressID     = 1234;
            address.AddressNumber = 1;
            address.AddressType   = 1;
            address.IsPrimary     = true;
            address.ShipToName    = "TestUser";

            List <PersonAddressDTO> addres = new List <PersonAddressDTO>();

            addres.Add(address);
            List <PersonEmailDTO> emails = new List <PersonEmailDTO>();

            email.Email = "*****@*****.**";

            List <EmailTypes> emailtype = new List <EmailTypes>();
            EmailTypes        type      = (EmailTypes)Enum.ToObject(typeof(EmailTypes), 1);

            email.EmailType = type;
            emails.Add(email);

            emailtype.Add(type);

            person.Emails     = emails;
            person.PersonID   = 8234;
            person.PersonGuid = Guid.Parse("f2f224db-2c8a-456f-b025-f5955cd16051");
            person.MasterGuid = Guid.Parse("f2f224db-2c8a-456f-b025-f5955cd16051");

            person.Addresses  = addres;
            person.Phones     = phones;
            person.FirstName  = "TestUser";
            person.MiddleName = "TestCase";
            person.LastName   = "Kaplan123";
            person.Title      = "Ms";
            string createdBy = "TestUser";
            bool   Republish = false;
            var    result    = MessageAdapter.Utilities.Utility.CreatePersonAsync(person, createdBy, Republish).Result;
        }
示例#3
0
        /// <summary>
        /// Gets the person.
        /// </summary>
        /// <param name="xmlDoc">The XML document.</param>
        /// <returns></returns>
        public static List <PersonDTO> GetPerson(XDocument xmlDoc)
        {
            IEnumerable <XElement> xelementList = xmlDoc.Descendants(Constants.PersonNode);
            List <PersonDTO>       personObj    = new List <PersonDTO>();

            //multiple person
            if (xelementList != null)
            {
                //Read the element value into person object
                personObj = (from b in xelementList
                             select new PersonDTO
                {
                    PersonGuid = b.Element(Constants.PersonGuid) != null && !string.IsNullOrWhiteSpace(b.Element(Constants.PersonGuid).Value) ? new Guid(b.Element(Constants.PersonGuid).Value) : Guid.Empty,
                    MasterGuid = b.Element(Constants.MasterGuid) != null && !string.IsNullOrWhiteSpace(b.Element(Constants.MasterGuid).Value) ? new Guid(b.Element(Constants.MasterGuid).Value) : Guid.Empty,
                    PersonID = b.Element(Constants.PersonId) != null && !string.IsNullOrWhiteSpace(b.Element(Constants.PersonId).Value) ? Convert.ToInt32(b.Element(Constants.PersonId).Value) : 0,
                    FirstName = b.Element(Constants.FirstName) != null ? b.Element(Constants.FirstName).Value : null,
                    LastName = b.Element(Constants.LastName) != null ? b.Element(Constants.LastName).Value : null,
                    Title = b.Element(Constants.Title) != null ? b.Element(Constants.Title).Value : null
                }).ToList();

                foreach (PersonDTO person in personObj)
                {
                    //generate list of emails, phones and addresses
                    List <emails>    emailList   = new List <emails>();
                    List <addresses> addressList = new List <addresses>();
                    List <phones>    phoneList   = new List <phones>();

                    person.Addresses = new List <PersonAddressDTO>();
                    person.Emails    = new List <PersonEmailDTO>();
                    person.Phones    = new List <PersonPhoneDTO>();

                    //Fetch the emails node content
                    IEnumerable <XElement> emailsElementList = xelementList.Elements(Constants.Emails);
                    if (emailsElementList != null)
                    {
                        //Fetch the email node from the emails element list
                        IEnumerable <XElement> emailElement = emailsElementList.Elements(Constants.Email);
                        if (emailElement != null)
                        {
                            List <PersonEmailDTO> emailsList = new List <PersonEmailDTO>();

                            //Read the Type and address of each email into the emails list
                            foreach (XElement email in emailElement)
                            {
                                PersonEmailDTO mail            = new PersonEmailDTO();
                                string         emailTypeString = email.Attribute(Constants.Type) != null?email.Attribute(Constants.Type).Value : null;

                                if (!string.IsNullOrEmpty(emailTypeString))
                                {
                                    EmailTypes emailType;
                                    bool       isParsed = Enum.TryParse <EmailTypes>(emailTypeString.ToLower(), out emailType);
                                    if (isParsed)
                                    {
                                        mail.EmailType = emailType;
                                        mail.Email     = email.Attribute(Constants.Address) != null?email.Attribute(Constants.Address).Value : null;

                                        emailsList.Add(mail);
                                    }
                                }
                            }
                            person.Emails = emailsList;
                        }
                    }

                    /******Commented as on Nov 11th 2016, address service was not integrated and was not taken up for drop 1 release*/

                    //Fetch the addresses node content
                    IEnumerable <XElement> addressesElementList = xelementList.Elements(Constants.Addresses);
                    if (addressesElementList != null)
                    {
                        //Fetch the address node from the addresses element list
                        IEnumerable <XElement> addressElement = addressesElementList.Elements(Constants.Address);
                        if (addressElement != null)
                        {
                            List <PersonAddressDTO> addressesList = new List <PersonAddressDTO>();
                            foreach (XElement addressDetail in addressElement)
                            {
                                PersonAddressDTO addressObj = new PersonAddressDTO();
                                if (addressDetail.Attribute(Constants.Number) != null)
                                {
                                    int addressNumber;
                                    int.TryParse(addressDetail.Attribute(Constants.Number).Value, out addressNumber);
                                    addressObj.AddressNumber = addressNumber;
                                }
                                if (addressDetail.Attribute(Constants.ID) != null)
                                {
                                    int addressID;
                                    int.TryParse(addressDetail.Attribute(Constants.ID).Value, out addressID);
                                    addressObj.AddressID = addressID;
                                }
                                if (addressDetail.Attribute(Constants.Type) != null)
                                {
                                    AddressType addressType;
                                    Enum.TryParse <AddressType>(addressDetail.Attribute(Constants.Type).Value.ToLower(), out addressType);
                                    addressObj.AddressType = (byte)addressType;
                                }
                                if (addressDetail.Attribute(Constants.IsPrimary) != null)
                                {
                                    bool isPrimary;
                                    bool.TryParse(addressDetail.Attribute(Constants.IsPrimary).Value, out isPrimary);
                                    addressObj.IsPrimary = isPrimary;
                                }

                                addressObj.ShipToName = addressDetail.Attribute(Constants.ShipToName) != null?addressDetail.Attribute(Constants.ShipToName).Value : null;

                                AddressDTO address = new AddressDTO();
                                //TODO: the below properties are to be updated to address service : Done
                                address.CompanyName = addressDetail.Element(Constants.CompanyName) != null?addressDetail.Element(Constants.CompanyName).Value : null;

                                address.CountryCode = addressDetail.Element(Constants.Country) != null?addressDetail.Element(Constants.Country).Value : null;

                                address.City = addressDetail.Element(Constants.City) != null?addressDetail.Element(Constants.City).Value : null;

                                address.Line1 = addressDetail.Element(Constants.Line1) != null?addressDetail.Element(Constants.Line1).Value : null;

                                address.Line2 = addressDetail.Element(Constants.Line2) != null?addressDetail.Element(Constants.Line2).Value : null;

                                address.Line3 = addressDetail.Element(Constants.Line3) != null?addressDetail.Element(Constants.Line3).Value : null;

                                address.RegionCode = addressDetail.Element(Constants.RegionCode) != null?addressDetail.Element(Constants.RegionCode).Value : null;

                                address.PostalCode = addressDetail.Element(Constants.PostalCode) != null?addressDetail.Element(Constants.PostalCode).Value : null;

                                AddressValidationResultDTO addressValidationResult = CreateAddress(address).Result;
                                if (addressValidationResult != null && addressValidationResult.AddressID != 0)
                                {
                                    addressObj.AddressID = addressValidationResult.AddressID;
                                    addressesList.Add(addressObj);
                                }
                            }
                            person.Addresses = addressesList;
                        }
                    }
                    //Fetch the phones node content
                    IEnumerable <XElement> phonesElementList = xelementList.Elements(Constants.Phones);
                    if (phonesElementList != null)
                    {
                        //Fetch the phone node from the phones element list
                        IEnumerable <XElement> phoneElement = phonesElementList.Elements(Constants.Phone);
                        if (phoneElement != null)
                        {
                            List <PersonPhoneDTO> phonesList = new List <PersonPhoneDTO>();
                            foreach (XElement phoneDetail in phoneElement)
                            {
                                PersonPhoneDTO phoneObj        = new PersonPhoneDTO();
                                string         phoneTypeString = phoneDetail.Attribute(Constants.Type) != null?phoneDetail.Attribute(Constants.Type).Value : null;

                                if (!string.IsNullOrEmpty(phoneTypeString))
                                {
                                    PhoneType phoneType;
                                    bool      isPhoneTypeParsed = Enum.TryParse <PhoneType>(phoneTypeString.ToLower(), out phoneType);
                                    if (isPhoneTypeParsed)
                                    {
                                        phoneObj.PhoneType = (byte)phoneType;
                                        phoneObj.Phone     = phoneDetail.Attribute(Constants.Number) != null?phoneDetail.Attribute(Constants.Number).Value : null;

                                        phonesList.Add(phoneObj);
                                    }
                                }
                            }
                            person.Phones = phonesList;
                        }
                    }
                }
            }
            return(personObj);
        }