Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Refactoring - use repository extensions (download)
KrzysztofPajak947ecb47f353
diff --git a/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs b/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.csindex e41206a3b..2e1a898b4 100644--- a/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs+++ b/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs@@ -121,7 +121,7 @@ namespace Grand.Business.Common.Services.Pdf};var bucket = new MongoDB.Driver.GridFS.GridFSBucket(_downloadRepository.Database);var id = await bucket.UploadFromBytesAsync(download.Filename, ms.ToArray());- download.DownloadObjectId = id;+ download.DownloadObjectId = id.ToString();await _downloadRepository.InsertAsync(download);//TODOdiff --git a/src/Business/Grand.Business.Storage/Services/DownloadService.cs b/src/Business/Grand.Business.Storage/Services/DownloadService.csindex 9584aa240..5aa730a83 100644--- a/src/Business/Grand.Business.Storage/Services/DownloadService.cs+++ b/src/Business/Grand.Business.Storage/Services/DownloadService.cs@@ -56,10 +56,10 @@ namespace Grand.Business.Storage.Servicesreturn _download;}- protected virtual async Task<byte[]> DownloadAsBytes(MongoDB.Bson.ObjectId objectId)+ protected virtual async Task<byte[]> DownloadAsBytes(string objectId){var bucket = new MongoDB.Driver.GridFS.GridFSBucket(_downloadRepository.Database);- var binary = await bucket.DownloadAsBytesAsync(objectId, new MongoDB.Driver.GridFS.GridFSDownloadOptions() { CheckMD5 = true, Seekable = true });+ var binary = await bucket.DownloadAsBytesAsync(new MongoDB.Bson.ObjectId(objectId), new MongoDB.Driver.GridFS.GridFSDownloadOptions() { CheckMD5 = true, Seekable = true });return binary;}/// <summary>@@ -95,7 +95,7 @@ namespace Grand.Business.Storage.Services{var bucket = new MongoDB.Driver.GridFS.GridFSBucket(_downloadRepository.Database);var id = await bucket.UploadFromBytesAsync(download.Filename, download.DownloadBinary);- download.DownloadObjectId = id;+ download.DownloadObjectId = id.ToString();}download.DownloadBinary = null;diff --git a/src/Core/Grand.Domain/Media/Download.cs b/src/Core/Grand.Domain/Media/Download.csindex 75ff5a2f5..5ebb1db6c 100644--- a/src/Core/Grand.Domain/Media/Download.cs+++ b/src/Core/Grand.Domain/Media/Download.cs@@ -1,5 +1,3 @@-using MongoDB.Bson;-using MongoDB.Bson.Serialization.Attributes;using System;namespace Grand.Domain.Media@@ -27,13 +25,12 @@ namespace Grand.Domain.Media/// <summary>/// Gets or sets the download binary/// </summary>- [BsonIgnore]public byte[] DownloadBinary { get; set; }/// <summary>/// Gets or sets the download binary/// </summary>- public ObjectId DownloadObjectId { get; set; }+ public string DownloadObjectId { get; set; }/// <summary>/// The mime-type of the downloaddiff --git a/src/Core/Grand.Domain/MongoDB/MongoDBMapperConfiguration.cs b/src/Core/Grand.Domain/MongoDB/MongoDBMapperConfiguration.csindex 459f58536..404f0b884 100644--- a/src/Core/Grand.Domain/MongoDB/MongoDBMapperConfiguration.cs+++ b/src/Core/Grand.Domain/MongoDB/MongoDBMapperConfiguration.cs@@ -29,6 +29,12 @@ namespace Grand.Domain.MongoDB};ConventionRegistry.Register("ApplicationConventions", cp, t => true);++ BsonClassMap.RegisterClassMap<Media.Download>(cm =>+ {+ cm.AutoMap();+ cm.UnmapMember(m => m.DownloadBinary);+ });}}