using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using AutoMapper; using HRM.BO; using HRM.DA; using HRM.UI.DTOs.Training; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace HRM.UI.Controllers { [ApiController] [Route("api/ADParameter")] [Authorize] public class ADParameterController : ControllerBase { IADParameterService _adparameter; IADParameterEmployeeService _adparamEmp; IAllowanceDeductionService _allowdeduct; public ADParameterController(IADParameterService adparameter, IADParameterEmployeeService adparamEmp, IAllowanceDeductionService allowdeduct) { this._adparameter = adparameter; this._adparamEmp = adparamEmp; this._allowdeduct = allowdeduct; } // GET: // [HttpPost] [Route("SaveAdParam")] public ActionResult SaveAdParam(ADParameter oitem) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { oitem.CreatedBy = currentUser.UserID; oitem.CreatedDate = DateTime.Now; oitem.PayrollTypeID = (int) currentUser.PayrollTypeID; this._adparameter.Save(oitem); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpPost] [Route("DeleteParam")] public ActionResult DeleteParam(ADParameter oitem) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { this._adparameter.Delete(oitem.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpPost] [Route("changeStatus")] public ActionResult changeStatus(ADParameter oitem) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); oitem.ModifiedBy = currentUser.UserID; oitem.ModifiedDate = DateTime.Now; EnumStatus sts = EnumStatus.Active; if(oitem.IsCurrentlyActive == false) { sts = EnumStatus.Inactive; } try { this._adparameter.ChangeStatus(oitem.ID, sts); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpPost] [Route("SaveAdParamEmployee")] public ActionResult SaveAdParamEmployee(ADParameterEmployee oitem) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { oitem.CreatedBy = currentUser.UserID; oitem.CreatedDate = DateTime.Now; oitem.ID = this._adparamEmp.Save(oitem, GlobalFunctions.LastPayProcessDate((DateTime) currentUser.NextPayProcessDate)); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(oitem.ID); } [HttpPost] [Route("UpdateAdParamEmpAmountAndDate")] public ActionResult UpdateAdParamEmpAmountAndDate(ADParameterEmployee oitem) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { oitem.ModifiedBy = currentUser.UserID; oitem.ModifiedDate = DateTime.Now; this._adparamEmp.UpdateAmountAndDate(oitem); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpPost] [Route("DeleteAdParamEmployee")] public ActionResult DeleteAdParamEmployee(ADParameterEmployee oitem) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { this._adparamEmp.Delete(oitem.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpGet("GetParams/{status}/{type}")] public ActionResult GetParams(EnumStatus status, EnumAllowOrDeduct type) { List adprams = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { adprams = this._adparameter.Get(status, type, (int)currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(adprams); } [HttpGet("GetParam/{adparameterID}")] public ActionResult GetParam(int adparameterID) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); ADParameter adpram = null; try { adpram = this._adparameter.Get(adparameterID, (int) currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(adpram); } [HttpGet("GetByGradeNType/{GradeID}/{EntitleType}/{AllowOrDeductType}")] public ActionResult GetByGradeNType(int GradeID, EnumEntitleType EntitleType, EnumAllowOrDeduct AllowOrDeductType) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List adprams = null; try { adprams = this._adparameter.Get(GradeID, EntitleType, AllowOrDeductType, (int) currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(adprams); } [HttpGet("GetADPramEmp/{EmployeeID}/{allowdeductType}/{adempType}")] public ActionResult GetADPramEmp(int EmployeeID, EnumAllowOrDeduct allowdeductType, EnumADEmpType adempType) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List returnItems = null; try { returnItems = this._adparamEmp.GetByEmployee(EmployeeID, allowdeductType, adempType, (int) currentUser.PayrollTypeID, (DateTime) currentUser.NextPayProcessDate); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(returnItems); } [HttpGet("GetGradesOfAllowDeduct/{AllowDeductID}")] public ActionResult GetGradesOfAllowDeduct(int AllowDeductID) { List adprams = null; try { adprams = this._adparameter.GetUsedGrades(AllowDeductID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(adprams); } [HttpGet("GetAllowDeductByPeriodicity/{status}/{AllowOrDeductType}/{periodicity}")] public ActionResult GetAllowDeductByPeriodicity(EnumStatus status, EnumAllowOrDeduct AllowOrDeductType,EnumPeriodicity periodicity) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List returnItems = null; try { returnItems = new AllowanceDeductionService().Get((int)currentUser.PayrollTypeID, EnumStatus.Active, AllowOrDeductType, periodicity); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(returnItems); } [HttpGet("GetMonthyIndividualAndOneOff/{status}/{AllowOrDeductType}")] public ActionResult GetMonthyIndividualAndOneOff(EnumStatus status, EnumAllowOrDeduct AllowOrDeductType) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List returnItems = null; try { returnItems = new AllowanceDeductionService().GetMonthyIndividualAndOneOff((int)currentUser.PayrollTypeID, EnumStatus.Active, AllowOrDeductType); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(returnItems); } [HttpGet("GetAllowDeductByGradeID/{GradeID}/{AllowOrDeductType}")] public ActionResult GetAllowDeductByGradeID(int Gradeid, EnumAllowOrDeduct AllowOrDeductType) { List returnItems = null; try { returnItems = this._allowdeduct.GetByGradeID(EnumStatus.Active, Gradeid, AllowOrDeductType); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(returnItems); } } }