Example #1
0
        private static bool IsPersonDataPresent(Person person)
        {
            if (person == null)
            {
                return false;
            }

            if (string.IsNullOrEmpty(person.CompanyName) &&
                string.IsNullOrEmpty(person.Email) &&
                string.IsNullOrEmpty(person.FirstName) &&
                string.IsNullOrEmpty(person.LastName) &&
                string.IsNullOrEmpty(person.PersonType) &&
                string.IsNullOrEmpty(person.Phone) &&
                person.PersonId == 0)
            {
                return false;
            }

            return true;
        }
        /// <summary>
        /// Populates/hydrates a person object based on data from the database and a columnPrefix
        /// </summary>
        /// <param name="data"></param>
        /// <param name="columnPrefix"></param>
        /// <returns></returns>
        private static Person PopulatePersonFromDataTable(DataTable data, string columnPrefix)
        {
            Person person = null;

            if (data.Rows.Count > 0)
            {
                if (!String.IsNullOrEmpty(data.Rows[0][columnPrefix + "_PersonId"].ToString()))
                {
                    person = new Person();
                    person.PersonId = (int)data.Rows[0][columnPrefix + "_PersonId"];
                    if (data.Columns.Contains(columnPrefix + "_PersonType")) person.PersonType = data.Rows[0][columnPrefix + "_PersonType"].ToString();
                    person.FirstName = data.Rows[0][columnPrefix + "_FirstName"].ToString();
                    person.LastName = data.Rows[0][columnPrefix + "_LastName"].ToString();
                    if (data.Columns.Contains(columnPrefix + "_CompanyName")) person.CompanyName = data.Rows[0][columnPrefix + "_CompanyName"].ToString();
                    person.Email = data.Rows[0][columnPrefix + "_Email"].ToString();
                    person.Phone = data.Rows[0][columnPrefix + "_Phone"].ToString();
                }
            }

            return person;
        }