/// <summary>
		/// Returns a list of the reset element ids.
		/// </summary>
		/// <param name="record">The record to delete from the database.</param>
		/// <returns>The number of affected records.</returns>
		public CastScheduleResult DeleteProductionCast( RecProductionCast record )
		{
            ProjectManager projectManagerService = new ProjectManager();   
            BedFilter filter = new BedFilter();
            filter.Factory = record.Factory;
            List<string> projectsInvolved = projectManagerService.LoadCastProjects( filter, record.CastId );
            if( null == projectsInvolved )
            {
                return null;
            }

            ProjectManager mgr = new ProjectManager();
            RecElementIdStatusStd std = new RecElementIdStatusStd { Factory = record.Factory, Project = record.Project };
            List<RecElementIdStatusStd> settings = mgr.LoadStandardSettings( std );

			ModelPlanner svc = new ModelPlanner( );
            List<int> deletedIds = svc.LoadElementIds( record.Factory, record.Project, record.CastId );

            // (1) Reset elements
            // Update Status, Note this can be optimized!
            RecProductionCast recProductionCastStatus = new RecProductionCast( record );
            recProductionCastStatus.CastStatus = (int)CastStatus.NoStatus;
            recProductionCastStatus.ElementIdStatus = RecElementIdStatusStd.GetLocalSettingFromGlobalId( settings, recProductionCastStatus.CastStatus).StatusId;
            UpdateStatus( record, recProductionCastStatus, settings );
            // Now reset
			svc.ResetElementProduction( record.Factory, record.Project, record.CastId, 0, false );

            // (2) Delete strands
            RecProductionCastStrand recStrand = new RecProductionCastStrand();
            recStrand.Factory = record.Factory;
            recStrand.Project = record.Factory; // Factory, Factory for productionCast & ProductionCastStrand
            recStrand.CastId = record.CastId;
            recStrand.StrandPos = 0;
            ProjectManager strand = new ProjectManager();
            strand.DeleteProductionCastStrand(recStrand);
            // (3) Now delete the cast Object
            int result = 0;
            // The cast object can be deleted if no elements belong to other projects other that the current one
            if( projectsInvolved.Count == 0 || (projectsInvolved.Count == 1 && projectsInvolved[0].Equals( record.Project ) )  )
            {
                var delete = new ImpactDelete( ImpProductionCast.Instance )
                {
                    Where = 
				{
					{ ImpProductionCast.Factory.Equal( record.Factory )},
					{ ImpProductionCast.Project.Equal( record.Factory )},// Factory, Factory for productionCast & ProductionCastStrand
					{ ImpProductionCast.CastId.Equal( record.CastId )},
				}
                };

                string statement = delete.ToString();

                using( ImpactDatabase database = new ImpactDatabase() )
                {
                    result = database.ExecuteNonQuery( statement );
                }
            }

			return new CastScheduleResult(deletedIds, projectsInvolved);
		}