public IHttpActionResult CreateLeaveRequest(LeaveRequestAC leaveRequest) { if (leaveRequest.Type == DomainModel.Models.Type.Compensation) { leaveRequest.CompensationDate = leaveRequest.EndDate; leaveRequest.EndDate = leaveRequest.StartDate; leaveRequest.CompensationStatus = Condition.Pending; } leaveRequest.EmployeeId = User.Identity.GetUserId(); if (leaveRequest.EmployeeId == null) { return(NotFound()); } try { if (ModelState.IsValid) { var body = _leaveRequestRepository.ApplyLeaveRequest(leaveRequest); _leaveRequestRepository.Save(); _emailUtil.ApplyLeave(_employeeRepository.GetEmployeeById(leaveRequest.EmployeeId).Email, body, leaveRequest.TeamLeader); } return(Ok(leaveRequest)); } catch (Exception) { return(BadRequest()); } }