Add List all Leave Type Controller
This commit is contained in:
parent
8037ad7e1e
commit
130cbb8042
5 changed files with 125 additions and 8 deletions
|
|
@ -2,12 +2,7 @@
|
||||||
using BMA.EHR.Domain.Models.Base;
|
using BMA.EHR.Domain.Models.Base;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BMA.EHR.Application.Repositories.Leaves
|
namespace BMA.EHR.Application.Repositories.Leaves
|
||||||
{
|
{
|
||||||
|
|
@ -60,8 +55,8 @@ namespace BMA.EHR.Application.Repositories.Leaves
|
||||||
{
|
{
|
||||||
if (entity is EntityBase)
|
if (entity is EntityBase)
|
||||||
{
|
{
|
||||||
(entity as EntityBase).CreatedUserId = UserId!;
|
(entity as EntityBase).CreatedUserId = UserId ?? "";
|
||||||
(entity as EntityBase).CreatedFullName = FullName!;
|
(entity as EntityBase).CreatedFullName = FullName ?? "System Administrator";
|
||||||
(entity as EntityBase).CreatedAt = DateTime.Now;
|
(entity as EntityBase).CreatedAt = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,10 @@ namespace BMA.EHR.Infrastructure.Persistence
|
||||||
Id = Guid.Parse(workSheet?.Cells[row, 1]?.GetValue<string>()!),
|
Id = Guid.Parse(workSheet?.Cells[row, 1]?.GetValue<string>()!),
|
||||||
Name = workSheet?.Cells[row, 2]?.GetValue<string>()!,
|
Name = workSheet?.Cells[row, 2]?.GetValue<string>()!,
|
||||||
Code = workSheet?.Cells[row, 3]?.GetValue<string>()!,
|
Code = workSheet?.Cells[row, 3]?.GetValue<string>()!,
|
||||||
|
|
||||||
|
CreatedFullName = "System Administrator",
|
||||||
|
CreatedAt = DateTime.Now,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
await service.AddAsync(inserted);
|
await service.AddAsync(inserted);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
|
@ -66,4 +66,10 @@
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="SeedLeaveData.xlsx">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
96
BMA.EHR.Leave.Service/Controllers/LeaveTypeController.cs
Normal file
96
BMA.EHR.Leave.Service/Controllers/LeaveTypeController.cs
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
using BMA.EHR.Application.Repositories;
|
||||||
|
using BMA.EHR.Application.Repositories.Leaves.LeaveRequests;
|
||||||
|
using BMA.EHR.Domain.Common;
|
||||||
|
using BMA.EHR.Infrastructure.Persistence;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Swashbuckle.AspNetCore.Annotations;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
|
namespace BMA.EHR.Leave.Service.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/v{version:apiVersion}/leave-types")]
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Authorize]
|
||||||
|
[SwaggerTag("API ระบบลงเวลาและการลา (ประเภทการลา)")]
|
||||||
|
public class LeaveTypeController : BaseController
|
||||||
|
{
|
||||||
|
#region " Fields "
|
||||||
|
|
||||||
|
private readonly LeaveTypeRepository _leaveTypeRepository;
|
||||||
|
private readonly LeaveDbContext _context;
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
private readonly UserProfileRepository _userProfileRepository;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region " Constuctor and Destructor "
|
||||||
|
|
||||||
|
public LeaveTypeController(LeaveTypeRepository leaveTypeRepository,
|
||||||
|
LeaveDbContext context,
|
||||||
|
IHttpContextAccessor httpContextAccessor,
|
||||||
|
IWebHostEnvironment hostingEnvironment,
|
||||||
|
IConfiguration configuration,
|
||||||
|
UserProfileRepository userProfileRepository)
|
||||||
|
{
|
||||||
|
_leaveTypeRepository = leaveTypeRepository;
|
||||||
|
_context = context;
|
||||||
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
_hostingEnvironment = hostingEnvironment;
|
||||||
|
_configuration = configuration;
|
||||||
|
_userProfileRepository = userProfileRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region " Properties "
|
||||||
|
|
||||||
|
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
|
||||||
|
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||||
|
|
||||||
|
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||||
|
|
||||||
|
private Guid OcId
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (UserId != null || UserId != "")
|
||||||
|
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||||
|
else
|
||||||
|
return Guid.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region " Methods "
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List รายการประเภทการลา
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// </returns>
|
||||||
|
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> GetAllAsync()
|
||||||
|
{
|
||||||
|
var leaveTypes = (await _leaveTypeRepository.GetAllAsync()).AsQueryable()
|
||||||
|
.OrderBy(l => l.Code)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return Success(leaveTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
16
BMA.EHR.Leave.Service/DTOs/LeaveTypes/CreateLeaveTypeDto.cs
Normal file
16
BMA.EHR.Leave.Service/DTOs/LeaveTypes/CreateLeaveTypeDto.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace BMA.EHR.Leave.Service.DTOs.LeaveTypes
|
||||||
|
{
|
||||||
|
public class CreateLeaveTypeDto
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public Guid Id { get; set; } = Guid.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Code { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue