Exemplo n.º 1
0
        public int UpdateContact(ContactEntity contact)
        {
            int result = 0;

            try
            {
                CommandTxt = SP_Contacts_U_contact;
                OpenConnection();
                SqlCommand dbCommand = new SqlCommand(CommandTxt, Connection);
                dbCommand.CommandType = CommandType.StoredProcedure;
                dbCommand.Parameters.AddWithValue("@iId", contact.Id);
                dbCommand.Parameters.AddWithValue("@iEmail", contact.Email);
                dbCommand.Parameters.AddWithValue("@iFirstName", contact.FirstName);
                dbCommand.Parameters.AddWithValue("@iLastName", contact.LastName);
                dbCommand.Parameters.AddWithValue("@iPhoneNumber", contact.PhoneNumber);
                dbCommand.Parameters.AddWithValue("@iStatus", contact.Status);
                result = dbCommand.ExecuteNonQuery();
                Connection.Close();
                return(result);
            }
            catch (Exception ex)
            {
                Connection.Close();
                return(result);
            }
        }
Exemplo n.º 2
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);
            }
        }