Beispiel #1
0
        [Route("api/v1/leave/status/update")] // leave approve and reject
        public HttpResponseMessage GetApproval(LeaveStatusModel leave_status)
        {
            HttpResponseMessage response = null;
            Leave leave = LeaveRepo.GetLeaveById(leave_status.leave_id);

            try
            {
                if (leave_status.is_approved == Constants.LEAVE_STATUS_APPROVED)
                {
                    leave.leave_statusid = Constants.LEAVE_STATUS_APPROVED;
                    LeaveRepo.EditLeave(leave);

                    response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Leave Approved", "Leave Approved"));
                }
                else if (leave_status.is_approved == Constants.LEAVE_STATUS_REJECTED || leave_status.is_approved == Constants.LEAVE_STATUS_CANCELLED)
                {
                    Leavebalance_sheet leave_balance_instance = LeaveRepo.LeaveBalanceById(leave.employee_id, leave.leavetype_id);
                    string             leave_type_name        = LeaveRepo.GetLeaveTypeById(leave.leavetype_id);

                    #region CL and ML
                    if (leave_type_name == Constants.LEAVE_TYPE_CL || leave_type_name == Constants.LEAVE_TYPE_ML)
                    {
                        leave_balance_instance.no_of_days = leave_balance_instance.no_of_days + leave.no_of_days;
                    }
                    #endregion

                    #region EL
                    else if (leave_type_name == Constants.LEAVE_TYPE_EL)
                    {
                        //if (leave.EL_flag > 0)
                        //{
                        //    int LOP_leave_type_id = LeaveRepo.GetLeavetypeIdByLeavetype(Constants.LEAVE_TYPE_LOP);
                        //    Leavebalance_sheet lop_balance_instance = LeaveRepo.LeaveBalanceById(leave.employee_id, LOP_leave_type_id);
                        //    leave_balance_instance.no_of_days = (decimal)leave.EL_flag;
                        //    lop_balance_instance.no_of_days =(decimal)(lop_balance_instance.no_of_days - (decimal)(leave.no_of_days - leave.EL_flag));
                        //    LeaveRepo.UpdateLeaveBalanceSheet(lop_balance_instance);
                        //}
                        //else
                        {
                            leave_balance_instance.no_of_days = leave_balance_instance.no_of_days + leave.no_of_days;
                        }
                    }
                    #endregion

                    #region LOP and WFH
                    else if (leave_type_name == Constants.LEAVE_TYPE_LOP || leave_type_name == Constants.LEAVE_TYPE_WFH)
                    {
                        leave_balance_instance.no_of_days = leave_balance_instance.no_of_days - leave.no_of_days;
                    }
                    #endregion

                    LeaveRepo.UpdateLeaveBalanceSheet(leave_balance_instance);

                    if (leave_status.is_approved == Constants.LEAVE_STATUS_CANCELLED)
                    {
                        if ((leave.from_date <= DateTime.Now.Date) || (DateTime.Now.Date >= leave.to_date))
                        {
                            response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_517", "Future leaves can only be cancelled", "Future leaves can only be cancelled"));
                            return(response);
                        }
                        else
                        {
                            leave.leave_statusid = Constants.LEAVE_STATUS_CANCELLED;
                            LeaveRepo.EditLeave(leave);
                            response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Leave Cancelled", "Leave Cancelled"));
                        }
                    }
                    if (leave_status.is_approved == Constants.LEAVE_STATUS_REJECTED)
                    {
                        leave.leave_statusid = Constants.LEAVE_STATUS_REJECTED;
                        LeaveRepo.EditLeave(leave);
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Leave Rejected", "Leave Rejected"));
                    }
                }
                ReportingTo reporting_to = EmployeeRepo.GetReportingtoByEmpId(leave.employee_id);
                Employee    employee     = EmployeeRepo.GetEmployeeById(leave.employee_id);
                MailHandler.LeaveMailing(leave.from_date, leave.to_date, employee.first_name, leave.leave_statusid, employee.email, reporting_to.mailid, leave_status.remarks, reporting_to.emp_name);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(response);
        }