From 59860177c65fdda2839ba86fd1c24ef921222c59 Mon Sep 17 00:00:00 2001 From: Benedek Farkas Date: Sat, 11 Oct 2025 23:21:29 +0200 Subject: [PATCH] Implementing deep cloning for ImageProfilePart + code styling in ImageProfilePartDriver --- .../Drivers/ImageProfilePartDriver.cs | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.MediaProcessing/Drivers/ImageProfilePartDriver.cs b/src/Orchard.Web/Modules/Orchard.MediaProcessing/Drivers/ImageProfilePartDriver.cs index edba7ddd4..75d900ff6 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaProcessing/Drivers/ImageProfilePartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaProcessing/Drivers/ImageProfilePartDriver.cs @@ -28,17 +28,17 @@ namespace Orchard.MediaProcessing.Drivers { get { return "MediaProcessing"; } } - protected override DriverResult Display(ImageProfilePart part, string displayType, dynamic shapeHelper) { - return ContentShape("Parts_MediaProcessing_ImageProfile", - () => shapeHelper.Parts_MediaProcessing_ImageProfile(Name: part.Name)); - } + protected override DriverResult Display(ImageProfilePart part, string displayType, dynamic shapeHelper) => + ContentShape("Parts_MediaProcessing_ImageProfile", () => + shapeHelper.Parts_MediaProcessing_ImageProfile(Name: part.Name)); protected override DriverResult Editor(ImageProfilePart part, dynamic shapeHelper) { var viewModel = new ImageProfileViewModel { Name = part.Name }; - return ContentShape("Parts_MediaProcessing_ImageProfile_Edit", - () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: viewModel, Prefix: Prefix)); + + return ContentShape("Parts_MediaProcessing_ImageProfile_Edit", () => + shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: viewModel, Prefix: Prefix)); } protected override DriverResult Editor(ImageProfilePart part, IUpdateModel updater, dynamic shapeHelper) { @@ -47,7 +47,7 @@ namespace Orchard.MediaProcessing.Drivers { // It would be nice if IUpdateModel provided access to the IsValid property of the Controller, instead of having to track a local flag. var isValid = updater.TryUpdateModel(viewModel, Prefix, null, null); - if (String.IsNullOrWhiteSpace(viewModel.Name)) { + if (string.IsNullOrWhiteSpace(viewModel.Name)) { updater.AddModelError("Name", T("The Name can't be empty.")); isValid = false; } @@ -72,17 +72,17 @@ namespace Orchard.MediaProcessing.Drivers { element.Add( new XAttribute("Name", part.Name), new XElement("Filters", - part.Filters.Select(filter => - new XElement("Filter", - new XAttribute("Description", filter.Description ?? ""), - new XAttribute("Category", filter.Category ?? ""), - new XAttribute("Type", filter.Type ?? ""), - new XAttribute("Position", filter.Position), - new XAttribute("State", filter.State ?? "") - ) - ) + part.Filters.Select(filter => + new XElement("Filter", + new XAttribute("Description", filter.Description ?? ""), + new XAttribute("Category", filter.Category ?? ""), + new XAttribute("Type", filter.Type ?? ""), + new XAttribute("Position", filter.Position), + new XAttribute("State", filter.State ?? "") + ) ) - ); + ) + ); } protected override void Importing(ImageProfilePart part, ImportContentContext context) { @@ -111,8 +111,17 @@ namespace Orchard.MediaProcessing.Drivers { protected override void Cloning(ImageProfilePart originalPart, ImageProfilePart clonePart, CloneContentContext context) { clonePart.Name = originalPart.Name; clonePart.ModifiedUtc = originalPart.ModifiedUtc; - clonePart.Record.Filters = originalPart.Filters; clonePart.Record.FileNames = new List(); + clonePart.Record.Filters = originalPart.Filters.Select(filter => + new FilterRecord { + Description = filter.Description, + Category = filter.Category, + Type = filter.Type, + Position = filter.Position, + State = filter.State, + ImageProfilePartRecord = clonePart.Record + }).ToList( + ); } } } \ No newline at end of file