Add new API
Update Salary Swap Sequence
This commit is contained in:
parent
680bfba81e
commit
a4e8b50d45
3 changed files with 196 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Requests.Commands;
|
||||
using BMA.EHR.Domain.Models.Commands.Core;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.Domain.Models.Organizations;
|
||||
|
|
@ -7,6 +8,7 @@ using BMA.EHR.Domain.Shared;
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Transactions;
|
||||
using Command = BMA.EHR.Domain.Models.Commands.Core.Command;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories.Commands
|
||||
|
|
@ -76,6 +78,8 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#endregion
|
||||
|
||||
#region " Command Receiver "
|
||||
|
||||
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
|
||||
{
|
||||
try
|
||||
|
|
@ -167,6 +171,89 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<CommandReceiver?> GetCommandReceiverAsync(Guid personalId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var receiver = await _dbContext.Set<CommandReceiver>()
|
||||
.FirstOrDefaultAsync(x => x.Id == personalId);
|
||||
|
||||
if (receiver == null)
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
||||
return receiver;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task SwapReceiverOrderAsync(Guid personalId, string direction)
|
||||
{
|
||||
try
|
||||
{
|
||||
var current = await _dbContext.Set<CommandReceiver>()
|
||||
.FirstOrDefaultAsync(x => x.Id == personalId);
|
||||
|
||||
if (current == null)
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
||||
var currentSeq = current.Sequence;
|
||||
|
||||
switch (direction.Trim().ToLower())
|
||||
{
|
||||
case "up":
|
||||
{
|
||||
// get prev record
|
||||
var prev = await _dbContext.Set<CommandReceiver>()
|
||||
.OrderByDescending(x => x.Sequence)
|
||||
.Where(x => x.Sequence < currentSeq)
|
||||
.Take(1)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (prev != null)
|
||||
{
|
||||
var prevSeq = prev.Sequence;
|
||||
|
||||
current.Sequence = prevSeq;
|
||||
prev.Sequence = currentSeq;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "down":
|
||||
{
|
||||
// get next record
|
||||
var next = await _dbContext.Set<CommandReceiver>()
|
||||
.OrderBy(x => x.Sequence)
|
||||
.Where(x => x.Sequence > currentSeq)
|
||||
.Take(1)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (next != null)
|
||||
{
|
||||
var nextSeq = next.Sequence;
|
||||
|
||||
current.Sequence = nextSeq;
|
||||
next.Sequence = currentSeq;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: throw new Exception("Invalid swap direction!");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task<List<CommandDeployment>> GetDeploymentByCommandIdAsync(Guid id)
|
||||
{
|
||||
try
|
||||
|
|
@ -473,6 +560,28 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#region " Placement "
|
||||
|
||||
public async Task UpdatePlacementSalaryAsync(Guid placementProfileId, UpdatePlacementSalaryRequest req)
|
||||
{
|
||||
try
|
||||
{
|
||||
var placementProfile = await _dbContext.Set<PlacementProfile>()
|
||||
.FirstOrDefaultAsync(p => p.Id == placementProfileId);
|
||||
|
||||
if (placementProfile == null)
|
||||
throw new Exception($"Invalid placement profile: {placementProfileId}");
|
||||
|
||||
placementProfile.Amount = req.SalaryAmount;
|
||||
placementProfile.PositionSalaryAmount = req.PositionSalaryAmount;
|
||||
placementProfile.MouthSalaryAmount = req.MonthSalaryAmount;
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<PositionPath>> GetPlacementPositionPath(Guid id)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
namespace BMA.EHR.Application.Requests.Commands
|
||||
{
|
||||
public class UpdatePlacementSalaryRequest
|
||||
{
|
||||
public double SalaryAmount { get; set; } = 0;
|
||||
|
||||
public double PositionSalaryAmount { get; set; } = 0;
|
||||
|
||||
public double MonthSalaryAmount { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using Amazon.S3.Model.Internal.MarshallTransformations;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Application.Requests.Commands;
|
||||
using BMA.EHR.Command.Service.Requests;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
|
|
@ -889,6 +890,81 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// บันทึกข้อมูลเงินเดือนสำหรับผู้บรรจุ
|
||||
/// </summary>
|
||||
/// <param name="personalId">Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("salary/{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> UpdatePlacementSalaryAsync(Guid personalId, [FromBody] UpdatePlacementSalaryRequest req)
|
||||
{
|
||||
try
|
||||
{
|
||||
var receiver = await _repository.GetCommandReceiverAsync(personalId);
|
||||
|
||||
if (receiver == null)
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
||||
await _repository.UpdatePlacementSalaryAsync(personalId, req);
|
||||
|
||||
return Success();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สลับลำดับข้อมูลในบัญชีแนบท้ายขึ้น
|
||||
/// </summary>
|
||||
/// <param name="personalId">Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("swap/up/{personalId}")]
|
||||
public async Task<ActionResult<ResponseObject>> SwapUpReceiverOrderAsync(Guid personalId)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _repository.SwapReceiverOrderAsync(personalId, "up");
|
||||
return Success();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สลับลำดับข้อมูลในบัญชีแนบท้ายลง
|
||||
/// </summary>
|
||||
/// <param name="personalId">Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("swap/down/{personalId}")]
|
||||
public async Task<ActionResult<ResponseObject>> SwapDownReceiverOrderAsync(Guid personalId)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _repository.SwapReceiverOrderAsync(personalId, "down");
|
||||
return Success();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue