matthewaustinbell / TimeManagement

0 stars 0 forks source link

16. then create an Ienumerable of Employee and add the connection string, dapper Using statement in EmployeeProvider.cs #14

Open matthewaustinbell opened 4 years ago

matthewaustinbell commented 4 years ago

create an IEnumerable of Employee and add the connection string, dapper Using statement in EmployeeProvider.cs


using System.Data.SqlClient;
using Dapper;
using TimeManagement.Data;

namespace TimeManagement.Data
{
    public class EmployeeProvider : IEmployeeProvider
    {
        private readonly string connectionString;

        public EmployeeProvider(string connectionString)
        {
            this.connectionString = connectionString;
        }

        public IEnumerable<Employee> Get()
        {
            IEnumerable<Employee> employee = null;

            using (var connection = new SqlConnection(connectionString))
            {
                employee = connection.Query<Employee>(
                    "select id, first_name as FirstName, last_name as LastName, address, home_phone as HomePhone, cell_phone as CellPhone from Employee");
            }

            return employee;
        }
    }
}