From 0b760a253fd14256d781f64cb3d2b6b1b282f6ef Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 24 Dec 2024 05:14:31 +0700 Subject: [PATCH] no message --- .../PositionExecutiveController.cs | 61 ++++++ .../PositionExecutiveSideController.cs | 61 ++++++ .../Controllers/PositionLevelController.cs | 61 ++++++ .../Controllers/PositionLineController.cs | 61 ++++++ .../Controllers/PositionPathController.cs | 61 ++++++ .../Controllers/PositionPathSideController.cs | 61 ++++++ .../Controllers/PositionTypeController.cs | 61 ++++++ BMA.EHR.MetaData.Service/Program.cs | 189 +++++++++--------- .../Services/PositionExecutiveService.cs | 88 ++++++++ .../Services/PositionExecutiveSideService.cs | 89 +++++++++ .../Services/PositionLevelService.cs | 90 +++++++++ .../Services/PositionLineService.cs | 89 +++++++++ .../Services/PositionPathService.cs | 89 +++++++++ .../Services/PositionPathSideService.cs | 89 +++++++++ .../Services/PositionTypeService.cs | 88 ++++++++ 15 files changed, 1147 insertions(+), 91 deletions(-) create mode 100644 BMA.EHR.MetaData.Service/Controllers/PositionExecutiveController.cs create mode 100644 BMA.EHR.MetaData.Service/Controllers/PositionExecutiveSideController.cs create mode 100644 BMA.EHR.MetaData.Service/Controllers/PositionLevelController.cs create mode 100644 BMA.EHR.MetaData.Service/Controllers/PositionLineController.cs create mode 100644 BMA.EHR.MetaData.Service/Controllers/PositionPathController.cs create mode 100644 BMA.EHR.MetaData.Service/Controllers/PositionPathSideController.cs create mode 100644 BMA.EHR.MetaData.Service/Controllers/PositionTypeController.cs create mode 100644 BMA.EHR.MetaData.Service/Services/PositionExecutiveService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/PositionExecutiveSideService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/PositionLevelService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/PositionLineService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/PositionPathService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/PositionPathSideService.cs create mode 100644 BMA.EHR.MetaData.Service/Services/PositionTypeService.cs diff --git a/BMA.EHR.MetaData.Service/Controllers/PositionExecutiveController.cs b/BMA.EHR.MetaData.Service/Controllers/PositionExecutiveController.cs new file mode 100644 index 00000000..21c4f077 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Controllers/PositionExecutiveController.cs @@ -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 " + + /// + /// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetsAsync() + { + try + { + var items = await _positionExecutiveService.GetsAsync(showAll: false); + + return Success(items); + } + catch (Exception ex) + { + return Error(ex); + } + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Controllers/PositionExecutiveSideController.cs b/BMA.EHR.MetaData.Service/Controllers/PositionExecutiveSideController.cs new file mode 100644 index 00000000..c61f1a95 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Controllers/PositionExecutiveSideController.cs @@ -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 " + + /// + /// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetsAsync() + { + try + { + var items = await _positionExecutiveSideService.GetsAsync(showAll: false); + + return Success(items); + } + catch (Exception ex) + { + return Error(ex); + } + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Controllers/PositionLevelController.cs b/BMA.EHR.MetaData.Service/Controllers/PositionLevelController.cs new file mode 100644 index 00000000..09f3b07c --- /dev/null +++ b/BMA.EHR.MetaData.Service/Controllers/PositionLevelController.cs @@ -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 " + + /// + /// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetsAsync() + { + try + { + var items = await _positionLevelService.GetsAsync(showAll: false); + + return Success(items); + } + catch (Exception ex) + { + return Error(ex); + } + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Controllers/PositionLineController.cs b/BMA.EHR.MetaData.Service/Controllers/PositionLineController.cs new file mode 100644 index 00000000..24ada345 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Controllers/PositionLineController.cs @@ -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 " + + /// + /// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetsAsync() + { + try + { + var items = await _positionLineService.GetsAsync(showAll: false); + + return Success(items); + } + catch (Exception ex) + { + return Error(ex); + } + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Controllers/PositionPathController.cs b/BMA.EHR.MetaData.Service/Controllers/PositionPathController.cs new file mode 100644 index 00000000..38caf117 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Controllers/PositionPathController.cs @@ -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 " + + /// + /// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetsAsync() + { + try + { + var items = await _positionPathService.GetsAsync(showAll: false); + + return Success(items); + } + catch (Exception ex) + { + return Error(ex); + } + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Controllers/PositionPathSideController.cs b/BMA.EHR.MetaData.Service/Controllers/PositionPathSideController.cs new file mode 100644 index 00000000..e1e8e628 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Controllers/PositionPathSideController.cs @@ -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 " + + /// + /// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetsAsync() + { + try + { + var items = await _positionPathSideService.GetsAsync(showAll: false); + + return Success(items); + } + catch (Exception ex) + { + return Error(ex); + } + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Controllers/PositionTypeController.cs b/BMA.EHR.MetaData.Service/Controllers/PositionTypeController.cs new file mode 100644 index 00000000..a4cf7052 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Controllers/PositionTypeController.cs @@ -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 " + + /// + /// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetsAsync() + { + try + { + var items = await _positionTypeService.GetsAsync(showAll: false); + + return Success(items); + } + catch (Exception ex) + { + return Error(ex); + } + } + + #endregion + } +} diff --git a/BMA.EHR.MetaData.Service/Program.cs b/BMA.EHR.MetaData.Service/Program.cs index 409512a1..7a34cf83 100644 --- a/BMA.EHR.MetaData.Service/Program.cs +++ b/BMA.EHR.MetaData.Service/Program.cs @@ -19,35 +19,35 @@ using System.Text; var builder = WebApplication.CreateBuilder(args); { - var issuer = builder.Configuration["Jwt:Issuer"]; - var key = builder.Configuration["Jwt:Key"]; + var issuer = builder.Configuration["Jwt:Issuer"]; + var key = builder.Configuration["Jwt:Key"]; - IdentityModelEventSource.ShowPII = true; + IdentityModelEventSource.ShowPII = true; - builder.Services.AddHttpContextAccessor(); + builder.Services.AddHttpContextAccessor(); - builder.Services.AddApiVersioning(opt => - { - opt.DefaultApiVersion = new ApiVersion(1, 0); - opt.AssumeDefaultVersionWhenUnspecified = true; - opt.ReportApiVersions = true; - opt.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(), - new HeaderApiVersionReader("x-api-version"), - new MediaTypeApiVersionReader("x-api-version")); - }); + builder.Services.AddApiVersioning(opt => + { + opt.DefaultApiVersion = new ApiVersion(1, 0); + opt.AssumeDefaultVersionWhenUnspecified = true; + opt.ReportApiVersions = true; + opt.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(), + new HeaderApiVersionReader("x-api-version"), + new MediaTypeApiVersionReader("x-api-version")); + }); - builder.Services.AddVersionedApiExplorer(setup => - { - setup.GroupNameFormat = "'v'VVV"; - setup.SubstituteApiVersionInUrl = true; - }); + builder.Services.AddVersionedApiExplorer(setup => + { + setup.GroupNameFormat = "'v'VVV"; + setup.SubstituteApiVersionInUrl = true; + }); - builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddEndpointsApiExplorer(); - // Authorization - builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(opt => - { + // Authorization + builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(opt => + { opt.RequireHttpsMetadata = false; //false for dev opt.Authority = issuer; opt.TokenValidationParameters = new() @@ -60,104 +60,111 @@ var builder = WebApplication.CreateBuilder(args); IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)) }; }); - builder.Services.AddAuthorization(); + builder.Services.AddAuthorization(); - // use serilog - ConfigureLogs(); - builder.Host.UseSerilog(); + // use serilog + ConfigureLogs(); + builder.Host.UseSerilog(); - // Add config CORS - builder.Services.AddCors(options => options.AddDefaultPolicy(builder => - { - builder - .AllowAnyOrigin() - .AllowAnyMethod() - .AllowAnyHeader() - .SetIsOriginAllowedToAllowWildcardSubdomains(); - })); + // Add config CORS + builder.Services.AddCors(options => options.AddDefaultPolicy(builder => + { + builder + .AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader() + .SetIsOriginAllowedToAllowWildcardSubdomains(); + })); - // Add services to the container. - builder.Services.AddApplication(); - builder.Services.AddPersistence(builder.Configuration); + // Add services to the container. + builder.Services.AddApplication(); + builder.Services.AddPersistence(builder.Configuration); builder.Services.AddTransient(); - builder.Services.AddControllers(options => - { - options.SuppressAsyncSuffixInActionNames = false; - }) - .AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddControllers(options => + { + options.SuppressAsyncSuffixInActionNames = false; + }) + .AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); - builder.Services.AddSwaggerGen(); - builder.Services.ConfigureOptions(); + builder.Services.AddSwaggerGen(); + builder.Services.ConfigureOptions(); - builder.Services.AddHealthChecks(); + builder.Services.AddHealthChecks(); } var app = builder.Build(); { - var apiVersionDescriptionProvider = app.Services.GetRequiredService(); + var apiVersionDescriptionProvider = app.Services.GetRequiredService(); - if (app.Environment.IsDevelopment()) - { - app.UseSwagger(); - app.UseSwaggerUI(options => - { - foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions) - { - options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", - description.GroupName.ToUpperInvariant()); - } - }); - } + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(options => + { + foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions) + { + options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", + description.GroupName.ToUpperInvariant()); + } + }); + } + + app.MapHealthChecks("/health"); - app.MapHealthChecks("/health"); - app.UseHttpsRedirection(); - app.UseCors(); - app.UseAuthentication(); - app.UseAuthorization(); - app.UseDefaultFiles(); - app.UseStaticFiles(); - app.MapControllers(); + app.UseCors(); + app.UseAuthentication(); + app.UseAuthorization(); + app.UseDefaultFiles(); + app.UseStaticFiles(); + app.MapControllers(); app.UseMiddleware(); // apply migrations await using var scope = app.Services.CreateAsyncScope(); - await using var db = scope.ServiceProvider.GetRequiredService(); - await db.Database.MigrateAsync(); + await using var db = scope.ServiceProvider.GetRequiredService(); + await db.Database.MigrateAsync(); - app.Run(); + app.Run(); } void ConfigureLogs() { - var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); - var configuration = new ConfigurationBuilder() - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddJsonFile( - $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", - optional: true) - .Build(); + var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); + var configuration = new ConfigurationBuilder() + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile( + $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", + optional: true) + .Build(); - Log.Logger = new LoggerConfiguration() - .Enrich.FromLogContext() - .MinimumLevel.Error() - .WriteTo.Console() - .Enrich.WithExceptionDetails() - .WriteTo.Elasticsearch(ConfigureElasticSink(configuration, environment ?? "")) - .Enrich.WithProperty("Environment", environment) - .ReadFrom.Configuration(configuration) - .CreateLogger(); + Log.Logger = new LoggerConfiguration() + .Enrich.FromLogContext() + .MinimumLevel.Error() + .WriteTo.Console() + .Enrich.WithExceptionDetails() + .WriteTo.Elasticsearch(ConfigureElasticSink(configuration, environment ?? "")) + .Enrich.WithProperty("Environment", environment) + .ReadFrom.Configuration(configuration) + .CreateLogger(); } ElasticsearchSinkOptions ConfigureElasticSink(IConfigurationRoot configuration, string environment) { - return new ElasticsearchSinkOptions(new Uri(configuration["ElasticConfiguration:Uri"] ?? "")) - { - AutoRegisterTemplate = true, - IndexFormat = $"{Assembly.GetExecutingAssembly()?.GetName()?.Name?.ToLower().Replace(".", "-")}-{environment?.ToLower().Replace(".", "-")}" - }; + return new ElasticsearchSinkOptions(new Uri(configuration["ElasticConfiguration:Uri"] ?? "")) + { + AutoRegisterTemplate = true, + IndexFormat = $"{Assembly.GetExecutingAssembly()?.GetName()?.Name?.ToLower().Replace(".", "-")}-{environment?.ToLower().Replace(".", "-")}" + }; } diff --git a/BMA.EHR.MetaData.Service/Services/PositionExecutiveService.cs b/BMA.EHR.MetaData.Service/Services/PositionExecutiveService.cs new file mode 100644 index 00000000..cf6e2ec8 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/PositionExecutiveService.cs @@ -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> 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 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 + } +} diff --git a/BMA.EHR.MetaData.Service/Services/PositionExecutiveSideService.cs b/BMA.EHR.MetaData.Service/Services/PositionExecutiveSideService.cs new file mode 100644 index 00000000..49bebd5b --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/PositionExecutiveSideService.cs @@ -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> 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 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 + } +} diff --git a/BMA.EHR.MetaData.Service/Services/PositionLevelService.cs b/BMA.EHR.MetaData.Service/Services/PositionLevelService.cs new file mode 100644 index 00000000..2080b88c --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/PositionLevelService.cs @@ -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> 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 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 + } +} diff --git a/BMA.EHR.MetaData.Service/Services/PositionLineService.cs b/BMA.EHR.MetaData.Service/Services/PositionLineService.cs new file mode 100644 index 00000000..6487a338 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/PositionLineService.cs @@ -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> 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 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 + } +} diff --git a/BMA.EHR.MetaData.Service/Services/PositionPathService.cs b/BMA.EHR.MetaData.Service/Services/PositionPathService.cs new file mode 100644 index 00000000..3de70b1c --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/PositionPathService.cs @@ -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> 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 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 + } +} \ No newline at end of file diff --git a/BMA.EHR.MetaData.Service/Services/PositionPathSideService.cs b/BMA.EHR.MetaData.Service/Services/PositionPathSideService.cs new file mode 100644 index 00000000..2f17b057 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/PositionPathSideService.cs @@ -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> 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 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 + } +} diff --git a/BMA.EHR.MetaData.Service/Services/PositionTypeService.cs b/BMA.EHR.MetaData.Service/Services/PositionTypeService.cs new file mode 100644 index 00000000..24b67896 --- /dev/null +++ b/BMA.EHR.MetaData.Service/Services/PositionTypeService.cs @@ -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> 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 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 + } +}