public async Task Deactivate(Guid planId) { var deactivateTasks = new List <Task>(); using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var plan = uow.PlanRepository.GetById <PlanDO>(planId); if (plan == null) { throw new MissingObjectException($"Plan with Id {planId} doesn't exist"); } plan.PlanState = PlanState.Inactive; uow.SaveChanges(); foreach (var activity in plan.GetDescendants().OfType <ActivityDO>()) { deactivateTasks.Add(_activity.Deactivate(activity)); } _pusherNotifier.NotifyUser(new NotificationMessageDTO { NotificationType = NotificationType.ExecutionStopped, Subject = "Plan Stopped", Message = $"\"{plan.Name}\" has been stopped.", Collapsed = false }, plan.Fr8AccountId); } try { await Task.WhenAll(deactivateTasks); } catch (Exception ex) { throw new Exception("Failed to deactivate plan", ex); } EventManager.PlanDeactivated(planId); }