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
Delete fs.chunks when user delete object from GrandNode #136
KrzysztofPajak5afe95e27bb8
diff --git a/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs b/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.csindex c76ae1d75..133aca9ab 100644--- a/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs+++ b/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs@@ -122,7 +122,7 @@ namespace Grand.Business.Common.Services.PdfContentType = "application/pdf",};- download.DownloadObjectId = await _storeFilesContext.BucketUploadFromBytesAsync(download.Filename, ms.ToArray());+ download.DownloadObjectId = await _storeFilesContext.BucketUploadFromBytes(download.Filename, ms.ToArray());await _downloadRepository.InsertAsync(download);//TODOdiff --git a/src/Business/Grand.Business.Storage/Services/DownloadService.cs b/src/Business/Grand.Business.Storage/Services/DownloadService.csindex 23dea4c0f..4c9311cfa 100644--- a/src/Business/Grand.Business.Storage/Services/DownloadService.cs+++ b/src/Business/Grand.Business.Storage/Services/DownloadService.cs@@ -96,7 +96,7 @@ namespace Grand.Business.Storage.Servicesthrow new ArgumentNullException(nameof(download));if (!download.UseDownloadUrl){- download.DownloadObjectId = await _storeFilesContext.BucketUploadFromBytesAsync(download.Filename, download.DownloadBinary);+ download.DownloadObjectId = await _storeFilesContext.BucketUploadFromBytes(download.Filename, download.DownloadBinary);}download.DownloadBinary = null;@@ -130,6 +130,10 @@ namespace Grand.Business.Storage.Servicesawait _downloadRepository.DeleteAsync(download);+ //delete from bucket+ if(!string.IsNullOrEmpty(download.DownloadObjectId))+ await _storeFilesContext.BucketDelete(download.DownloadObjectId);+await _mediator.EntityDeleted(download);}diff --git a/src/Core/Grand.Domain/Data/IStoreFilesContext.cs b/src/Core/Grand.Domain/Data/IStoreFilesContext.csindex cccd178d8..5e84409ec 100644--- a/src/Core/Grand.Domain/Data/IStoreFilesContext.cs+++ b/src/Core/Grand.Domain/Data/IStoreFilesContext.cs@@ -5,6 +5,7 @@ namespace Grand.Domain.Datapublic interface IStoreFilesContext{Task<byte[]> BucketDownload(string id);- Task<string> BucketUploadFromBytesAsync(string filename, byte[] source);+ Task BucketDelete(string id);+ Task<string> BucketUploadFromBytes(string filename, byte[] source);}}diff --git a/src/Core/Grand.Domain/Data/Mongo/MongoStoreFilesContext.cs b/src/Core/Grand.Domain/Data/Mongo/MongoStoreFilesContext.csindex 9312d43e9..7c590bd94 100644--- a/src/Core/Grand.Domain/Data/Mongo/MongoStoreFilesContext.cs+++ b/src/Core/Grand.Domain/Data/Mongo/MongoStoreFilesContext.cs@@ -29,7 +29,13 @@ namespace Grand.Domain.Data.Mongoreturn binary;}- public async Task<string> BucketUploadFromBytesAsync(string filename, byte[] source)+ public async Task BucketDelete(string id)+ {+ var bucket = new MongoDB.Driver.GridFS.GridFSBucket(_database);+ await bucket.DeleteAsync(new ObjectId(id));+ }++ public async Task<string> BucketUploadFromBytes(string filename, byte[] source){var bucket = new MongoDB.Driver.GridFS.GridFSBucket(_database);var id = await bucket.UploadFromBytesAsync(filename, source);diff --git a/src/Web/Grand.Web.Admin/Controllers/DocumentController.cs b/src/Web/Grand.Web.Admin/Controllers/DocumentController.csindex caef04e06..ea4129067 100644--- a/src/Web/Grand.Web.Admin/Controllers/DocumentController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/DocumentController.cs@@ -71,16 +71,7 @@ namespace Grand.Web.Admin.Controllers{if (ModelState.IsValid){- if (string.IsNullOrEmpty(model.CustomerId))- model.CustomerId = (await _customerService.GetCustomerByEmail(model.CustomerEmail))?.Id;-- var document = model.ToEntity();- document.CreatedOnUtc = DateTime.UtcNow;-- await _documentService.Insert(document);-- //activity log- await _customerActivityService.InsertActivity("AddNewDocument", document.Id, _translationService.GetResource("ActivityLog.AddNewDocument"), document.Name);+ var document = await _documentViewModelService.InsertDocument(model);Success(_translationService.GetResource("Admin.Documents.Document.Added"));return continueEditing ? RedirectToAction("EditDocument", new { id = document.Id }) : RedirectToAction("List");@@ -112,16 +103,7 @@ namespace Grand.Web.Admin.Controllersif (ModelState.IsValid){- if (string.IsNullOrEmpty(model.CustomerId))- model.CustomerId = (await _customerService.GetCustomerByEmail(model.CustomerEmail))?.Id;-- document = model.ToEntity(document);- document.UpdatedOnUtc = DateTime.UtcNow;-- await _documentService.Update(document);-- //activity log- await _customerActivityService.InsertActivity("EditDocument", document.Id, _translationService.GetResource("ActivityLog.EditDocument"), document.Name);+ document = await _documentViewModelService.UpdateDocument(document, model);Success(_translationService.GetResource("Admin.Documents.Document.Updated"));return continueEditing ? RedirectToAction("EditDocument", new { id = document.Id }) : RedirectToAction("List");@@ -142,10 +124,7 @@ namespace Grand.Web.Admin.Controllersif (ModelState.IsValid){- await _documentService.Delete(document);-- //activity log- await _customerActivityService.InsertActivity("DeleteDocument", document.Id, _translationService.GetResource("ActivityLog.DeleteDocument"), document.Name);+ await _documentViewModelService.DeleteDocument(document);Success(_translationService.GetResource("Admin.Documents.Document.Deleted"));return RedirectToAction("List");diff --git a/src/Web/Grand.Web.Admin/Controllers/DownloadController.cs b/src/Web/Grand.Web.Admin/Controllers/DownloadController.csindex ce9bf2bb9..d3d66e750 100644--- a/src/Web/Grand.Web.Admin/Controllers/DownloadController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/DownloadController.cs@@ -68,6 +68,7 @@ namespace Grand.Web.Admin.Controllersreturn Json(new { downloadId = download.Id, success = true });}+ [DisableRequestSizeLimit][HttpPost]//do not validate request token (XSRF)[IgnoreAntiforgeryToken]diff --git a/src/Web/Grand.Web.Admin/Controllers/MessageTemplateController.cs b/src/Web/Grand.Web.Admin/Controllers/MessageTemplateController.csindex 0adf2652b..123479cd2 100644--- a/src/Web/Grand.Web.Admin/Controllers/MessageTemplateController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/MessageTemplateController.cs@@ -3,6 +3,7 @@ using Grand.Business.Common.Interfaces.Localization;using Grand.Business.Common.Interfaces.Stores;using Grand.Business.Common.Services.Security;using Grand.Business.Messages.Interfaces;+using Grand.Business.Storage.Interfaces;using Grand.Domain.Messages;using Grand.Web.Admin.Extensions;using Grand.Web.Admin.Models.Messages;@@ -29,6 +30,7 @@ namespace Grand.Web.Admin.Controllersprivate readonly ITranslationService _translationService;private readonly IMessageTokenProvider _messageTokenProvider;private readonly IStoreService _storeService;+ private readonly IDownloadService _downloadService;private readonly EmailAccountSettings _emailAccountSettings;#endregion Fields@@ -41,6 +43,7 @@ namespace Grand.Web.Admin.ControllersITranslationService translationService,IMessageTokenProvider messageTokenProvider,IStoreService storeService,+ IDownloadService downloadService,EmailAccountSettings emailAccountSettings){_messageTemplateService = messageTemplateService;@@ -49,6 +52,7 @@ namespace Grand.Web.Admin.Controllers_translationService = translationService;_messageTokenProvider = messageTokenProvider;_storeService = storeService;+ _downloadService = downloadService;_emailAccountSettings = emailAccountSettings;}@@ -197,6 +201,8 @@ namespace Grand.Web.Admin.Controllers//No message template found with the specified idreturn RedirectToAction("List");+ var prevAttachment = messageTemplate.AttachedDownloadId;+if (ModelState.IsValid){messageTemplate = model.ToEntity(messageTemplate);@@ -206,6 +212,14 @@ namespace Grand.Web.Admin.Controllersif (model.SendImmediately)messageTemplate.DelayBeforeSend = null;+ //delete an old "attachment" file+ if (!string.IsNullOrEmpty(prevAttachment) && prevAttachment!= messageTemplate.AttachedDownloadId)+ {+ var attachment = await _downloadService.GetDownloadById(prevAttachment);+ if (attachment != null)+ await _downloadService.DeleteDownload(attachment);+ }+await _messageTemplateService.UpdateMessageTemplate(messageTemplate);Success(_translationService.GetResource("Admin.Content.MessageTemplates.Updated"));@@ -241,6 +255,14 @@ namespace Grand.Web.Admin.Controllersawait _messageTemplateService.DeleteMessageTemplate(messageTemplate);+ //delete an old "attachment" file+ if (!string.IsNullOrEmpty(messageTemplate.AttachedDownloadId))+ {+ var attachment = await _downloadService.GetDownloadById(messageTemplate.AttachedDownloadId);+ if (attachment != null)+ await _downloadService.DeleteDownload(attachment);+ }+Success(_translationService.GetResource("Admin.Content.MessageTemplates.Deleted"));return RedirectToAction("List");}diff --git a/src/Web/Grand.Web.Admin/Interfaces/IDocumentViewModelService.cs b/src/Web/Grand.Web.Admin/Interfaces/IDocumentViewModelService.csindex a19a90cc7..fc508405d 100644--- a/src/Web/Grand.Web.Admin/Interfaces/IDocumentViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Interfaces/IDocumentViewModelService.cs@@ -9,5 +9,8 @@ namespace Grand.Web.Admin.Interfaces{Task<(IEnumerable<DocumentModel> documetListModel, int totalCount)> PrepareDocumentListModel(DocumentListModel model, int pageIndex, int pageSize);Task<DocumentModel> PrepareDocumentModel(DocumentModel documentModel, Document document, SimpleDocumentModel simpleModel);+ Task<Document> InsertDocument(DocumentModel model);+ Task<Document> UpdateDocument(Document document, DocumentModel model);+ Task DeleteDocument(Document document);}}diff --git a/src/Web/Grand.Web.Admin/Services/CourseViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CourseViewModelService.csindex 85811f86a..cf212c320 100644--- a/src/Web/Grand.Web.Admin/Services/CourseViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/CourseViewModelService.cs@@ -38,6 +38,7 @@ namespace Grand.Web.Admin.Servicesprivate readonly ITranslationService _translationService;private readonly ICustomerActivityService _customerActivityService;private readonly IProductCourseService _productCourseService;+ private readonly IDownloadService _downloadService;private readonly IServiceProvider _serviceProvider;private readonly SeoSettings _seoSettings;@@ -45,6 +46,7 @@ namespace Grand.Web.Admin.ServicesICourseSubjectService courseSubjectService,ISlugService slugService, IPictureService pictureService, ILanguageService languageService,ITranslationService translationService, ICustomerActivityService customerActivityService, IProductCourseService productCourseService,+ IDownloadService downloadService,IServiceProvider serviceProvider,SeoSettings seoSettings){@@ -58,6 +60,7 @@ namespace Grand.Web.Admin.Services_translationService = translationService;_customerActivityService = customerActivityService;_productCourseService = productCourseService;+ _downloadService = downloadService;_serviceProvider = serviceProvider;_seoSettings = seoSettings;}@@ -72,7 +75,7 @@ namespace Grand.Web.Admin.Servicesforeach (var item in await _courseLevelService.GetAll()){- model.AvailableLevels.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem()+ model.AvailableLevels.Add(new SelectListItem(){Text = item.Name,Value = item.Id@@ -147,7 +150,6 @@ namespace Grand.Web.Admin.Servicesif (!string.IsNullOrEmpty(course.ProductId))await _productCourseService.UpdateCourseOnProduct(course.ProductId, course.Id);-//activity logawait _customerActivityService.InsertActivity("EditCourse", course.Id, _translationService.GetResource("ActivityLog.EditCourse"), course.Name);@@ -171,7 +173,7 @@ namespace Grand.Web.Admin.Servicesforeach (var item in await _courseSubjectService.GetByCourseId(courseId)){- model.AvailableSubjects.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem()+ model.AvailableSubjects.Add(new SelectListItem(){Text = item.Name,Value = item.Id@@ -192,6 +194,9 @@ namespace Grand.Web.Admin.Servicespublic virtual async Task<CourseLesson> UpdateCourseLessonModel(CourseLesson lesson, CourseLessonModel model){+ var prevAttachmentId = lesson.AttachmentId;+ var prevVideoFile = lesson.VideoFile;+string prevPictureId = lesson.PictureId;lesson = model.ToEntity(lesson);await _courseLessonService.Update(lesson);@@ -204,6 +209,22 @@ namespace Grand.Web.Admin.Servicesawait _pictureService.DeletePicture(prevPicture);}+ //delete an old "attachment" file (if deleted or updated)+ if (!string.IsNullOrEmpty(prevAttachmentId) && prevAttachmentId != lesson.AttachmentId)+ {+ var prevAttachment = await _downloadService.GetDownloadById(prevAttachmentId);+ if (prevAttachment != null)+ await _downloadService.DeleteDownload(prevAttachment);+ }++ //delete an old "video" file (if deleted or updated)+ if (!string.IsNullOrEmpty(prevVideoFile) && prevVideoFile != lesson.VideoFile)+ {+ var prevVideo = await _downloadService.GetDownloadById(prevVideoFile);+ if (prevVideo != null)+ await _downloadService.DeleteDownload(prevVideo);+ }+//activity logawait _customerActivityService.InsertActivity("EditCourseLesson", lesson.Id, _translationService.GetResource("ActivityLog.EditLessonCourse"), lesson.Name);@@ -212,6 +233,21 @@ namespace Grand.Web.Admin.Servicespublic virtual async Task DeleteCourseLesson(CourseLesson lesson){await _courseLessonService.Delete(lesson);++ if (!string.IsNullOrEmpty(lesson.VideoFile))+ {+ var prevVideo = await _downloadService.GetDownloadById(lesson.VideoFile);+ if (prevVideo != null)+ await _downloadService.DeleteDownload(prevVideo);+ }++ if (!string.IsNullOrEmpty(lesson.AttachmentId))+ {+ var prevAttachment = await _downloadService.GetDownloadById(lesson.AttachmentId);+ if (prevAttachment != null)+ await _downloadService.DeleteDownload(prevAttachment);+ }+//activity logawait _customerActivityService.InsertActivity("DeleteCourseLesson", lesson.Id, _translationService.GetResource("ActivityLog.DeleteCourseLesson"), lesson.Name);}diff --git a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.csindex a7e704515..12e66080c 100644--- a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs@@ -70,6 +70,7 @@ namespace Grand.Web.Admin.Servicesprivate readonly IProductService _productService;private readonly ISalesEmployeeService _salesEmployeeService;private readonly ICustomerNoteService _customerNoteService;+ private readonly IDownloadService _downloadService;private readonly IServiceProvider _serviceProvider;private readonly TaxSettings _taxSettings;@@ -102,6 +103,7 @@ namespace Grand.Web.Admin.ServicesIProductService productService,ISalesEmployeeService salesEmployeeService,ICustomerNoteService customerNoteService,+ IDownloadService downloadService,IServiceProvider serviceProvider,CustomerSettings customerSettings,TaxSettings taxSettings,@@ -137,6 +139,7 @@ namespace Grand.Web.Admin.Services_productService = productService;_salesEmployeeService = salesEmployeeService;_customerNoteService = customerNoteService;+ _downloadService = downloadService;_serviceProvider = serviceProvider;}@@ -1525,6 +1528,14 @@ namespace Grand.Web.Admin.Servicesthrow new ArgumentException("No customer note found with the specified id");await _customerNoteService.DeleteCustomerNote(customerNote);++ //delete an old "attachment" file+ if (!string.IsNullOrEmpty(customerNote.DownloadId))+ {+ var attachment = await _downloadService.GetDownloadById(customerNote.DownloadId);+ if (attachment != null)+ await _downloadService.DeleteDownload(attachment);+ }}}}diff --git a/src/Web/Grand.Web.Admin/Services/DocumentViewModelService.cs b/src/Web/Grand.Web.Admin/Services/DocumentViewModelService.csindex 1fe6c3894..2c0d71873 100644--- a/src/Web/Grand.Web.Admin/Services/DocumentViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/DocumentViewModelService.cs@@ -4,14 +4,17 @@ using Grand.Business.Catalog.Interfaces.Products;using Grand.Business.Checkout.Interfaces.Orders;using Grand.Business.Checkout.Interfaces.Shipping;using Grand.Business.Common.Interfaces.Localization;+using Grand.Business.Common.Interfaces.Logging;using Grand.Business.Customers.Interfaces;using Grand.Business.Marketing.Interfaces.Documents;+using Grand.Business.Storage.Interfaces;using Grand.Domain.Common;using Grand.Domain.Documents;using Grand.Web.Admin.Extensions;using Grand.Web.Admin.Interfaces;using Grand.Web.Admin.Models.Documents;using Microsoft.AspNetCore.Mvc.Rendering;+using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;@@ -32,6 +35,8 @@ namespace Grand.Web.Admin.Servicesprivate readonly ICollectionService _collectionService;private readonly IVendorService _vendorService;private readonly ISalesEmployeeService _salesEmployeeService;+ private readonly ICustomerActivityService _customerActivityService;+ private readonly IDownloadService _downloadService;public DocumentViewModelService(IDocumentService documentService,@@ -45,7 +50,9 @@ namespace Grand.Web.Admin.ServicesICategoryService categoryService,ICollectionService collectionService,IVendorService vendorService,- ISalesEmployeeService salesEmployeeService+ ISalesEmployeeService salesEmployeeService,+ ICustomerActivityService customerActivityService,+ IDownloadService downloadService){_documentService = documentService;@@ -60,6 +67,8 @@ namespace Grand.Web.Admin.Services_collectionService = collectionService;_vendorService = vendorService;_salesEmployeeService = salesEmployeeService;+ _customerActivityService = customerActivityService;+ _downloadService = downloadService;}public virtual async Task<(IEnumerable<DocumentModel> documetListModel, int totalCount)> PrepareDocumentListModel(DocumentListModel model, int pageIndex, int pageSize)@@ -205,5 +214,62 @@ namespace Grand.Web.Admin.Servicesreturn model;}+ public virtual async Task<Document> InsertDocument(DocumentModel model)+ {+ if (string.IsNullOrEmpty(model.CustomerId))+ model.CustomerId = (await _customerService.GetCustomerByEmail(model.CustomerEmail))?.Id;++ var document = model.ToEntity();+ document.CreatedOnUtc = DateTime.UtcNow;++ await _documentService.Insert(document);++ //activity log+ await _customerActivityService.InsertActivity("AddNewDocument", document.Id, _translationService.GetResource("ActivityLog.AddNewDocument"), document.Name);++ return document;+ }+ public virtual async Task<Document> UpdateDocument(Document document, DocumentModel model)+ {+ var prevAttachmentId = document.DownloadId;++ if (string.IsNullOrEmpty(model.CustomerId))+ model.CustomerId = (await _customerService.GetCustomerByEmail(model.CustomerEmail))?.Id;++ document = model.ToEntity(document);+ document.UpdatedOnUtc = DateTime.UtcNow;++ await _documentService.Update(document);++ //delete an old "attachment" file (if deleted or updated)+ if (!string.IsNullOrEmpty(prevAttachmentId) && prevAttachmentId != document.DownloadId)+ {+ var prevAttachment = await _downloadService.GetDownloadById(prevAttachmentId);+ if (prevAttachment != null)+ await _downloadService.DeleteDownload(prevAttachment);+ }++ //activity log+ await _customerActivityService.InsertActivity("EditDocument", document.Id, _translationService.GetResource("ActivityLog.EditDocument"), document.Name);++ return document;+ }++ public virtual async Task DeleteDocument(Document document)+ {+ await _documentService.Delete(document);++ //delete an old "attachment" file+ if (!string.IsNullOrEmpty(document.DownloadId))+ {+ var prevAttachment = await _downloadService.GetDownloadById(document.DownloadId);+ if (prevAttachment != null)+ await _downloadService.DeleteDownload(prevAttachment);+ }++ //activity log+ await _customerActivityService.InsertActivity("DeleteDocument", document.Id, _translationService.GetResource("ActivityLog.DeleteDocument"), document.Name);++ }}}diff --git a/src/Web/Grand.Web.Admin/Services/MerchandiseReturnViewModelService.cs b/src/Web/Grand.Web.Admin/Services/MerchandiseReturnViewModelService.csindex 96874e025..f6d323203 100644--- a/src/Web/Grand.Web.Admin/Services/MerchandiseReturnViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/MerchandiseReturnViewModelService.cs@@ -354,6 +354,14 @@ namespace Grand.Web.Admin.ServicesmerchandiseReturnNote.MerchandiseReturnId = merchandiseReturn.Id;await _merchandiseReturnService.DeleteMerchandiseReturnNote(merchandiseReturnNote);++ //delete an old "attachment" file+ if (!string.IsNullOrEmpty(merchandiseReturnNote.DownloadId))+ {+ var attachment = await _downloadService.GetDownloadById(merchandiseReturnNote.DownloadId);+ if (attachment != null)+ await _downloadService.DeleteDownload(attachment);+ }}}}diff --git a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.csindex 75bb4f3d9..8bde87f05 100644--- a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs@@ -993,6 +993,14 @@ namespace Grand.Web.Admin.ServicesorderNote.OrderId = order.Id;await _orderService.DeleteOrderNote(orderNote);++ //delete an old "attachment" file+ if (!string.IsNullOrEmpty(orderNote.DownloadId))+ {+ var attachment = await _downloadService.GetDownloadById(orderNote.DownloadId);+ if (attachment != null)+ await _downloadService.DeleteDownload(attachment);+ }}public virtual async Task LogEditOrder(string orderId)diff --git a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.csindex 49488354c..0f0595079 100644--- a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs@@ -1044,6 +1044,21 @@ namespace Grand.Web.Admin.Servicespublic virtual async Task DeleteProduct(Product product){await _productService.DeleteProduct(product);++ //delete an "download" file+ if (!string.IsNullOrEmpty(product.DownloadId))+ {+ var download = await _downloadService.GetDownloadById(product.DownloadId);+ if (download != null)+ await _downloadService.DeleteDownload(download);+ }++ if (!string.IsNullOrEmpty(product.SampleDownloadId))+ {+ var sampledownload = await _downloadService.GetDownloadById(product.SampleDownloadId);+ if (sampledownload != null)+ await _downloadService.DeleteDownload(sampledownload);+ }//activity logawait _customerActivityService.InsertActivity("DeleteProduct", product.Id, _translationService.GetResource("ActivityLog.DeleteProduct"), product.Name);}@@ -1063,8 +1078,7 @@ namespace Grand.Web.Admin.Servicesif (!(product.LimitedToStores && product.Stores.Contains(_workContext.CurrentCustomer.StaffStoreId) && product.Stores.Count == 1))continue;}-- await _productService.DeleteProduct(product);+ await DeleteProduct(product);}}public virtual async Task<ProductModel.AddRequiredProductModel> PrepareAddRequiredProductModel()diff --git a/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.csindex bcb441fab..bb8536e71 100644--- a/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs@@ -280,6 +280,14 @@ namespace Grand.Web.Admin.ServicesshipmentNote.ShipmentId = shipment.Id;await _shipmentService.DeleteShipmentNote(shipmentNote);++ //delete an old "attachment" file+ if (!string.IsNullOrEmpty(shipmentNote.DownloadId))+ {+ var attachment = await _downloadService.GetDownloadById(shipmentNote.DownloadId);+ if (attachment != null)+ await _downloadService.DeleteDownload(attachment);+ }}public virtual async Task LogShipment(string shipmentId, string message)