From d615c1d7b002dc12e9c9ae06e13dc139c8213bfb Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 22 Mar 2023 00:02:46 +0000 Subject: [PATCH] case 4494 --- docs/8.0/ayanova/docs/changelog.md | 4 ++++ server/AyaNova/biz/AttachmentBiz.cs | 16 ++++++++++++++-- server/AyaNova/biz/PMBiz.cs | 2 +- server/AyaNova/biz/QuoteBiz.cs | 2 +- server/AyaNova/biz/WorkOrderBiz.cs | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/docs/8.0/ayanova/docs/changelog.md b/docs/8.0/ayanova/docs/changelog.md index f3028437..fefcc9dc 100644 --- a/docs/8.0/ayanova/docs/changelog.md +++ b/docs/8.0/ayanova/docs/changelog.md @@ -14,6 +14,10 @@ See the [upgrade instructions](ops-upgrade.md) section of this manual for detail - App: Additional improvements to web app local error logging in certain conditions +#### Fixed + +- Server: Fix for issue occasionally causing error saving duplicated Work order, Quote, PM with attachments selected + ### AyaNova 8.0.39 (2023-03-17) #### Added diff --git a/server/AyaNova/biz/AttachmentBiz.cs b/server/AyaNova/biz/AttachmentBiz.cs index 198aeab4..943e6fe6 100644 --- a/server/AyaNova/biz/AttachmentBiz.cs +++ b/server/AyaNova/biz/AttachmentBiz.cs @@ -224,7 +224,7 @@ namespace AyaNova.Biz //////////////////////////////////////////////////////////////////////////////////////////////// //DUPLICATE ATTACHMENTS TO NEW OBJECT // - internal static async Task DuplicateAttachments(AyaTypeId aSource, AyaTypeId aDest, AyContext ct) + internal static async Task DuplicateAttachments(AyaTypeId aSource, AyaTypeId aDest, long attachedByUserId, AyContext ct) { var sources = await ct.FileAttachment.AsNoTracking() .Where(z => z.AttachToAType == aSource.AType && z.AttachToObjectId == aSource.ObjectId) @@ -233,7 +233,19 @@ namespace AyaNova.Biz { foreach (var src in sources) { - ct.FileAttachment.Add(new FileAttachment { AttachToObjectId = aDest.ObjectId, AttachToAType = aDest.AType, StoredFileName = src.StoredFileName, DisplayFileName = src.DisplayFileName, ContentType = src.ContentType, LastModified = src.LastModified, Notes = src.Notes, Exists = src.Exists, Size = src.Size }); + ct.FileAttachment.Add(new FileAttachment + { + AttachToObjectId = aDest.ObjectId, + AttachToAType = aDest.AType, + StoredFileName = src.StoredFileName, + DisplayFileName = src.DisplayFileName, + ContentType = src.ContentType, + LastModified = src.LastModified, + Notes = src.Notes, + Exists = src.Exists, + Size = src.Size, + AttachedByUserId=attachedByUserId// + }); } await ct.SaveChangesAsync(); } diff --git a/server/AyaNova/biz/PMBiz.cs b/server/AyaNova/biz/PMBiz.cs index d0e5c80c..ae80cb09 100644 --- a/server/AyaNova/biz/PMBiz.cs +++ b/server/AyaNova/biz/PMBiz.cs @@ -151,7 +151,7 @@ namespace AyaNova.Biz if (newObject.GenCopyAttachmentsFrom != null && !newObject.GenCopyAttachmentsFrom.IsEmpty) { //copy attachment from existing object - await AttachmentBiz.DuplicateAttachments(newObject.GenCopyAttachmentsFrom, new AyaTypeId(AyaType.PM, newObject.Id), ct); + await AttachmentBiz.DuplicateAttachments(newObject.GenCopyAttachmentsFrom, new AyaTypeId(AyaType.PM, newObject.Id), this.UserId, ct); newObject.GenCopyAttachmentsFrom = null;//so it doesn't get returned } await PMHandlePotentialNotificationEvent(AyaEvent.Created, newObject); diff --git a/server/AyaNova/biz/QuoteBiz.cs b/server/AyaNova/biz/QuoteBiz.cs index f02d646d..71849617 100644 --- a/server/AyaNova/biz/QuoteBiz.cs +++ b/server/AyaNova/biz/QuoteBiz.cs @@ -155,7 +155,7 @@ namespace AyaNova.Biz if (newObject.GenCopyAttachmentsFrom != null && !newObject.GenCopyAttachmentsFrom.IsEmpty) { //copy attachment from existing object - await AttachmentBiz.DuplicateAttachments(newObject.GenCopyAttachmentsFrom, new AyaTypeId(AyaType.Quote, newObject.Id), ct); + await AttachmentBiz.DuplicateAttachments(newObject.GenCopyAttachmentsFrom, new AyaTypeId(AyaType.Quote, newObject.Id), this.UserId, ct); newObject.GenCopyAttachmentsFrom = null;//so it doesn't get returned } await QuoteHandlePotentialNotificationEvent(AyaEvent.Created, newObject); diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index f165b600..c425a6cb 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -176,7 +176,7 @@ namespace AyaNova.Biz if (newObject.GenCopyAttachmentsFrom != null && !newObject.GenCopyAttachmentsFrom.IsEmpty) { //copy attachment from existing object - await AttachmentBiz.DuplicateAttachments(newObject.GenCopyAttachmentsFrom, new AyaTypeId(AyaType.WorkOrder, newObject.Id), ct); + await AttachmentBiz.DuplicateAttachments(newObject.GenCopyAttachmentsFrom, new AyaTypeId(AyaType.WorkOrder, newObject.Id), this.UserId, ct); newObject.GenCopyAttachmentsFrom = null;//so it doesn't get returned } await WorkOrderHandlePotentialNotificationEvent(AyaEvent.Created, newObject);