public async Task <Result> Handle(CreateLeaveCommand request, CancellationToken cancellationToken) { var leaveRequestResult = await _leaveService.CheckLeave(request); if (!leaveRequestResult.CanUseLeave) { return(Result.Failure("İzin bulunamadı.")); } if (leaveRequestResult.LeaveCount == 0) { return(Result.Failure("Bu tarihte izin kullanılmasına gerek yok.")); } var entity = new LeaveRequest { LeaveDay = leaveRequestResult.LeaveCount, EmployeeId = request.EmployeeId, LeaveType = request.LeaveType, LeaveStatus = CalculateLeaveStatus(request, leaveRequestResult) }; _context.LeaveRequests.Add(entity); await _context.SaveChangesAsync(cancellationToken); if (entity.LeaveStatus == LeaveStatus.Approved) { await _leaveService.ApproveLeave(leaveRequestResult.Id, leaveRequestResult.LeaveCount, cancellationToken); _notificationService.SendNotification(request.EmployeeId, "İzin onaylandı."); } else { _notificationService.SendNotification(request.EmployeeId, "İzin Yönetici onayında."); } return(Result.Success(entity.Id)); }