smartstore / SmartStoreNET

Open Source ASP.NET MVC Enterprise eCommerce Shopping Cart Solution
http://www.smartstore.com/en/net
GNU General Public License v3.0
2.64k stars 1.46k forks source link

remove media file in ver 4.x.x #2179

Closed pineportal closed 3 years ago

pineportal commented 3 years ago

after upload file IsTransient is true; how to change in false?

image

pineportal commented 3 years ago

i am add this code. But the image is deleted automatically

 public class CarouselAlbumProvider : IAlbumProvider, IMediaTrackDetector
    {
        public const string Name = "carousel";

        private readonly CarouselObjectContext _dbContext;

        public CarouselAlbumProvider(CarouselObjectContext dbContext)
        {
            _dbContext = dbContext;
        }

        public IEnumerable<MediaAlbum> GetAlbums()
        {
            MediaAlbum album = new MediaAlbum()
            {
                Name = "carousel",
                ResKey = "Plugins.FriendlyName.SmartPlugins.Carousel",
                CanDetectTracks = true
            };
            yield return album;
        }

        public AlbumDisplayHint GetDisplayHint(MediaAlbum album)
        {
            return null;
        }

        public void ConfigureTracks(string albumName, TrackedMediaPropertyTable table)
        {
            if (albumName == "carousel")
            {
                table.Register<CarouselItemRecord>(x => x.BackgroundGraphicId);
            }
        }

        public IEnumerable<MediaTrack> DetectAllTracks(string albumName)
        {
            var ctx = _dbContext;
            string name = nameof(CarouselItemRecord);
            var p = new FastPager<CarouselItemRecord>(ctx.Set<CarouselItemRecord>().AsNoTracking().Where(x => x.BackgroundGraphicId > 0), 5000);
            while (p.ReadNextPage(x => new { x.Id, x.BackgroundGraphicId }, x => x.Id, out var list))
            {
                foreach (var x in list)
                {
                    yield return new MediaTrack { EntityId = x.Id, EntityName = name, MediaFileId = x.BackgroundGraphicId, Property = nameof(x.BackgroundGraphicId) };
                }
            }
        }
    }
pineportal commented 3 years ago

I am use IMediaTracker in Controller. fix problem