using System; using System.Collections.Generic; using HRM.BO; using HRM.DA; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace HRM.UI.Controllers.Adhoc_feature { [Route("api/AdhocFeature")] [ApiController] [Authorize] public class AdhocFeatureController : ControllerBase { private readonly IADParameterEmployeeService _adParameterEmployeeService; private readonly IApproveFinantialDataService _approveFinancialDataService; public AdhocFeatureController(IADParameterEmployeeService adParameterEmployeeService, IApproveFinantialDataService approveFinancialDataService) { _adParameterEmployeeService = adParameterEmployeeService; _approveFinancialDataService = approveFinancialDataService; } [HttpGet("getAllFinancialData")] public ActionResult GetAllFinancialData() { List items = new List(); try { items = _approveFinancialDataService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpPost("getAdParamEmpForApproval")] public ActionResult GetAdParamEmpForApproval(dynamic data) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); int itemId = (int)items["id"].ToObject(); DateTime fromDate = (DateTime)items["fromDate"].ToObject(); DateTime toDate = (DateTime)items["toDate"].ToObject(); List adParameterEmployees = new List(); try { adParameterEmployees = _adParameterEmployeeService.GetForApproval(itemId, fromDate, toDate, payrollTypeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(adParameterEmployees); } [HttpPost("getAllFinancialDataByType")] public ActionResult GetAllFinancialDataByType(dynamic data) { var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); int selectedDataType = (int)items["selectedDataType"].ToObject(); ApproveFinantialDataService service = new ApproveFinantialDataService(); List finantialData = new List(); try { finantialData = service.GetByType(selectedDataType); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(finantialData); } [HttpGet("getByAllowForApproval/{allowDeductId}")] public ActionResult GetByAllowForApproval(int allowDeductId) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollId = currentUser.PayrollTypeID.GetValueOrDefault(); List items = new List(); try { items = _adParameterEmployeeService.GetByAllowForApproval(allowDeductId, payrollId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpPost("saveFinancialDataList")] public ActionResult SaveFinancialDataList(List items) { try { _approveFinancialDataService.Save(items); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpPost("deleteFinancialDataList")] public ActionResult DeleteFinancialDataList(List items) { try { _approveFinancialDataService.Delete(items); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } } }