using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using HRM.BO; namespace HRM.UI.Controllers.Payroll { [Route("api/UnAuthLeave")] [ApiController] public class UnAuthLeaveController : ControllerBase { private readonly IEmployeeUnAuthorizeLeaveService _employeeUnAuthorizeLeaveService; private readonly IUnAuthorizeLeaveService _unAuthorizeLeaveService; private readonly IUnAuthorizeLeaveParamService _unAuthorizeLeaveParamService; public UnAuthLeaveController(IEmployeeUnAuthorizeLeaveService employeeUnAuthorizeLeaveService, IUnAuthorizeLeaveService unAuthorizeLeaveService, IUnAuthorizeLeaveParamService unAuthorizeLeaveParamService) { this._employeeUnAuthorizeLeaveService = employeeUnAuthorizeLeaveService; this._unAuthorizeLeaveService = unAuthorizeLeaveService; this._unAuthorizeLeaveParamService = unAuthorizeLeaveParamService; } [HttpPost] [Route("deleteAllEmployeeUnAuthorizeLeave")] public ActionResult DeleteAllEmployeeUnAuthorizeLeave(List employeeUnAuthorizeLeaves) { try { _employeeUnAuthorizeLeaveService.DeleteAll(employeeUnAuthorizeLeaves); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("saveEmployeeUnAuthorizeLeave")] public ActionResult SaveEmployeeUnAuthorizeLeave(EmployeeUnAuthorizeLeave employeeUnAuthorizeLeave) { CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); int id=0; try { if (employeeUnAuthorizeLeave.IsNew) { employeeUnAuthorizeLeave.CreatedBy = ouser.UserID; employeeUnAuthorizeLeave.CreatedDate = DateTime.Today; } else { employeeUnAuthorizeLeave.ModifiedBy = ouser.UserID; employeeUnAuthorizeLeave.ModifiedDate = DateTime.Today; } employeeUnAuthorizeLeave.MonthDate = (DateTime)ouser.NextPayProcessDate; employeeUnAuthorizeLeave.IsLateAttendanceRelated = false; employeeUnAuthorizeLeave.PayrollTypeID = (int) ouser.PayrollTypeID; id = _employeeUnAuthorizeLeaveService.Save(employeeUnAuthorizeLeave); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(id); } [HttpPost] [Route("deleteEmployeeUnAuthorizeLeaveById")] public ActionResult DeleteEmployeeUnAuthorizeLeaveById(EmployeeUnAuthorizeLeave item) { try { _employeeUnAuthorizeLeaveService.Delete(item.ID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("saveEmployeeUnAuthorizeLeaveList")] public ActionResult SaveEmployeeUnAuthorizeLeaveList(List employeeUnAuthorizeLeaves) { try { _employeeUnAuthorizeLeaveService.Save(employeeUnAuthorizeLeaves); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("saveAuthorizeLeave")] public ActionResult SaveAuthorizeLeave(int employeeId) { DateTime month = new DateTime(); List items = new List(); try { _employeeUnAuthorizeLeaveService.SaveAuthorizeLeave(employeeId, month, items); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("adjustDaysById")] public ActionResult AdjustDaysById(int id) { try { _employeeUnAuthorizeLeaveService.AdjustedDays(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("adjustDaysByIdAndMonth")] public ActionResult AdjustDaysByIdAndMonth(int id) { DateTime month = new DateTime(); try { _employeeUnAuthorizeLeaveService.AdjustedDays(id, month); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("getEmployeeUnAuthorizeLeaveById/{id}")] public ActionResult GetEmployeeUnAuthorizeLeaveById(int id) { EmployeeUnAuthorizeLeave employeeUnAuthorizeLeave = new EmployeeUnAuthorizeLeave(); try { employeeUnAuthorizeLeave = _employeeUnAuthorizeLeaveService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(employeeUnAuthorizeLeave); } [HttpGet("getEmployeeUnAuthorizeLeave/{empid}/{salarymonth}")] public ActionResult getEmployeeUnAuthorizeLeave( string empid, string salaryMonth) { DateTime? smonth = GlobalFunctions.GetApiDefaultDateData(salaryMonth); int? employeeid = GlobalFunctions.GetApiDefaultIntData(empid); List employeeUnAuthorizeLeave = new List(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { employeeUnAuthorizeLeave = _employeeUnAuthorizeLeaveService.Get((int) ouser.PayrollTypeID, smonth, employeeid); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(employeeUnAuthorizeLeave); } [HttpGet("getAllUnAuthorizeLeave")] public ActionResult GetAllUnAuthorizeLeave() { List unAuthorizeLeaves = new List(); try { unAuthorizeLeaves = _unAuthorizeLeaveService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(unAuthorizeLeaves); } [HttpGet("getUnAuthorizeLeaveByCode/{code}")] public ActionResult GetUnAuthorizeLeaveByCode(string code) { UnAuthorizeLeave unAuthorizeLeave = new UnAuthorizeLeave(); try { unAuthorizeLeave = _unAuthorizeLeaveService.Get(code); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(unAuthorizeLeave); } [HttpPost] [Route("saveUnAuthorizeLeave")] public ActionResult SaveUnAuthorizeLeave(UnAuthorizeLeave unAuthorizeLeave) { try { _unAuthorizeLeaveService.Save(unAuthorizeLeave); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteUnAuthorizeLeave")] public ActionResult DeleteUnAuthorizeLeave(int id) { try { _unAuthorizeLeaveService.Delete(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("getUaLeaveUsedParamGrade/{ualeaveid}")] public ActionResult getUaLeaveUsedParamGrade(int ualeaveid) { List employeeUnAuthorizeLeave = new List(); try { employeeUnAuthorizeLeave = _unAuthorizeLeaveParamService.GetUsedGrades(ualeaveid); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(employeeUnAuthorizeLeave); } //[HttpGet("getAllUnAuthorizeLeaveParamDetail")] //public ActionResult GetAllUnAuthorizeLeaveParamDetail() //{ // CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); // List unAuthorizeLeaveParams = new List(); // try // { // unAuthorizeLeaveParams = _unAuthorizeLeaveParameterService.Get(); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(unAuthorizeLeaveParams); //} //[HttpGet("getUnAuthorizeLeaveParamDetailByLeaveParamId/{leaveParamId}")] //public ActionResult GetUnAuthorizeLeaveParamDetailByLeaveParamId(int leaveParamId) //{ // List unAuthorizeLeaveParams = new List(); // try // { // unAuthorizeLeaveParams = _unAuthorizeLeaveParameterService.GetDetail(leaveParamId); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(unAuthorizeLeaveParams); //} // UnAuthorizeLeaveParam [HttpGet("getUnAuthorizeLeaveParamById/{id}")] public ActionResult GetUnAuthorizeLeaveParamById(int id) { UnAuthorizeLeaveParam unAuthorizeLeaveParam = new UnAuthorizeLeaveParam(); try { unAuthorizeLeaveParam = _unAuthorizeLeaveParamService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(unAuthorizeLeaveParam); } [HttpGet("getAllUnAuthorizeLeaveParam")] public ActionResult GetAllUnAuthorizeLeaveParam() { CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); List unAuthorizeLeaveParams = new List(); try { unAuthorizeLeaveParams = _unAuthorizeLeaveParamService.Get((int)ouser.PayrollTypeID, true); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(unAuthorizeLeaveParams); } [HttpGet("getUnAuthorizeLeaveParamByGrade/{GradeID}")] public ActionResult getUnAuthorizeLeaveParamByGrade(int GradeID) { CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); List unAuthorizeLeaveParams = new List(); try { unAuthorizeLeaveParams = _unAuthorizeLeaveParamService.GetByGrade(GradeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(unAuthorizeLeaveParams); } [HttpGet("getUnAuthorizeLeaveParamListByLeaveId/{leaveId}")] public ActionResult GetUnAuthorizeLeaveParamListByLeaveId(int leaveId) { List unAuthorizeLeaveParams = new List(); try { unAuthorizeLeaveParams = _unAuthorizeLeaveParamService.GetByLeaveID(leaveId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(unAuthorizeLeaveParams); } [HttpPost] [Route("saveUnAuthorizeLeaveParam")] public ActionResult SaveUnAuthorizeLeaveParam(UnAuthorizeLeaveParam item) { CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); int id = 0; try { if (item.IsNew) { item.CreatedBy = ouser.UserID; item.CreatedDate = DateTime.Today; } else { item.ModifiedBy = ouser.UserID; item.ModifiedDate = DateTime.Today; } item.PayrollTypeID = (int)ouser.PayrollTypeID; _unAuthorizeLeaveParamService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteUnAuthorizeLeaveParam")] public ActionResult DeleteUnAuthorizeLeaveParam(UnAuthorizeLeaveParam param) { try { _unAuthorizeLeaveParamService.Delete(param.ID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } } }