98 lines
2.5 KiB
C#
98 lines
2.5 KiB
C#
using System;
|
|
using HRM.BO;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace HRM.UI.Controllers.CommonInterface
|
|
{
|
|
[ApiController]
|
|
[Route("api/virtualGrid")]
|
|
[Authorize]
|
|
public class VirtualGridController : ControllerBase
|
|
{
|
|
private readonly IVirtualGridService _virtualGridService;
|
|
|
|
public VirtualGridController(IVirtualGridService virtualGridService)
|
|
{
|
|
_virtualGridService = virtualGridService;
|
|
}
|
|
|
|
[HttpGet("layout/{gridKey}")]
|
|
public ActionResult GetLayout(string gridKey)
|
|
{
|
|
try
|
|
{
|
|
return Ok(_virtualGridService.GetLayout(gridKey, GetContext()));
|
|
}
|
|
catch (ArgumentException e)
|
|
{
|
|
return BadRequest(e.Message);
|
|
}
|
|
catch (UnauthorizedAccessException e)
|
|
{
|
|
return StatusCode(StatusCodes.Status403Forbidden, e.Message);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
}
|
|
|
|
[HttpPost("page")]
|
|
public ActionResult GetPage(VirtualGridRequest request)
|
|
{
|
|
try
|
|
{
|
|
return Ok(_virtualGridService.GetPage(request, GetContext()));
|
|
}
|
|
catch (ArgumentException e)
|
|
{
|
|
return BadRequest(e.Message);
|
|
}
|
|
catch (UnauthorizedAccessException e)
|
|
{
|
|
return StatusCode(StatusCodes.Status403Forbidden, e.Message);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
}
|
|
|
|
[HttpPost("export-excel")]
|
|
public ActionResult ExportExcel(VirtualGridExportRequest request)
|
|
{
|
|
try
|
|
{
|
|
VirtualGridFile file = _virtualGridService.ExportExcel(request, GetContext());
|
|
return File(file.Content, file.ContentType, file.FileName);
|
|
}
|
|
catch (ArgumentException e)
|
|
{
|
|
return BadRequest(e.Message);
|
|
}
|
|
catch (UnauthorizedAccessException e)
|
|
{
|
|
return StatusCode(StatusCodes.Status403Forbidden, e.Message);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
}
|
|
|
|
private VirtualGridContext GetContext()
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
return new VirtualGridContext
|
|
{
|
|
UserID = currentUser.UserID,
|
|
EmployeeID = currentUser.EmployeeID,
|
|
PayrollTypeID = currentUser.PayrollTypeID,
|
|
UserType = currentUser.UserType,
|
|
};
|
|
}
|
|
}
|
|
}
|