Example #1
0
        public ContactEntity GetContactById(int Id)
        {
            ContactEntity        contactEntity  = new ContactEntity();
            ContactEntityBuilder contactBuilder = new ContactEntityBuilder();

            try
            {
                CommandTxt = SP_Contacts_G_ById_contact;

                OpenConnection();
                SqlCommand dbCommand = new SqlCommand(CommandTxt, Connection);
                dbCommand.CommandType = CommandType.StoredProcedure;
                dbCommand.Parameters.AddWithValue("@iId", Id);
                using (SqlDataReader reader = dbCommand.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        if (reader.Read())
                        {
                            contactEntity = contactBuilder.BuildEntity(reader);
                        }
                    }
                }
                Connection.Close();
                return(contactEntity);
            }
            catch (Exception ex)
            {
                return(contactEntity);
            }
        }
Example #2
0
        public List <ContactEntity> GetAllContact()
        {
            List <ContactEntity> lstContactEntity = null;
            ContactEntityBuilder contactBuilder   = new ContactEntityBuilder();

            try
            {
                CommandTxt = SP_Contacts_G_ALL_contact;
                OpenConnection();
                SqlCommand dbCommand = new SqlCommand(CommandTxt, Connection);
                dbCommand.CommandType = CommandType.StoredProcedure;
                using (SqlDataReader dataReader = dbCommand.ExecuteReader())
                {
                    lstContactEntity = contactBuilder.BuildEntities(dataReader);
                }
                Connection.Close();
                return(lstContactEntity);
            }
            catch (Exception ex)
            {
                return(lstContactEntity);
            }
        }