private static Walkin CreateWalkingFromDataset(string walkInId, WalkinDataset ds)
    {
        Walkin walkIn = new Walkin();

        WalkinDataset.WalkinRow walkInRow = (WalkinDataset.WalkinRow)ds.Walkin.Rows[0];
        walkIn.FirstName        = walkInRow.FirstName;
        walkIn.LastName         = walkInRow.LastName;
        walkIn.MiddleInitial    = walkInRow.MiddleInitial;
        walkIn.SSNumber         = walkInRow.SSNumber;
        walkIn.MotherMaidenName = walkInRow.MotherMaidenName;

        new WalkinAddressTableAdapter().Fill(ds.WalkinAddress, walkInId);
        if (ds.WalkinAddress.Rows.Count > 0)
        {
            List <Address> addresses = new List <Address>();
            foreach (WalkinDataset.WalkinAddressRow addressRow in ds.WalkinAddress.Rows)
            {
                Address address = new Address();
                addresses.Add(address);
                address.Address1      = addressRow.Address1;
                address.Address2      = addressRow.IsAddress2Null() ? null : addressRow.Address2;
                address.AddressType   = addressRow.Type;
                address.City          = addressRow.City;
                address.CountryCode   = addressRow.Country;
                address.PostalZipCode = addressRow.PostalZipCode;
                address.StateProvince = addressRow.StateProvince;
            }
            walkIn.Addresses = addresses.ToArray();
        }

        new WalkinEmailAddressTableAdapter().Fill(ds.WalkinEmailAddress, walkInId);
        if (ds.WalkinEmailAddress.Rows.Count > 0)
        {
            List <EmailAddress> emails = new List <EmailAddress>();
            foreach (WalkinDataset.WalkinEmailAddressRow emailRow in ds.WalkinEmailAddress.Rows)
            {
                EmailAddress email = new EmailAddress();
                emails.Add(email);
                email.EmailAddress1 = emailRow.EmailAddress;
                email.Type          = emailRow.Type;
            }
            walkIn.EmailAddresses = emails.ToArray();
        }

        new WalkinPhoneNumberTableAdapter().Fill(ds.WalkinPhoneNumber, walkInId);
        if (ds.WalkinPhoneNumber.Rows.Count > 0)
        {
            List <PhoneNumber> phones = new List <PhoneNumber>();
            foreach (WalkinDataset.WalkinPhoneNumberRow phoneRow in ds.WalkinPhoneNumber.Rows)
            {
                PhoneNumber phone = new PhoneNumber();
                phones.Add(phone);
                phone.PhoneNumber1 = phoneRow.PhoneNumber;
                phoneRow.Type      = phoneRow.Type;
            }
            walkIn.PhoneNumbers = phones.ToArray();
        }
        return(walkIn);
    }
    public void QueueWalkin(Walkin walkIn, string reason, string description)
    {
        using (SqlConnection conn = CreateConnection())
        {
            conn.Open();
            using (SqlTransaction transaction = conn.BeginTransaction())
            {
                string walkInId = CreateWalkin(walkIn, conn, transaction);

                CreateQueueEntry(
                    String.Format("{0} {1} {2}", walkIn.FirstName, walkIn.MiddleInitial, walkIn.LastName),
                    null, walkInId, DateTime.Now,
                    _defaultStatus, reason, description,
                    conn, transaction);

                transaction.Commit();
            }
        }
    }
    private Walkin[] LookupWalkin(string walkInId)
    {
        using (SqlConnection conn = CreateConnection())
        {
            conn.Open();
            WalkinDataset ds = new WalkinDataset();

            new WalkinTableAdapter().Fill(ds.Walkin, walkInId);
            if (ds.Walkin.Rows.Count == 0)
            {
                return(new Walkin[0]);
            }

            Walkin walkIn = CreateWalkingFromDataset(walkInId, ds);

            return(new Walkin[1] {
                walkIn
            });
        }
    }
    private string CreateWalkin(Walkin walkIn, SqlConnection conn, SqlTransaction transaction)
    {
        string     walkInId        = Guid.NewGuid().ToString();
        SqlCommand cmdCreateWalkin = new SqlCommand("sp_CreateWalkin", conn, transaction);

        cmdCreateWalkin.CommandType = CommandType.StoredProcedure;
        cmdCreateWalkin.Parameters.AddWithValue("@WalkinId", walkInId);
        cmdCreateWalkin.Parameters.AddWithValue("@FirstName", walkIn.FirstName);
        cmdCreateWalkin.Parameters.AddWithValue("@LastName", walkIn.LastName);
        cmdCreateWalkin.Parameters.AddWithValue("@MiddleInitial", walkIn.MiddleInitial ?? _notAvailable);
        cmdCreateWalkin.Parameters.AddWithValue("@SSNumber", walkIn.SSNumber ?? _defaultSSN);
        cmdCreateWalkin.Parameters.AddWithValue("@MotherMaidenName", walkIn.MotherMaidenName ?? _notAvailable);
        cmdCreateWalkin.Parameters.AddWithValue("@CustomerLevel", walkIn.CustomerLevel ?? _defaultCustomerLevel);
        cmdCreateWalkin.ExecuteNonQuery();

        if (walkIn.Addresses != null && walkIn.Addresses.Length > 0)
        {
            SqlCommand cmdCreateAddress = GetCreateWalkinAddressCommand(conn, transaction);

            foreach (Address address in walkIn.Addresses)
            {
                cmdCreateAddress.Parameters["@WalkinId"].Value = walkInId;
                cmdCreateAddress.Parameters["@Type"].Value     = address.AddressType;
                cmdCreateAddress.Parameters["@Address1"].Value = address.Address1 ?? _notAvailable;
                if (!String.IsNullOrEmpty(address.Address2))
                {
                    cmdCreateAddress.Parameters["@Address2"].Value = address.Address2;
                }
                cmdCreateAddress.Parameters["@StateProvince"].Value = address.StateProvince ?? _notAvailable;
                cmdCreateAddress.Parameters["@City"].Value          = address.City ?? _notAvailable;
                cmdCreateAddress.Parameters["@Country"].Value       = address.CountryCode ?? _notAvailable;
                cmdCreateAddress.Parameters["@PostalZipCode"].Value = address.PostalZipCode ?? _notAvailable;
                cmdCreateAddress.ExecuteNonQuery();
            }
        }

        if (walkIn.EmailAddresses != null && walkIn.EmailAddresses.Length > 0)
        {
            SqlCommand cmdCreateEmailAddress = GetCreateWalkinEmailAddressCommand(conn, transaction);

            foreach (EmailAddress email in walkIn.EmailAddresses)
            {
                cmdCreateEmailAddress.Parameters["@WalkinId"].Value     = walkInId;
                cmdCreateEmailAddress.Parameters["@Type"].Value         = email.Type ?? "Personal";
                cmdCreateEmailAddress.Parameters["@EmailAddress"].Value = email.EmailAddress1 ?? _notAvailable;
                cmdCreateEmailAddress.ExecuteNonQuery();
            }
        }

        if (walkIn.PhoneNumbers != null && walkIn.PhoneNumbers.Length > 0)
        {
            SqlCommand cmdCreatePhoneNumber = GetCreateWalkinPhoneNumberCommand(conn, transaction);
            foreach (PhoneNumber phone in walkIn.PhoneNumbers)
            {
                cmdCreatePhoneNumber.Parameters["@WalkinId"].Value    = walkInId;
                cmdCreatePhoneNumber.Parameters["@Type"].Value        = phone.PhoneType;
                cmdCreatePhoneNumber.Parameters["@PhoneNumber"].Value = phone.PhoneNumber1 ?? _notAvailable;
                cmdCreatePhoneNumber.ExecuteNonQuery();
            }
        }

        return(walkInId);
    }