internal DraftApprenticeship GetDraftApprenticeship(long draftApprenticeshipId)
        {
            var existingDraftApprenticeship = DraftApprenticeships.SingleOrDefault(a => a.Id == draftApprenticeshipId);

            if (existingDraftApprenticeship == null)
            {
                throw new InvalidOperationException($"There is not a draft apprenticeship with id {draftApprenticeshipId} in cohort {Id}");
            }

            return(existingDraftApprenticeship);
        }
        private void CheckIsCompleteForParty(Party party)
        {
            if (!DraftApprenticeships.Any())
            {
                throw new DomainException(nameof(Apprenticeships), $"Cohort must have at least one draft apprenticeship");
            }

            if (party == Party.Employer || party == Party.Provider)
            {
                if (DraftApprenticeships.Any(x => !x.IsCompleteForParty(party)))
                {
                    throw new DomainException(nameof(DraftApprenticeships), $"Cohort must be complete for {party}");
                }
            }
        }
        public void Delete(Party modifyingParty, UserInfo userInfo)
        {
            CheckIsWithParty(modifyingParty);

            StartTrackingSession(UserAction.DeleteCohort, modifyingParty, EmployerAccountId, ProviderId, userInfo);
            ChangeTrackingSession.TrackUpdate(this);
            LastUpdatedOn = DateTime.UtcNow;

            MarkAsDeletedAndEmitCohortDeletedEvent(modifyingParty, userInfo);

            foreach (var draftApprenticeship in DraftApprenticeships.ToArray())
            {
                RemoveDraftApprenticeship(draftApprenticeship);
            }

            ChangeTrackingSession.CompleteTrackingSession();
        }
        public void DeleteDraftApprenticeship(long draftApprenticeshipId, Party modifyingParty, UserInfo userInfo)
        {
            CheckIsWithParty(modifyingParty);

            var draftApprenticeship = DraftApprenticeships.Single(x => x.Id == draftApprenticeshipId);

            StartTrackingSession(UserAction.DeleteDraftApprenticeship, modifyingParty, EmployerAccountId, ProviderId, userInfo);
            ChangeTrackingSession.TrackUpdate(this);

            RemoveDraftApprenticeship(draftApprenticeship);

            LastUpdatedOn = DateTime.UtcNow;
            Approvals     = Party.None;
            ResetTransferSenderRejection();

            if (!DraftApprenticeships.Any())
            {
                MarkAsDeletedAndEmitCohortDeletedEvent(modifyingParty, userInfo);
            }

            ChangeTrackingSession.CompleteTrackingSession();
        }