diff --git a/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs b/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs index ffaa76f76..9b251bcfc 100644 --- a/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs @@ -262,17 +262,21 @@ public class AuditDocumentService(IRepository _auditDocumentRepos [HttpPost] public async Task MovieFileOrFolder(MovieFileOrFolderInDto inDto) { + + var data = await _auditDocumentRepository.Select(x => new DeleteAudit() + { + Id = x.Id, + ParentId = x.ParentId, + AuditDocumentTypeEnum = x.AuditDocumentTypeEnum, + MainFileId = x.MainFileId + }).ToListAsync(); + foreach (var id in inDto.Ids) { - var file = await _auditDocumentRepository.Where(x => x.Id == id).FirstNotNullAsync(); + var file = data.Where(x => x.Id == id).FirstOrDefault(); if (file.AuditDocumentTypeEnum == AuditDocumentType.Folder) { - var data = await _auditDocumentRepository.Select(x => new DeleteAudit() - { - Id = x.Id, - ParentId = x.ParentId, - MainFileId = x.MainFileId - }).ToListAsync(); + if (finChild(new List { id }, inDto.ParentId, data)) { @@ -280,26 +284,33 @@ public class AuditDocumentService(IRepository _auditDocumentRepos } } + } - bool finChild(List ids, Guid ChildId, List data) + bool finChild(List ids, Guid ChildId, List data) + { + var child = data.Where(x => x.ParentId != null && ids.Contains(x.ParentId.Value)).ToList(); + if (child.Count() == 0) { - var child = data.Where(x => x.ParentId != null && ids.Contains(x.ParentId.Value)).ToList(); - if (child.Count() == 0) - { - return false; - } - else if (child.Any(x => x.Id == ChildId)) - { - return true; - } - else - { - var newids = child.Select(x => x.Id).ToList(); - - return finChild(newids, ChildId, data); - - } + return false; } + else if (child.Any(x => x.Id == ChildId)) + { + return true; + } + else + { + var newids = child.Select(x => x.Id).ToList(); + + return finChild(newids, ChildId, data); + + } + } + + foreach (var id in inDto.Ids) + { + + + await _auditDocumentRepository.UpdatePartialFromQueryAsync(id, x => new AuditDocument() { diff --git a/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs b/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs index e0db95589..573603c74 100644 --- a/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs +++ b/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs @@ -13,6 +13,7 @@ public class DeleteAudit { public Guid Id { get; set; } + public AuditDocumentType AuditDocumentTypeEnum { get; set; } public Guid? ParentId { get; set; } public Guid? MainFileId { get; set; }