77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
using Azure.Core;
|
|
using CPRNIMS.Domain.Contracts.Inventory;
|
|
using CPRNIMS.Infrastructure.Dto.Inventory;
|
|
using CPRNIMS.Infrastructure.Dto.Inventory.Request;
|
|
using CPRNIMS.WebApi.Security;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Security.Claims;
|
|
|
|
namespace CPRNIMS.WebApi.Controllers.Inventory
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class RISMgmtController : ControllerBase
|
|
{
|
|
private readonly IRIS _risRepo;
|
|
public RISMgmtController(IRIS risRepo) {
|
|
_risRepo = risRepo;
|
|
}
|
|
|
|
[HttpGet("GetRIS")]
|
|
public async Task<IActionResult> GetRIS([FromQuery] RISFilterDto filter, CancellationToken ct)
|
|
{
|
|
var result = await _risRepo.GetPagedAsync(filter,ct);
|
|
|
|
return Ok(result);
|
|
}
|
|
[HttpGet("{id}")]
|
|
public async Task<IActionResult> GetRISById(long id, CancellationToken ct)
|
|
{
|
|
return Ok(await _risRepo.GetByIdAsync(id, ct));
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> CreateRIS([FromBody] CreateRISRequest request,CancellationToken ct)
|
|
{
|
|
var currentUser = User.ToUserClaims();
|
|
if (currentUser == null)
|
|
return BadRequest();
|
|
|
|
if (!ModelState.IsValid)
|
|
return BadRequest(new
|
|
{
|
|
success = false,
|
|
message = "Validation failed.",
|
|
errors = ModelState.Values
|
|
.SelectMany(v => v.Errors)
|
|
.Select(e => e.ErrorMessage)
|
|
});
|
|
|
|
var ris = await _risRepo.CreateAsync(request, currentUser.UserName,ct);
|
|
return Ok(new
|
|
{
|
|
success = true,
|
|
message = $"RIS {ris.RISNo} created successfully.",
|
|
data= ris
|
|
});
|
|
}
|
|
|
|
[HttpPut("ApproveRIS")]
|
|
public async Task<IActionResult> ApproveRIS([FromBody] ApproveRISRequest request, CancellationToken ct)
|
|
{
|
|
var currentUser = User.ToUserClaims();
|
|
if(currentUser == null)
|
|
return BadRequest();
|
|
|
|
await _risRepo.ApproveAsync(request, currentUser.UserName, ct);
|
|
return Ok(new { success = true, message = "RIS approved." });
|
|
}
|
|
[HttpPut("CancelRIS")]
|
|
public async Task<IActionResult> CancelRIS([FromBody] CancelRISRequest request, CancellationToken ct)
|
|
{
|
|
await _risRepo.CancelAsync(request, ct);
|
|
return Ok(new { success = true, message = "RIS cancelled and inventory restored." });
|
|
}
|
|
}
|
|
}
|