public void CancelLeave()
        {
            _leaveRequestRepository.ApplyLeave(leave);
            var leaves = _leaveRequestRepository.CancelLeave(1);

            Assert.Equal(Condition.Cancel, leaves.Status);
        }
示例#2
0
        /// <summary>
        /// Method to Cancel leave, only allowed to the applier of the leave to cancel the leave
        /// </summary>
        /// <param name="leaveId"></param>
        /// <param name="userName"></param>
        /// <returns>replyText as string</returns>
        private async Task <string> CancelLeave(int leaveId, string userName, string accessToken)
        {
            // get user details from oAuth server
            var user = await _projectUser.GetUserByUsername(userName, accessToken);

            // only authorize user of leave is allowed to cancel there leave
            if (user.Id == _leaveRepository.LeaveById(leaveId).EmployeeId)
            {
                // method to cancel leave
                var leave = _leaveRepository.CancelLeave(leaveId);
                replyText = string.Format("Your leave Id no: {0} From {1} To {2} has been {3}", leave.Id, leave.FromDate.ToShortDateString(), leave.EndDate.Value.ToShortDateString(), leave.Status);
            }
            else
            {
                // if leave doesn't exist or unauthorize trespass try to do
                replyText = string.Format("{0}{1}{2}", _stringConstant.LeaveDoesnotExist, _stringConstant.OrElseString, _stringConstant.CancelLeaveError);
            }
            return(replyText);
        }