/// <summary>
        /// Creates a cohort with a draft apprenticeship
        /// </summary>
        internal Cohort(long providerId,
                        long accountId,
                        long accountLegalEntityId,
                        long?transferSenderId,
                        DraftApprenticeshipDetails draftApprenticeshipDetails,
                        Party originatingParty,
                        UserInfo userInfo) : this(providerId, accountId, accountLegalEntityId, transferSenderId, originatingParty, userInfo)
        {
            CheckDraftApprenticeshipDetails(draftApprenticeshipDetails);
            ValidateDraftApprenticeshipDetails(draftApprenticeshipDetails, false);
            WithParty  = originatingParty;
            EditStatus = originatingParty.ToEditStatus();
            IsDraft    = true;

            var draftApprenticeship = new DraftApprenticeship(draftApprenticeshipDetails, originatingParty);

            Apprenticeships.Add(draftApprenticeship);

            Publish(() => new DraftApprenticeshipCreatedEvent(draftApprenticeship.Id, Id, draftApprenticeship.Uln, draftApprenticeship.ReservationId, draftApprenticeship.CreatedOn.Value));

            StartTrackingSession(UserAction.CreateCohort, originatingParty, accountId, providerId, userInfo);
            ChangeTrackingSession.TrackInsert(this);
            ChangeTrackingSession.TrackInsert(draftApprenticeship);
            ChangeTrackingSession.CompleteTrackingSession();
        }
        public virtual void UpdateChangeOfPartyRequest(DraftApprenticeship draftApprenticeship, long employerAccountId, long providerId, UserInfo userInfo, Party modifyingParty)
        {
            StartTrackingSession(UserAction.UpdateChangeOfPartyRequest, modifyingParty, employerAccountId, providerId, userInfo);
            ChangeTrackingSession.TrackUpdate(this);

            Price     = (int?)draftApprenticeship.Cost;
            StartDate = draftApprenticeship.StartDate;
            EndDate   = draftApprenticeship.EndDate;

            ChangeTrackingSession.CompleteTrackingSession();
        }
 private void RemoveDraftApprenticeship(DraftApprenticeship draftApprenticeship)
 {
     ChangeTrackingSession.TrackDelete(draftApprenticeship);
     LastUpdatedOn = DateTime.UtcNow;
     Apprenticeships.Remove(draftApprenticeship);
     Publish(() => new DraftApprenticeshipDeletedEvent
     {
         DraftApprenticeshipId = draftApprenticeship.Id,
         CohortId      = draftApprenticeship.CommitmentId,
         Uln           = draftApprenticeship.Uln,
         ReservationId = draftApprenticeship.ReservationId,
         DeletedOn     = DateTime.UtcNow
     });
 }
        public virtual bool IsApprovedByAllParties => WithParty == Party.None; //todo: use new Approvals flag

        public DraftApprenticeship AddDraftApprenticeship(DraftApprenticeshipDetails draftApprenticeshipDetails, Party creator, UserInfo userInfo)
        {
            CheckIsWithParty(creator);
            ValidateDraftApprenticeshipDetails(draftApprenticeshipDetails, false);

            StartTrackingSession(UserAction.AddDraftApprenticeship, creator, EmployerAccountId, ProviderId, userInfo);
            ChangeTrackingSession.TrackUpdate(this);

            var draftApprenticeship = new DraftApprenticeship(draftApprenticeshipDetails, creator);

            Apprenticeships.Add(draftApprenticeship);
            Approvals = Party.None;
            UpdatedBy(creator, userInfo);
            LastUpdatedOn = DateTime.UtcNow;

            ChangeTrackingSession.TrackInsert(draftApprenticeship);
            ChangeTrackingSession.CompleteTrackingSession();

            Publish(() => new DraftApprenticeshipCreatedEvent(draftApprenticeship.Id, Id, draftApprenticeship.Uln, draftApprenticeship.ReservationId, draftApprenticeship.CreatedOn.Value));
            return(draftApprenticeship);
        }
        public DraftApprenticeship CreateCopyForChangeOfParty(ChangeOfPartyRequest changeOfPartyRequest, Guid?reservationId)
        {
            var result = new DraftApprenticeship
            {
                FirstName         = this.FirstName,
                LastName          = this.LastName,
                DateOfBirth       = this.DateOfBirth,
                Cost              = changeOfPartyRequest.Price,
                StartDate         = changeOfPartyRequest.StartDate,
                EndDate           = changeOfPartyRequest.EndDate,
                Uln               = this.Uln,
                CourseCode        = this.CourseCode,
                CourseName        = this.CourseName,
                ProgrammeType     = this.ProgrammeType,
                EmployerRef       = changeOfPartyRequest.ChangeOfPartyType == ChangeOfPartyRequestType.ChangeEmployer ? string.Empty : this.EmployerRef,
                ProviderRef       = changeOfPartyRequest.ChangeOfPartyType == ChangeOfPartyRequestType.ChangeProvider ? string.Empty : this.ProviderRef,
                ReservationId     = reservationId,
                ContinuationOfId  = Id,
                OriginalStartDate = OriginalStartDate ?? StartDate
            };

            return(result);
        }