From 44e9b211c20508d4dcf579d152d3faea00582a44 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 20 Dec 2023 14:00:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A8=A1=E6=9D=BF=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=EF=BC=8C=E6=B8=85=E7=90=86=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E6=96=87=E6=A1=A3,=E9=9C=80=E8=A6=81=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Common/CommonDocumentService.cs | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Common/CommonDocumentService.cs b/IRaCIS.Core.Application/Service/Common/CommonDocumentService.cs index bc7db9531..185e1f6eb 100644 --- a/IRaCIS.Core.Application/Service/Common/CommonDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Common/CommonDocumentService.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Application.Helper; +using IRaCIS.Application.Contracts; namespace IRaCIS.Core.Application.Service { @@ -99,14 +100,36 @@ namespace IRaCIS.Core.Application.Service //---读取模板内容失败, 请将文件另存为docx格式尝试! return ResponseOutput.NotOk(_localizer["Document_ TemplateRead"]); } - - } } - var entity = await _commonDocumentRepository.InsertOrUpdateAsync(addOrEditCommonDocument, true, verifyExp1, verifyExp2); + + if (addOrEditCommonDocument.Id == null) //insert + { - return ResponseOutput.Ok(entity.Id.ToString()); + + var entity = await _commonDocumentRepository.InsertFromDTOAsync(addOrEditCommonDocument, true, verifyExp1, verifyExp2); + + return ResponseOutput.Ok(entity.Id.ToString()); + } + else //update + { + + var dbbeforeEntity = await _commonDocumentRepository.UpdateFromDTOAsync(addOrEditCommonDocument, false, false, verifyExp1, verifyExp2); + + var filePath = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, dbbeforeEntity.Path); + + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + + return ResponseOutput.Ok(); + + } + + + } @@ -114,7 +137,20 @@ namespace IRaCIS.Core.Application.Service [HttpDelete("{commonDocumentId:guid}")] public async Task DeleteCommonDocument(Guid commonDocumentId) { + var find= await _commonDocumentRepository.FirstOrDefaultNoTrackingAsync(t=>t.Id== commonDocumentId); + var success = await _commonDocumentRepository.DeleteFromQueryAsync(t => t.Id == commonDocumentId, true,true); + + if (find != null) + { + var filePath = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, find.Path); + + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + } + return ResponseOutput.Ok(); }