Exemplo n.º 1
0
        public static List <CompanyEntity> GetAllCompanies()
        {
            try
            {
                SqlCommand command = new SqlCommand("Company_GetAll", connection);
                command.CommandType = CommandType.StoredProcedure;

                connection.Open();
                SqlDataReader reader   = command.ExecuteReader();
                var           entities = new List <CompanyEntity>();
                while (reader.Read())
                {
                    var record = new CompanyEntity(reader.GetString(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5));
                    entities.Add(record);
                }
                connection.Close();

                return(entities);
            }
            catch (Exception)
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
                throw;
            }
        }
Exemplo n.º 2
0
        public static string AddCompany(CompanyEntity companyEntity)
        {
            try
            {
                SqlCommand command = new SqlCommand("Company_Add", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("@Id", companyEntity.Id);
                command.Parameters.AddWithValue("@Name", companyEntity.Name);
                command.Parameters.AddWithValue("@Address", companyEntity.Address);
                command.Parameters.AddWithValue("@Www", companyEntity.Www);
                command.Parameters.AddWithValue("@Nip", companyEntity.Nip);
                command.Parameters.AddWithValue("@Phone", companyEntity.Phone);

                connection.Open();
                command.ExecuteNonQuery();
                connection.Close();

                return("Company record added!");
            }
            catch (Exception ex)
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
                return(ex.Message.ToString());
            }
        }