private Snapshot_ProductHeader CastToProductHeaderSnapshot(ProductHeader productHeader, int licenseProductId)
        {
            var snapshotProductHeader = new Snapshot_ProductHeader();

            snapshotProductHeader.CloneProductHeaderId = (int)productHeader.Id;
            snapshotProductHeader.Title           = productHeader.Title;
            snapshotProductHeader.CatalogueId     = productHeader.CatalogueId;
            snapshotProductHeader.AlbumArtUrl     = productHeader.AlbumArtUrl;
            snapshotProductHeader.DatabaseVersion = productHeader.DatabaseVersion;
            if (productHeader.SoundscanSales != null)
            {
                snapshotProductHeader.SoundscanSales = (int)productHeader.SoundscanSales;
            }
            snapshotProductHeader.MechsPriority     = productHeader.MechsPriority;
            snapshotProductHeader.RelatedLicensesNo = productHeader.RelatedLicensesNo;
            snapshotProductHeader.ArtistRecsId      = (int)productHeader.Artist.id;
            snapshotProductHeader.Artist            = CastToArtistRecsSnapshot(productHeader.Artist);
            if (productHeader.Label != null)
            {
                snapshotProductHeader.LabelId = (int)productHeader.Label.label_id;
                snapshotProductHeader.Label   = CastToLabelSnapshot(productHeader.Label);
            }
            snapshotProductHeader.Configurations = CastToRecsConfigurationsSnapshot(productHeader.Configurations, (int)productHeader.Id, licenseProductId);

            return(snapshotProductHeader);
        }
 public Snapshot_ProductHeader SaveSnapshotProductHeader(Snapshot_ProductHeader snapshotProductHeader)
 {
     using (var context = new DataContext())
     {
         context.Snapshot_ProductHeaders.Add(snapshotProductHeader);
         context.SaveChanges();
         return(snapshotProductHeader);
     }
 }
        private void DeleteAllRecsConfigAndChildrenForProductHeader(Snapshot_ProductHeader productHeader)
        {
            var recConfigs =
                _snapshotRecsConfigurationRepository.GetAllRecsConfigurationsRecordingsForProductHeaderId(
                    productHeader.CloneProductHeaderId);

            if (recConfigs != null)
            {
                foreach (var config in recConfigs)
                {
                    if (config.ConfigurationId != null)
                    {
                        var id = (int)config.ConfigurationId;
                        //Delete Config
                        var config2 =
                            _snapshotConfigurationRepository.GetSnapshotConfigurationByConfigurationId(id);
                        _snapshotConfigurationRepository.DeleteConfigurationSnapshot(config2.SnapshotConfigId);
                    }

                    //Delete LicenseProductConfig if exists
                    if (config.LicenseProductConfigurationId != null)
                    {
                        var id = (int)config.LicenseProductConfigurationId;

                        /* Mechs data, do not delete
                         * var licenseProductConfig =
                         *  _licenseProductConfigurationRepository
                         *      .GetSnapshotLicenseProductConfigurationByLicenseProductConfigurationId(
                         *          id);
                         *
                         * //Delete licenseProductConfiguration
                         * _licenseProductConfigurationRepository.DeleteLicenseProductConfigurationBySnapshot(licenseProductConfig);
                         */
                    }

                    //delete recConfig
                    _snapshotRecsConfigurationRepository.DeleteWorkRecordingByRecordignSnapshotId(
                        config.SnapshotRecsConfigurationId);
                }
            }
        }
        private void DeleteLabelAndAllChuldren(Snapshot_ProductHeader productHeader)
        {
            if (productHeader.LabelId > 0)
            {
                var label = _snapshotLabelRepository.GetSnapshotLabelByLabelId(productHeader.LabelId);

                //labelGroups
                var labelGroups =
                    _snapshotLabelGroupRepository.GetAllALabelGroupsForLabelId(
                        label.CloneLabelId);
                if (labelGroups != null)
                {
                    foreach (var labelGroup in labelGroups)
                    {
                        _snapshotLabelGroupRepository.DeleteLabelGroupByLabelGroupSnapshotId(
                            labelGroup.SnapshotLabelGroupId);
                    }
                }

                //Delete label
                _snapshotLabelRepository.DeleteLabelSnapshotBySnapshotId(label.SnapshotLabelId);
            }
        }