Ejemplo n.º 1
0
        //protected DatabaseRepository()
        //{
        //    Database = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnect"].ToString());
        //}

        /// <summary>
        /// Create and open an sql connection.
        /// </summary>
        /// <returns>A new open sql connection</returns>
        protected SqlConnection GetConnection()
        {
            Connection = DataBaseProvider.GetSqlConnection();

            if (Connection.State != ConnectionState.Open)
            {
                Connection.Open();
            }

            return(Connection);
        }
Ejemplo n.º 2
0
        public IList <SalesDto> GetAll()
        {
            List <SalesDto> salesList = new List <SalesDto>();

            using (SqlConnection connection = DataBaseProvider.GetSqlConnection())
            {
                using (IDataReader reader = DataBaseProvider.ExecuteCommand <IDataReader>(connection, GETALL, CommandType.StoredProcedure))
                {
                    while (reader.Read())
                    {
                        SalesDto dto = DtoHelper.GetDto <SalesDto>(reader);
                        salesList.Add(dto);
                    }
                }
            }

            return(salesList);
        }