create project

This commit is contained in:
Kittapath 2023-03-23 12:31:21 +07:00
commit ffeab6a127
196 changed files with 36968 additions and 0 deletions

101
Services/DistrictService.cs Normal file
View file

@ -0,0 +1,101 @@
using System.Security.Claims;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class DistrictService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public DistrictService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<District>> GetsAsync(string provinceId, bool showAll = true)
{
if (showAll)
return await _context.Districts.AsQueryable()
.Where(x => x.Province.Id == Guid.Parse(provinceId))
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.Districts.AsQueryable()
.Where(x => x.Province.Id == Guid.Parse(provinceId))
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<District?> GetByIdAsync(Guid id)
{
return await _context.Districts.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, District updated)
{
var existData = await _context.Districts.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(District inserted, string provinceId)
{
var province = await _context.Provinces.FirstOrDefaultAsync(x => x.Id == Guid.Parse(provinceId));
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
inserted.Province = province;
await _context.Districts.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -0,0 +1,98 @@
using System.Security.Claims;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class EducationLevelService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public EducationLevelService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<EducationLevel>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.EducationLevels.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.EducationLevels.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<EducationLevel?> GetByIdAsync(Guid id)
{
return await _context.EducationLevels.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, EducationLevel updated)
{
var existData = await _context.EducationLevels.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(EducationLevel inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
await _context.EducationLevels.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

98
Services/PrefixService.cs Normal file
View file

@ -0,0 +1,98 @@
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
using System.Security.Claims;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class PrefixService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public PrefixService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<Prefix>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.Prefixes.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.Prefixes.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<Prefix?> GetByIdAsync(Guid id)
{
return await _context.Prefixes.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, Prefix updated)
{
var existData = await _context.Prefixes.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(Prefix inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
await _context.Prefixes.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -0,0 +1,98 @@
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
using System.Security.Claims;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class ProvinceService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public ProvinceService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<Province>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.Provinces.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.Provinces.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<Province?> GetByIdAsync(Guid id)
{
return await _context.Provinces.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, Province updated)
{
var existData = await _context.Provinces.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(Province inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
await _context.Provinces.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -0,0 +1,97 @@
using System.Security.Claims;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Recurit.Exam.Service.Services;
public class RelationshipService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public RelationshipService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<Relationship>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.Relationships.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.Relationships.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<Relationship?> GetByIdAsync(Guid id)
{
return await _context.Relationships.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, Relationship updated)
{
var existData = await _context.Relationships.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(Relationship inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
await _context.Relationships.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}

View file

@ -0,0 +1,98 @@
using System.Security.Claims;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class ReligionService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public ReligionService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<Religion>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.Religions.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.Religions.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<Religion?> GetByIdAsync(Guid id)
{
return await _context.Religions.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, Religion updated)
{
var existData = await _context.Religions.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(Religion inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
await _context.Religions.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -0,0 +1,119 @@
using System.Collections.Immutable;
using System.Security.Claims;
using BMA.EHR.Extensions;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class SubDistrictService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public SubDistrictService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<SubDistrict>> GetsAsync(string districtId, bool showAll = true)
{
if (showAll)
return await _context.SubDistricts.AsQueryable()
.Include(d => d.District)
.Where(x => x.District.Id == Guid.Parse(districtId))
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.SubDistricts.AsQueryable()
.Include(d => d.District)
.Where(x => x.District.Id == Guid.Parse(districtId))
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<SubDistrict?> GetByIdAsync(Guid id)
{
return await _context.SubDistricts.AsQueryable()
.Include(d => d.District)
.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, SubDistrict updated)
{
var existData = await _context.SubDistricts.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
// if (!existData.Compare(updated))
// {
// existData.Name = updated.Name;
// existData.ZipCode = updated.ZipCode;
// existData.IsActive = updated.IsActive;
// existData.LastUpdatedAt = DateTime.Now;
// existData.LastUpdateUserId = UserId ?? "";
// existData.LastUpdateFullName = FullName ?? "";
// await _context.SaveChangesAsync();
// }
if (existData.Name != updated.Name || existData.ZipCode != updated.ZipCode)
{
existData.Name = updated.Name;
existData.ZipCode = updated.ZipCode;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(SubDistrict inserted, string districtId)
{
var district = await _context.Districts.FirstOrDefaultAsync(x => x.Id == Guid.Parse(districtId));
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
inserted.District = district;
await _context.SubDistricts.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}