Skip to content

Commit

Permalink
feat: dbContext in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
eroskarsburg committed May 8, 2024
1 parent 68a748b commit 50c1b4d
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 6 deletions.
21 changes: 21 additions & 0 deletions MindCare-Central-Clinic/Controllers/PatientController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Mvc;

namespace MindCare_Central_Clinic.Controllers
{
public class PatientController : Controller
{
private readonly ILogger<PatientController> _logger;

public PatientController(ILogger<PatientController> logger)
{
_logger = logger;
}

public IActionResult Index()
{


return View();
}
}
}
6 changes: 6 additions & 0 deletions MindCare-Central-Clinic/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"sql": "Server=myServer;Database=myDb1;Trusted_Connection=True;",
"mysql": "Server=myServer;Database=myDb2;Trusted_Connection=True;",
"oracle": "Server=myServer;Database=myDb2;Trusted_Connection=True;",
"phpmyadmin": "Server=myServer;Database=myDb2;Trusted_Connection=True;"
},
"AllowedHosts": "*"
}
6 changes: 0 additions & 6 deletions MindCare.Application/DataAccess/Class1.cs

This file was deleted.

48 changes: 48 additions & 0 deletions MindCare.Application/DataAccess/DbContext/DbConnectionFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.Extensions.Configuration;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.Common;
using System.Data.Entity.Infrastructure;

namespace MindCare.Application.DataAccess.DbContext
{
public class DbConnectionFactory : IDbConnectionFactory
{
private readonly IConfiguration _configuration;


public DbConnectionFactory(IConfiguration configuration) => _configuration = configuration;

public DbContext ObterContexto(string AppSettingsSection)
{
IConfigurationSection configuracaoSessao = _configuration.GetSection(AppSettingsSection);
AppSettingsDbConfiguracao configSessao = new();
configuracaoSessao.Bind(configSessao);

IDbConnection dbConnection;
ISQLCommands sqlCommands;
ISQLQuerys sqlQuerys;

switch (configSessao.TipoBanco)
{
case EnumDbConnection.MySQL:
dbConnection = new MySqlConnection(configSessao.ConnectionString);
sqlQuerys = new MySQLQuerys();
sqlCommands = new MySQLCommands();
break;
default:
throw new NotImplementedException();
}

return new DbContext(dbConnection, sqlQuerys, sqlCommands);
}
}

public enum EnumDbConnection
{
SQL,
MySQL,
Oracle,
PhpMyAdmin
}
}
20 changes: 20 additions & 0 deletions MindCare.Application/DataAccess/DbContext/DbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Extensions.Configuration;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;
using System.Data;

namespace MindCare.Application.DataAccess.DbContext
{
public class DbContext
{
public IDbConnection connection;
public ISQLQuerys sqlQuery;
public ISQLCommands sqlCommand;
public DbContext(IDbConnection connection, ISQLQuerys siapQuery, ISQLCommands siapCommand)
{
this.connection = connection ?? throw new ArgumentNullException(nameof(DbContext.connection));
this.sqlQuery = siapQuery ?? throw new ArgumentNullException(nameof(sqlQuery));
this.sqlCommand = siapCommand ?? throw new ArgumentNullException(nameof(sqlCommand));
}
}
}
9 changes: 9 additions & 0 deletions MindCare.Application/DataAccess/DbContext/IDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.Extensions.Configuration;

namespace MindCare.Application.DataAccess.DbContext
{
public interface IDbContext
{
public string Initialize(DbConnType conn);
}
}
23 changes: 23 additions & 0 deletions MindCare.Application/DataAccess/Repository/PatientRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using MindCare.Application.DataAccess.DbContext;
using MindCare.Application.Entities;
using System.Data.Common;

namespace MindCare.Application.DataAccess.Repository
{
public class PatientRepository
{
private readonly IDbContext _dbContext;
private readonly DbConnection _connection;

public PatientRepository(IDbContext dbContext)
{
_dbContext = dbContext.Initialize();
}

public async IEnumerable<Patient> Select(Patient obj)
{
var newObj =

Check failure on line 19 in MindCare.Application/DataAccess/Repository/PatientRepository.cs

View workflow job for this annotation

GitHub Actions / build

Invalid expression term 'return'

Check failure on line 19 in MindCare.Application/DataAccess/Repository/PatientRepository.cs

View workflow job for this annotation

GitHub Actions / build

; expected

Check failure on line 19 in MindCare.Application/DataAccess/Repository/PatientRepository.cs

View workflow job for this annotation

GitHub Actions / build

Invalid expression term 'return'

Check failure on line 19 in MindCare.Application/DataAccess/Repository/PatientRepository.cs

View workflow job for this annotation

GitHub Actions / build

; expected
return await

Check failure on line 20 in MindCare.Application/DataAccess/Repository/PatientRepository.cs

View workflow job for this annotation

GitHub Actions / build

Invalid expression term '}'

Check failure on line 20 in MindCare.Application/DataAccess/Repository/PatientRepository.cs

View workflow job for this annotation

GitHub Actions / build

; expected

Check failure on line 20 in MindCare.Application/DataAccess/Repository/PatientRepository.cs

View workflow job for this annotation

GitHub Actions / build

Invalid expression term '}'

Check failure on line 20 in MindCare.Application/DataAccess/Repository/PatientRepository.cs

View workflow job for this annotation

GitHub Actions / build

; expected
}
}
}
6 changes: 6 additions & 0 deletions MindCare.Application/MindCare.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="MySql.Data" Version="8.4.0" />
</ItemGroup>

</Project>

0 comments on commit 50c1b4d

Please sign in to comment.