private bool IsInactivityTaskAlreadyExists(long componentId, string processName, string activityName, long systemComponentId, ITaskService taskService) { var processEvents = taskService.FindProcessEvents(processName, componentId, systemComponentId); if (string.IsNullOrWhiteSpace(activityName)) { return processEvents.Count() > 0; } else { return processEvents.Where(processEvent => processEvent.ActivityName == activityName).Any(); } }