no message

This commit is contained in:
kittapath 2024-12-24 05:14:31 +07:00
parent b64bf10419
commit 0b760a253f
15 changed files with 1147 additions and 91 deletions

View file

@ -0,0 +1,61 @@
using BMA.EHR.Domain.Common;
using BMA.EHR.MetaData.Service.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
namespace BMA.EHR.MetaData.Service.Controllers
{
[Route("api/v{version:apiVersion}/metadata/position-executive")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("จัดการข้อมูลประเภทตำแหน่ง เพื่อนำไปใช้งานในระบบ")]
public class PositionExecutiveController : BaseController
{
#region " Fields "
private readonly PositionExecutiveService _positionExecutiveService;
#endregion
#region " Constructor and Destructor "
public PositionExecutiveController(PositionExecutiveService positionExecutiveService)
{
_positionExecutiveService = positionExecutiveService;
}
#endregion
#region " Methods "
/// <summary>
/// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetsAsync()
{
try
{
var items = await _positionExecutiveService.GetsAsync(showAll: false);
return Success(items);
}
catch (Exception ex)
{
return Error(ex);
}
}
#endregion
}
}

View file

@ -0,0 +1,61 @@
using BMA.EHR.Domain.Common;
using BMA.EHR.MetaData.Service.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
namespace BMA.EHR.MetaData.Service.Controllers
{
[Route("api/v{version:apiVersion}/metadata/position-executive-side")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("จัดการข้อมูลด้านการบริหาร เพื่อนำไปใช้งานในระบบ")]
public class PositionExecutiveSideController : BaseController
{
#region " Fields "
private readonly PositionExecutiveSideService _positionExecutiveSideService;
#endregion
#region " Constructor and Destructor "
public PositionExecutiveSideController(PositionExecutiveSideService positionExecutiveSideService)
{
_positionExecutiveSideService = positionExecutiveSideService;
}
#endregion
#region " Methods "
/// <summary>
/// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetsAsync()
{
try
{
var items = await _positionExecutiveSideService.GetsAsync(showAll: false);
return Success(items);
}
catch (Exception ex)
{
return Error(ex);
}
}
#endregion
}
}

View file

@ -0,0 +1,61 @@
using BMA.EHR.Domain.Common;
using BMA.EHR.MetaData.Service.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
namespace BMA.EHR.MetaData.Service.Controllers
{
[Route("api/v{version:apiVersion}/metadata/position-level")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("จัดการข้อมูลระดับตำแหน่ง เพื่อนำไปใช้งานในระบบ")]
public class PositionLevelController : BaseController
{
#region " Fields "
private readonly PositionLevelService _positionLevelService;
#endregion
#region " Constructor and Destructor "
public PositionLevelController(PositionLevelService positionLevelService)
{
_positionLevelService = positionLevelService;
}
#endregion
#region " Methods "
/// <summary>
/// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetsAsync()
{
try
{
var items = await _positionLevelService.GetsAsync(showAll: false);
return Success(items);
}
catch (Exception ex)
{
return Error(ex);
}
}
#endregion
}
}

View file

@ -0,0 +1,61 @@
using BMA.EHR.Domain.Common;
using BMA.EHR.MetaData.Service.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
namespace BMA.EHR.MetaData.Service.Controllers
{
[Route("api/v{version:apiVersion}/metadata/position-line")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("จัดการข้อมูลสายงานตำแหน่ง เพื่อนำไปใช้งานในระบบ")]
public class PositionLineController : BaseController
{
#region " Fields "
private readonly PositionLineService _positionLineService;
#endregion
#region " Constructor and Destructor "
public PositionLineController(PositionLineService positionLineService)
{
_positionLineService = positionLineService;
}
#endregion
#region " Methods "
/// <summary>
/// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetsAsync()
{
try
{
var items = await _positionLineService.GetsAsync(showAll: false);
return Success(items);
}
catch (Exception ex)
{
return Error(ex);
}
}
#endregion
}
}

View file

@ -0,0 +1,61 @@
using BMA.EHR.Domain.Common;
using BMA.EHR.MetaData.Service.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
namespace BMA.EHR.MetaData.Service.Controllers
{
[Route("api/v{version:apiVersion}/metadata/position-path")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("จัดการข้อมูลสายงาน เพื่อนำไปใช้งานในระบบ")]
public class PositionPathController : BaseController
{
#region " Fields "
private readonly PositionPathService _positionPathService;
#endregion
#region " Constructor and Destructor "
public PositionPathController(PositionPathService positionPathService)
{
_positionPathService = positionPathService;
}
#endregion
#region " Methods "
/// <summary>
/// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetsAsync()
{
try
{
var items = await _positionPathService.GetsAsync(showAll: false);
return Success(items);
}
catch (Exception ex)
{
return Error(ex);
}
}
#endregion
}
}

View file

@ -0,0 +1,61 @@
using BMA.EHR.Domain.Common;
using BMA.EHR.MetaData.Service.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
namespace BMA.EHR.MetaData.Service.Controllers
{
[Route("api/v{version:apiVersion}/metadata/position-path-side")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("จัดการข้อมูลด้าน/สาขา เพื่อนำไปใช้งานในระบบ")]
public class PositionPathSideController : BaseController
{
#region " Fields "
private readonly PositionPathSideService _positionPathSideService;
#endregion
#region " Constructor and Destructor "
public PositionPathSideController(PositionPathSideService positionPathSideService)
{
_positionPathSideService = positionPathSideService;
}
#endregion
#region " Methods "
/// <summary>
/// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetsAsync()
{
try
{
var items = await _positionPathSideService.GetsAsync(showAll: false);
return Success(items);
}
catch (Exception ex)
{
return Error(ex);
}
}
#endregion
}
}

View file

@ -0,0 +1,61 @@
using BMA.EHR.Domain.Common;
using BMA.EHR.MetaData.Service.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
namespace BMA.EHR.MetaData.Service.Controllers
{
[Route("api/v{version:apiVersion}/metadata/position-type")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("จัดการข้อมูลประเภทตำแหน่ง เพื่อนำไปใช้งานในระบบ")]
public class PositionTypeController : BaseController
{
#region " Fields "
private readonly PositionTypeService _positionTypeService;
#endregion
#region " Constructor and Destructor "
public PositionTypeController(PositionTypeService positionTypeService)
{
_positionTypeService = positionTypeService;
}
#endregion
#region " Methods "
/// <summary>
/// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetsAsync()
{
try
{
var items = await _positionTypeService.GetsAsync(showAll: false);
return Success(items);
}
catch (Exception ex)
{
return Error(ex);
}
}
#endregion
}
}

View file

@ -82,6 +82,13 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddPersistence(builder.Configuration); builder.Services.AddPersistence(builder.Configuration);
builder.Services.AddTransient<HolidayService>(); builder.Services.AddTransient<HolidayService>();
builder.Services.AddTransient<PositionExecutiveService>();
builder.Services.AddTransient<PositionExecutiveSideService>();
builder.Services.AddTransient<PositionLevelService>();
builder.Services.AddTransient<PositionLineService>();
builder.Services.AddTransient<PositionPathService>();
builder.Services.AddTransient<PositionPathSideService>();
builder.Services.AddTransient<PositionTypeService>();
builder.Services.AddControllers(options => builder.Services.AddControllers(options =>
{ {
options.SuppressAsyncSuffixInActionNames = false; options.SuppressAsyncSuffixInActionNames = false;

View file

@ -0,0 +1,88 @@
using System.Security.Claims;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.MetaData.Service.Services
{
public class PositionExecutiveService
{
#region " Fields "
private readonly ApplicationDBContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public PositionExecutiveService(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<PositionExecutive>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.PositionExecutives.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.PositionExecutives.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<PositionExecutive?> GetByIdAsync(Guid id)
{
return await _context.PositionExecutives.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, PositionExecutive updated)
{
var existData = await _context.PositionExecutives.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name || existData.IsActive != updated.IsActive)
{
existData.Name = updated.Name;
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(PositionExecutive 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.PositionExecutives.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -0,0 +1,89 @@
using System.Security.Claims;
using Microsoft.EntityFrameworkCore;
using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Domain.Models.MetaData;
namespace BMA.EHR.MetaData.Service.Services
{
public class PositionExecutiveSideService
{
#region " Fields "
private readonly ApplicationDBContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public PositionExecutiveSideService(ApplicationDBContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
public string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
public string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<PositionExecutiveSide>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.PositionExecutiveSides.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.PositionExecutiveSides.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<PositionExecutiveSide?> GetByIdAsync(Guid id)
{
return await _context.PositionExecutiveSides.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, PositionExecutiveSide updated)
{
var existData = await _context.PositionExecutiveSides.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name || existData.Note != updated.Note || existData.IsActive != updated.IsActive)
{
existData.Name = updated.Name;
existData.IsActive = updated.IsActive;
existData.Note = updated.Note;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(PositionExecutiveSide 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.PositionExecutiveSides.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -0,0 +1,90 @@
using System.Security.Claims;
using Microsoft.EntityFrameworkCore;
using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Domain.Models.MetaData;
namespace BMA.EHR.MetaData.Service.Services
{
public class PositionLevelService
{
#region " Fields "
private readonly ApplicationDBContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public PositionLevelService(ApplicationDBContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
public string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
public string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<PositionLevel>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.PositionLevels.AsQueryable()
.OrderBy(d => d.Level)
.ToListAsync();
else
return await _context.PositionLevels.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Level)
.ToListAsync();
}
public async Task<PositionLevel?> GetByIdAsync(Guid id)
{
return await _context.PositionLevels.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, PositionLevel updated)
{
var existData = await _context.PositionLevels.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name || existData.ShortName != updated.ShortName || existData.Level != updated.Level || existData.IsActive != updated.IsActive)
{
existData.Level = updated.Level;
existData.Name = updated.Name;
existData.ShortName = updated.ShortName;
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(PositionLevel 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.PositionLevels.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -0,0 +1,89 @@
using System.Security.Claims;
using Microsoft.EntityFrameworkCore;
using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Domain.Models.MetaData;
namespace BMA.EHR.MetaData.Service.Services
{
public class PositionLineService
{
#region " Fields "
private readonly ApplicationDBContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public PositionLineService(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<PositionLine>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.PositionLines.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.PositionLines.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<PositionLine?> GetByIdAsync(Guid id)
{
return await _context.PositionLines.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, PositionLine updated)
{
var existData = await _context.PositionLines.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name || existData.IsActive != updated.IsActive)
{
existData.Name = updated.Name;
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(PositionLine 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.PositionLines.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -0,0 +1,89 @@
using System.Security.Claims;
using Microsoft.EntityFrameworkCore;
using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Domain.Models.MetaData;
namespace BMA.EHR.MetaData.Service.Services
{
public class PositionPathService
{
#region " Fields "
private readonly ApplicationDBContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public PositionPathService(ApplicationDBContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
public string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
public string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<PositionPath>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.PositionPaths.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.PositionPaths.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<PositionPath?> GetByIdAsync(Guid id)
{
return await _context.PositionPaths.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, PositionPath updated)
{
var existData = await _context.PositionPaths.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name || existData.Note != updated.Note || existData.IsActive != updated.IsActive)
{
existData.Name = updated.Name;
existData.IsActive = updated.IsActive;
existData.Note = updated.Note;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(PositionPath 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.PositionPaths.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -0,0 +1,89 @@
using System.Security.Claims;
using Microsoft.EntityFrameworkCore;
using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Domain.Models.MetaData;
namespace BMA.EHR.MetaData.Service.Services
{
public class PositionPathSideService
{
#region " Fields "
private readonly ApplicationDBContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public PositionPathSideService(ApplicationDBContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
public string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
public string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<PositionPathSide>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.PositionPathSides.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.PositionPathSides.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<PositionPathSide?> GetByIdAsync(Guid id)
{
return await _context.PositionPathSides.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, PositionPathSide updated)
{
var existData = await _context.PositionPathSides.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name || existData.Note != updated.Note || existData.IsActive != updated.IsActive)
{
existData.Name = updated.Name;
existData.IsActive = updated.IsActive;
existData.Note = updated.Note;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(PositionPathSide 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.PositionPathSides.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -0,0 +1,88 @@
using System.Security.Claims;
using Microsoft.EntityFrameworkCore;
using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Domain.Models.MetaData;
namespace BMA.EHR.MetaData.Service.Services
{
public class PositionTypeService
{
#region " Fields "
private readonly ApplicationDBContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public PositionTypeService(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<PositionType>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.PositionTypes.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.PositionTypes.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<PositionType?> GetByIdAsync(Guid id)
{
return await _context.PositionTypes.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, PositionType updated)
{
var existData = await _context.PositionTypes.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name || existData.IsActive != updated.IsActive)
{
existData.Name = updated.Name;
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(PositionType 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.PositionTypes.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}