Ejemplo n.º 1
0
        public DTO.Address Save(DTO.Address address, Guid accountCode)
        {
            using (var transaction = Connection.BeginTransaction())
            {
                try
                {
                    if (!address.IsNull())
                    {
                        var newAddress = address.Transfer();

                        var _address = accountService.SaveOrUpdateAddress(newAddress, accountCode) as VO.AddressCustomer;

                        address.AddressCustomerCode = _address.AddressCustomerCode;
                    }
                    else
                    {
                        throw new ArgumentException("É preciso preencher os dados do endereço.");
                    }
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }

            return(address);
        }
Ejemplo n.º 2
0
        private Dictionary <int, List <DTO.Address> > GetAddresses(DO.Requisition requisition)
        {
            string DBAccountsCustomerImport = GetDbAccountsCustomerImport();

            var result = new Dictionary <int, List <DTO.Address> >();

            using (var connection = new SqlConnection(strConnection))
            {
                using (var command = new SqlCommand(string.Format("{0}.[SPRK_AddressList]", DBAccountsCustomerImport), connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@Requisition", requisition.Code);

                    connection.Open();

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var address = new DTO.Address()
                            {
                                ContactName = reader["EndNome"].ToString().Trim(),
                                Type        = GetAddressType(reader["EndTipo"].AsInt()),
                                Purpose     = GetAddressPurposeType(reader["EndFinalidade"].AsInt()),
                                Street      = string.Format("{0} {1}", (StreetTypeEC)reader["EndTipoLogradouro"].AsInt(), reader["EndLogradouro"].ToString().Trim()),
                                Number      = reader["EndNumero"].ToString().Trim(),
                                District    = reader["EndBairro"].ToString().Trim(),
                                City        = reader["EndCidade"].ToString().Trim(),
                                State       = reader["EndEstado"].ToString().Trim(),
                                ZipCode     = reader["EndCEP"].ToString().Trim(),
                                Complement  = reader["EndComplemento"].ToString().Trim(),
                                Country     = reader["EndPais"].ToString().Trim(),
                                Status      = true,
                                Removed     = false
                            };

                            address.Phones = new List <DTO.Phone>();

                            if (!reader["EndDDD1"].ToString().Trim().ClearStrings().IsNullOrWhiteSpace())
                            {
                                address.Phones.Add(new DTO.Phone()
                                {
                                    CodeCountry = address.Country,
                                    DDD         = reader["EndDDD1"].ToString().Trim(),
                                    Number      = reader["EndTelefone1"].ToString().Trim().ClearStrings(),
                                    Extension   = reader["EndRamal1"].ToString().Trim().ClearStrings(),
                                    PhoneType   = PhoneType.Residencial
                                });
                            }

                            if (!reader["EndDDD2"].ToString().Trim().ClearStrings().IsNullOrWhiteSpace())
                            {
                                address.Phones.Add(new DTO.Phone()
                                {
                                    CodeCountry = address.Country,
                                    DDD         = reader["EndDDD2"].ToString().Trim(),
                                    Number      = reader["EndTelefone2"].ToString().Trim().ClearStrings(),
                                    Extension   = reader["EndRamal2"].ToString().Trim().ClearStrings(),
                                    PhoneType   = PhoneType.Comercial
                                });
                            }

                            if (!reader["EndDDD3"].ToString().Trim().ClearStrings().IsNullOrWhiteSpace())
                            {
                                address.Phones.Add(new DTO.Phone()
                                {
                                    CodeCountry = address.Country,
                                    DDD         = reader["EndDDD3"].ToString().Trim(),
                                    Number      = reader["EndTelefone3"].ToString().Trim().ClearStrings(),
                                    Extension   = reader["EndRamal3"].ToString().Trim().ClearStrings(),
                                    PhoneType   = PhoneType.Outros
                                });
                            }

                            if (!reader["EndDDDCelular"].ToString().Trim().ClearStrings().IsNullOrWhiteSpace())
                            {
                                address.Phones.Add(new DTO.Phone()
                                {
                                    CodeCountry = address.Country,
                                    DDD         = reader["EndDDDCelular"].ToString().Trim(),
                                    Number      = reader["EndCelular"].ToString().Trim().ClearStrings().PadLeft(9, '9'),
                                    PhoneType   = PhoneType.Celular
                                });
                            }

                            if (!reader["EndDDDFax"].ToString().Trim().ClearStrings().IsNullOrWhiteSpace())
                            {
                                address.Phones.Add(new DTO.Phone()
                                {
                                    CodeCountry = address.Country,
                                    DDD         = reader["EndDDDFax"].ToString().Trim(),
                                    Number      = reader["EndFax"].ToString().Trim().ClearStrings(),
                                    PhoneType   = PhoneType.Fax
                                });
                            }

                            if (result.ContainsKey(reader["ConCodigo"].AsInt()))
                            {
                                result[reader["ConCodigo"].AsInt()].Add(address);
                            }
                            else
                            {
                                result.Add(reader["ConCodigo"].AsInt(), new List <DTO.Address>()
                                {
                                    address
                                });
                            }
                        }
                    }
                }
            }

            return(result);
        }