EchoTex_Payroll/HRM.UI/Controllers/Ess/EssController.cs

179 lines
5.6 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using HRM.BO;
using HRM.BO.ess;
using Microsoft.AspNetCore.Authorization;
using static iTextSharp.text.pdf.AcroFields;
using HRM.DA.Fund;
using System.Data;
using HRM.Report;
using Ease.Core.DataAccess;
namespace HRM.UI.Controllers.Ess
{
[Route("api/Ess")]
[ApiController]
[Authorize]
public class EssController : ControllerBase
{
private readonly IProfileUpdateRequestService _profileUpdateRequestService;
public EssController(IProfileUpdateRequestService profileUpdateRequestService)
{
this._profileUpdateRequestService = profileUpdateRequestService;
}
[HttpPost]
[Route("savePUR")]
public ActionResult SaveEmployee(ProfileUpdateRequest item)
{
int ans;
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
item.RequestEmpID = currentUser.EmployeeID.GetValueOrDefault();
try
{
ans = _profileUpdateRequestService.Save(item);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(ans);
}
[HttpPost]
[Route("updateEmployee")]
public ActionResult UpdateEmployee(ProfileUpdateRequest item)
{
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
item.currentUserId = currentUser.UserID;
_profileUpdateRequestService.UpdateEmployee(item);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("updateEmployeeRequestBulk")]
public ActionResult UpdateEmployeeRequestBulk(List<ProfileUpdateRequest> items)
{
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
items.ForEach(x =>
{
x.currentUserId = currentUser.UserID;
_profileUpdateRequestService.UpdateEmployee(x);
});
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("rejectEmployeeRequestBulk")]
public ActionResult RejectEmployeeRequestBulk(List<ProfileUpdateRequest> items)
{
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int currentUserId = currentUser.UserID;
var ids = string.Join(",", items.Select(x => x.ID));
_profileUpdateRequestService.RejectEmployeeRequestBulk(ids, currentUserId, DateTime.Now);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getAllPURByEmpId")]
public ActionResult GetAllPURByEmpId()
{
List<ProfileUpdateRequest> items = new List<ProfileUpdateRequest>();
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int empId = currentUser.EmployeeID.GetValueOrDefault();
try
{
items = _profileUpdateRequestService.GetAllByEmpId(empId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getPURByEmpIdAndStatus/{status}")]
public ActionResult GetPURByEmpIdAndStatus(EnumPURequestStatus status)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int empId = currentUser.EmployeeID.GetValueOrDefault();
int ans;
try
{
ans = _profileUpdateRequestService.GetPURCountEmpIdAndStatus(empId, status);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(ans);
}
[HttpGet("getAllPUR")]
public ActionResult GetAllPUR()
{
List<ProfileUpdateRequest> items = new List<ProfileUpdateRequest>();
try
{
items = _profileUpdateRequestService.GetAll();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("updateStatusToRejected")]
public ActionResult UpdateStatusToRejected(ProfileUpdateRequest item)
{
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
item.currentUserId = currentUser.UserID;
_profileUpdateRequestService.UpdateStatusToRejected(item);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
}
}