public async Task <IBaseResponse> Handle(AddLeaveCommandQuery request, CancellationToken cancellationToken)
        {
            try
            {
                if (!request.IsValid)
                {
                    return(BaseResponse.CreateFail("Invalid request"));
                }
                var employee = await _employeeRepo.GetEmployeeByEmpCode(request.EmpCode);

                if (employee == null)
                {
                    return(BaseResponse.CreateFail("Employee Not Found"));
                }
                var addCommand = CreateDTO(request, employee);
                var result     = await _repo.AddOrUpdateLeave(addCommand);

                return(result ? BaseResponse.CreateSuccess()
                    : BaseResponse.CreateFail("Failed to Save Leave"));
            }
            catch (Exception ex)
            {
                return(BaseResponse.CreateFail(ex.Message));
            }
        }
Пример #2
0
        public async Task <IBaseResponse> Handle(ApproveLeaveCommandQuery request, CancellationToken cancellationToken)
        {
            try
            {
                if (!request.IsValid)
                {
                    return(BaseResponse.CreateFail("Invalid Request"));
                }
                var result = await _repo.UpdateStatus((LeaveStatus)request.Status, request.Id);

                return(result ? BaseResponse.CreateSuccess() :BaseResponse.CreateFail("Failed To Update Leave Status"));
            }
            catch (Exception ex)
            {
                return(BaseResponse.CreateFail(ex.Message));
            }
        }