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(); }