public Account(Account clonedAccount)
 {
     if (clonedAccount == null)
     {
         return;
     }
     CustomAttribute = clonedAccount.CustomAttribute;
     Id = clonedAccount.Id;
     Name = clonedAccount.Name;
     Number = clonedAccount.Number;
     if (clonedAccount.Addresses != null) {
         Addresses = new Addresses(clonedAccount.Addresses);
     }
     if (clonedAccount.PhoneNumbers != null)
     {
         PhoneNumbers = new PhoneNumbers(clonedAccount.PhoneNumbers);
     }
     if (clonedAccount.EmailAddresses != null)
     {
         EmailAddresses = new EmailAddresses(clonedAccount.EmailAddresses);
     }
 }
        public ResponseAccount GetAccountByAccountNumber(AccountNumberRequest req)
        {
            var accountNumber = req.AccountNumber;
            var acc = from account in accounts where account.Number == accountNumber select account;
            if (acc.Count() < 1)
            {
                throw new WebFaultException(HttpStatusCode.NoContent);
            }
            else if (acc.Count() > 1)
            {
                throw new WebFaultException(HttpStatusCode.Conflict);
            }
            ResponseAccount retVal = new ResponseAccount();
            Account retAccount = new Account(acc.FirstOrDefault());

            if (retAccount != null && req.CustomAttribute != null && req.CustomAttribute.Equals("overwrite"))
            {
                retAccount.CustomAttribute = "overwritten custom attribute";
            }

            retVal.Account = retAccount;
            return retVal;
        }
 private Account SQLGetAccount(string query)
 {
     using (SqlConnection connection = new SqlConnection(config.connectionString))
     {
         Account account = new Account();
         SqlCommand command = new SqlCommand(query, connection);
         connection.Open();
         SqlDataReader reader = command.ExecuteReader();
         try
         {
             if (reader.Read())
             {
                 // Loop through a list of contact fields that are configured and add them to the return object
                 foreach (string field in config.accountConfig.fields)
                 {
                     try
                     {
                         account.GetType().GetProperty(field).SetValue(account, reader[field], null);
                     }
                     catch (Exception ex)
                     {
                         throw new WebFaultException<string>(String.Format("Column <{0}> not found in query results: {1}", field, ex.Message), HttpStatusCode.InternalServerError);
                     }
                 }
                 // Get all the phone numbers
                 account.PhoneNumbers = getPhoneNumbers(reader, config.accountConfig.phoneCount, config.accountConfig.phoneMappings);
                 // Get all the email addresses
                 account.EmailAddresses = getEmails(reader, config.accountConfig.emailCount, config.accountConfig.emailMappings);
                 // Get the address
                 if (config.accountConfig.getAddress)
                 {
                     account.Addresses.Address.Add(getAddress(reader, config.accountConfig.addressFields));
                 }
             }
             else
             {
                 throw new WebFaultException<string>("No results found", HttpStatusCode.NoContent);
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             reader.Close();
         }
         return account;
     }
 }