示例#1
0
        public void Insert(long dealerId)
        {
            DBAccess.ExecuteNonQuery("INSERT INTO Contact (Surname, Name, Patronymic, Position, DealerId) VALUES (@param1, @param2, @param3, @param4, @param5)", Surname, Name, Patronymic, Position, dealerId);
            long contactId = DBAccess.ExecuteScalar <long>("SELECT MAX(Id) FROM Contact");

            Phones.ForEach(x => x.Insert(contactId));
            Faxes.ForEach(x => x.Insert(contactId));
            Emails.ForEach(x => x.Insert(contactId));
        }
        private async Task <StoredContact> ToStoredContact(StoredContact contact)
        {
            if (contact == null)
            {
                ContactStore contactStore = await ContactStore.CreateOrOpenAsync(
                    ContactStoreSystemAccessMode.ReadWrite,
                    ContactStoreApplicationAccessMode.ReadOnly);

                contact = new StoredContact(contactStore);
            }

            IDictionary <string, object> properties = await contact.GetPropertiesAsync();

            // Address
            if (Addresses != null && Addresses.Count > 0)
            {
                Addresses.ForEach(address => address.AsStoredContactProperties(ref properties));
            }

            // Birthday
            if (W3ContactBirthday != null)
            {
                W3ContactBirthday.AsStoredContactProperties(ref properties);
            }

            // Emails
            if (Emails != null && Emails.Count > 0)
            {
                Emails.ForEach(email => email.AsStoredContactProperties(ref properties));
            }

            // Name
            if (Name != null)
            {
                Name.AsStoredContactProperties(ref properties);
            }

            // NickName
            if (W3ContactNickName != null)
            {
                W3ContactNickName.AsStoredContactProperties(ref properties);
            }

            // Note
            if (W3ContactNotes != null)
            {
                W3ContactNotes.AsStoredContactProperties(ref properties);
            }

            // Organization
            if (Organization != null)
            {
                Organization.AsStoredContactProperties(ref properties);
            }

            // Phones
            if (Phones != null && Phones.Count > 0)
            {
                Phones.ForEach(phone => phone.AsStoredContactProperties(ref properties));
            }

            // Photos
            if (Photos != null && Photos.Count > 0)
            {
                W3ContactPhoto firstPhoto = Photos.FirstOrDefault();
                if (firstPhoto != null)
                {
                    await firstPhoto.SetPictureOnStoredContactAsync(contact);
                }
            }

            // Urls
            if (Urls != null && Urls.Count > 0)
            {
                Urls.ForEach(url => url.AsStoredContactProperties(ref properties));
            }

            return(contact);
        }
示例#3
0
        public void IsValid()
        {
            if (Purpose == AddressPurposeType.Shipping)
            {
                if (Name.IsNullorEmpty())
                {
                    throw new ArgumentException("Nome inválido");
                }

                if (ContactName.IsNullorEmpty())
                {
                    throw new ArgumentException("Nome do destinatário inválido");
                }
            }

            if (Type == AddressType.None)
            {
                Type = AddressType.HomeAddress;
            }

            if (ZipCode.IsNullorEmpty() || ZipCode.ClearStrings().Length != 8)
            {
                throw new ArgumentException("CEP inválido");
            }

            if (Street.IsNullOrWhiteSpace())
            {
                throw new ArgumentException("Logradouro inválido");
            }

            if (Number.IsNullorEmpty())
            {
                throw new ArgumentException("Número inválido");
            }

            if (District.IsNullorEmpty())
            {
                throw new ArgumentException("Bairro inválido");
            }

            if (City.IsNullorEmpty())
            {
                throw new ArgumentException("Cidade inválida");
            }

            List <string> states = new List <string>()
            {
                "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO"
            };

            if (!states.Contains(State))
            {
                throw new ArgumentException("Estado inválido");
            }

            if (Phones.Count == 0)
            {
                throw new ArgumentException("Telefone inválido. Informe ao menos 1");
            }

            var _phone = "";

            Phones.ForEach(phone =>
            {
                phone.DDD.Replace("\0", "").Replace("&#x0", "").Replace("\\0", "").Trim();

                if (!phone.DDD.IsNullorEmpty() && phone.DDD.TakeSpecialCharactersOff().Length != 2)
                {
                    if (phone.DDD.TakeSpecialCharactersOff().Length == 3)
                    {
                        phone.DDD = phone.DDD.Substring(1);
                    }
                    else if (phone.DDD.TakeSpecialCharactersOff().Length == 4)
                    {
                        phone.DDD = phone.DDD.Substring(2);
                    }
                    else
                    {
                        throw new ArgumentException("DDD inválido");
                    }
                }

                _phone = phone.Number.Replace("\0", "").Replace("&#x0", "").Replace("\\0", "").Trim();

                if (phone.PhoneType != PhoneType.Celular)
                {
                    if (!_phone.IsNullorEmpty() && _phone.ClearStrings().Length != 8 && _phone.ClearStrings().Length != 9)
                    {
                        throw new ArgumentException("Número de telefone inválido");
                    }
                }
                else
                {
                    if (!_phone.IsNullorEmpty() && _phone.ClearStrings().Length != 8 && _phone.ClearStrings().Length != 9)
                    {
                        throw new ArgumentException("Número de celular inválido");
                    }
                }
            });
        }