This commit is contained in:
2021-07-27 19:31:48 +00:00
parent 120f9f85a4
commit cb0ad0440c
2 changed files with 18 additions and 2 deletions

View File

@@ -221,7 +221,23 @@ namespace AyaNova.Biz
//Other job handlers here...
////////////////////////////////////////////////////////////////////////////////////////////////
//DUPLICATE ATTACHMENTS TO NEW OBJECT
//
internal static async Task DuplicateAttachments(AyaTypeId aSource, AyaTypeId aDest, AyContext ct)
{
var sources = await ct.FileAttachment.AsNoTracking()
.Where(z => z.AttachToAType == aSource.AType && z.AttachToObjectId == aSource.ObjectId)
.ToListAsync();
if (sources.Count > 0)
{
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 });
}
await ct.SaveChangesAsync();
}
}
/////////////////////////////////////////////////////////////////////

View File

@@ -169,7 +169,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);
newObject.GenCopyAttachmentsFrom=null;//so it doesn't get returned
}
return newObject;