Add project files.

This commit is contained in:
Suphonchai Phoonsawat 2023-06-05 20:22:51 +07:00
parent cc6b248537
commit 717b0f0a8e
31 changed files with 1296 additions and 0 deletions

View file

@ -0,0 +1,16 @@
using BMA.EHR.Application.Repositories;
using Microsoft.Extensions.DependencyInjection;
namespace BMA.EHR.Application
{
public static class ApplicationServicesRegistration
{
public static IServiceCollection AddApplication(this IServiceCollection services)
{
services.AddTransient<PrefixRepository>();
services.AddTransient<BloodGroupRepository>();
return services;
}
}
}

View file

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BMA.EHR.Domain\BMA.EHR.Domain.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,14 @@
using BMA.EHR.Domain.Entities.MetaData;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Application.Common.Interfaces
{
public interface IApplicationDBContext
{
DbSet<PrefixEntity> Prefixes { get; set; }
DbSet<BloodGroupEntity> BloodGroups { get; set; }
Task<int> SaveChangesAsync();
}
}

View file

@ -0,0 +1,9 @@
namespace BMA.EHR.Application.Common.Interfaces
{
public interface IGenericRepository<S,T> where T : class
{
Task<T?> GetByIdAsync(S id);
Task<IReadOnlyList<T>> GetAllAsync();
}
}

View file

@ -0,0 +1,26 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Entities.MetaData;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Application.Repositories
{
public class BloodGroupRepository : IGenericRepository<Guid, BloodGroupEntity>
{
private readonly IApplicationDBContext _dbContext;
public BloodGroupRepository(IApplicationDBContext dbContext)
{
_dbContext = dbContext;
}
public async Task<IReadOnlyList<BloodGroupEntity>> GetAllAsync()
{
return await _dbContext.BloodGroups.ToListAsync();
}
public async Task<BloodGroupEntity?> GetByIdAsync(Guid id)
{
return await _dbContext.BloodGroups.FirstOrDefaultAsync(x => x.Id == id);
}
}
}

View file

@ -0,0 +1,26 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Entities.MetaData;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Application.Repositories
{
public class PrefixRepository : IGenericRepository<Guid, PrefixEntity>
{
private readonly IApplicationDBContext _dbContext;
public PrefixRepository(IApplicationDBContext dbContext)
{
_dbContext = dbContext;
}
public async Task<IReadOnlyList<PrefixEntity>> GetAllAsync()
{
return await _dbContext.Prefixes.ToListAsync();
}
public async Task<PrefixEntity?> GetByIdAsync(Guid id)
{
return await _dbContext.Prefixes.FirstOrDefaultAsync(x => x.Id == id);
}
}
}