using Microsoft.Extensions.Configuration;
using SqlSugar;
using System;
using System.Data.SqlClient;
using System.IO;
using System.Linq;

namespace WebAPIBase.Data.DapperORM.Class
{
    public class BaseRepository
    {
        public static IConfigurationRoot Configuration { get; set; }

        public SqlConnection GetSqlConnection(bool open = true)
        {
            IConfigurationBuilder builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json");

            Configuration = builder.Build();

            string cs = Configuration["Logging:AppSettings:ConnectionString"];


            var conn = new SqlConnection(cs);
            if (open) conn.Open();
            return conn;
        }

    }
}
