102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
using CPRNIMS.Domain.UIContracts.Account;
|
|
using CPRNIMS.Domain.UIContracts.Inventory;
|
|
using CPRNIMS.Infrastructure.Dto.Inventory.Request;
|
|
using CPRNIMS.Infrastructure.Helper;
|
|
using CPRNIMS.WebApps.Controllers.Base;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CPRNIMS.WebApps.Controllers.Inventory
|
|
{
|
|
public class RISMgmtController : BaseMethod
|
|
{
|
|
private readonly IRIS _ris;
|
|
public RISMgmtController(ErrorLogHelper errorMessageService,
|
|
IWebHostEnvironment webHostEnvironment, TokenHelper tokenHelper
|
|
, IRIS ris, IAccount account)
|
|
: base(errorMessageService, webHostEnvironment, tokenHelper, account)
|
|
{
|
|
_ris = ris;
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> CreateRIS([FromBody] CreateRISRequest request,CancellationToken ct)
|
|
{
|
|
var result = await _ris.CreateRIS(request,ct);
|
|
|
|
return Json(new { success = true, message= $"RIS {result.RISNo} created successfully.", data = result });
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> ApproveRIS([FromBody] ApproveRISRequest request,CancellationToken ct)
|
|
{
|
|
bool isSuccess = await _ris.ApproveRIS(request, ct);
|
|
|
|
if (!isSuccess)
|
|
return BadRequest(new { success = false, message = "RIS cancelled failed" });
|
|
|
|
return Ok(new
|
|
{
|
|
success = true,
|
|
message = $"RIS approved successfully."
|
|
});
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> CancelRIS([FromBody] CancelRISRequest request,CancellationToken ct)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.Reason))
|
|
return BadRequest(new
|
|
{
|
|
success = false,
|
|
message = "A reason for cancellation is required."
|
|
});
|
|
bool isSuccess = await _ris.CancelRIS(request,ct);
|
|
|
|
if (!isSuccess)
|
|
return BadRequest(new { success = false, message = "RIS cancelled failed" });
|
|
|
|
return Ok(new
|
|
{
|
|
success = true,
|
|
message = "RIS cancelled and inventory restored."
|
|
});
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetRIS(
|
|
[FromQuery] string? searchRISNo,string? searchItemName,string? searchIssuedTo,string? discipline,string? status,
|
|
int pageNumber = 1,int pageSize = 12,CancellationToken ct = default)
|
|
{
|
|
short? statusCode = status switch
|
|
{
|
|
"0" => 0,
|
|
"1" => 1,
|
|
"2" => 2,
|
|
_ => null
|
|
};
|
|
|
|
var result = await _ris.GetRISPaged(new RISPagedRequest
|
|
{
|
|
SearchRISNo = searchRISNo,
|
|
SearchItemName = searchItemName,
|
|
SearchIssuedTo = searchIssuedTo,
|
|
Discipline = discipline,
|
|
Status = statusCode,
|
|
PageNumber = pageNumber,
|
|
PageSize = pageSize
|
|
}, ct);
|
|
|
|
return Json(new
|
|
{
|
|
data = result.Data,
|
|
recordsTotal = result.RecordsTotal,
|
|
departmentList = result.DepartmentList,
|
|
disciplineList = result.DisciplineList
|
|
});
|
|
}
|
|
public async Task<IActionResult> GetRISById(int risId, CancellationToken ct)
|
|
{
|
|
var response = await _ris.GetRISById(risId,ct);
|
|
return GetResponse(response);
|
|
}
|
|
}
|
|
}
|