Skip to content

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.

Refactoring - use repository extensions (storage service)

KrzysztofPajak2293d96a8a77
diff --git a/src/Business/Grand.Business.Storage/Services/DownloadService.cs b/src/Business/Grand.Business.Storage/Services/DownloadService.cs
index 2768e5f34..9584aa240 100644
--- a/src/Business/Grand.Business.Storage/Services/DownloadService.cs
+++ b/src/Business/Grand.Business.Storage/Services/DownloadService.cs
@@ -3,9 +3,6 @@ using Grand.Domain.Data;
using Grand.Domain.Media;
using Grand.Infrastructure.Extensions;
using MediatR;
-using MongoDB.Bson;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
@@ -59,7 +56,7 @@ namespace Grand.Business.Storage.Services
return _download;
}
- protected virtual async Task<byte[]> DownloadAsBytes(ObjectId objectId)
+ protected virtual async Task<byte[]> DownloadAsBytes(MongoDB.Bson.ObjectId 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 });
@@ -78,7 +75,8 @@ namespace Grand.Business.Storage.Services
var query = from o in _downloadRepository.Table
where o.DownloadGuid == downloadGuid
select o;
- var order = await query.FirstOrDefaultAsync();
+
+ var order = (await query.ToListAsync2()).FirstOrDefault();
if (!order.UseDownloadUrl)
order.DownloadBinary = await DownloadAsBytes(order.DownloadObjectId);
diff --git a/src/Business/Grand.Business.Storage/Services/PictureService.cs b/src/Business/Grand.Business.Storage/Services/PictureService.cs
index c772a1b19..e8e31bbd4 100644
--- a/src/Business/Grand.Business.Storage/Services/PictureService.cs
+++ b/src/Business/Grand.Business.Storage/Services/PictureService.cs
@@ -7,8 +7,6 @@ using Grand.Domain.Data;
using Grand.Domain.Media;
using MediatR;
using Microsoft.AspNetCore.Hosting;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using SkiaSharp;
using System;
using System.IO;
@@ -488,7 +486,7 @@ namespace Grand.Business.Storage.Services
Reference = p.Reference,
ObjectId = p.ObjectId
});
- return await query.FirstOrDefaultAsync();
+ return await Task.FromResult(query.FirstOrDefault());
});
}