diff --git a/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs index 6f5bab8dd..454bbddb0 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs @@ -42,7 +42,7 @@ namespace IRaCIS.Application.Contracts //有父亲 就有值 - public Guid ParentId { get; set; } + public Guid? ParentId { get; set; } public bool IsEnable { get; set; } diff --git a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs index 7ca8b2ea5..2b1eb8c73 100644 --- a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs +++ b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs @@ -59,26 +59,25 @@ namespace IRaCIS.Application.Services [HttpPost] public async Task AddOrUpdateBasicDic(AddOrEditBasicDic addOrEditBasic) { - if (addOrEditBasic.Id == null) - { - var entity = await _dicRepository.InsertDictionaryAsync(addOrEditBasic); + //if (addOrEditBasic.Id == null) + //{ + // var entity = await _dicRepository.InsertDictionaryAsync(addOrEditBasic); - await _dicRepository.UpdateFromQueryAsync(t => t.ParentId == Guid.Empty, - u => new Dictionary() { ParentId = null }); + // await _dicRepository.UpdateFromQueryAsync(t => t.ParentId == Guid.Empty, + // u => new Dictionary() { ParentId = null }); - return ResponseOutput.Ok(entity.Id.ToString()); - } - else - { - var entity = await _dicRepository.InsertOrUpdateAsync(addOrEditBasic, true); - await _dicRepository.UpdateFromQueryAsync(t => t.ParentId == Guid.Empty, - u => new Dictionary() { ParentId = null }); + // return ResponseOutput.Ok(entity.Id.ToString()); + //} + //else + //{ + // var entity = await _dicRepository.InsertOrUpdateAsync(addOrEditBasic, true); - return ResponseOutput.Ok(entity.Id.ToString()); - } - //var entity = await _dicRepository.InsertOrUpdateAsync(addOrEditBasic, true); - //return ResponseOutput.Ok(entity.Id.ToString()); + // return ResponseOutput.Ok(entity.Id.ToString()); + //} + var entity = await _dicRepository.InsertOrUpdateAsync(addOrEditBasic, true); + + return ResponseOutput.Ok(entity.Id.ToString()); } @@ -100,6 +99,11 @@ namespace IRaCIS.Application.Services [HttpDelete("{id:guid}")] public async Task DeleteDictionary(Guid id) { + if ( await _dicRepository.AnyAsync(t => t.ParentId == id)) + { + return ResponseOutput.NotOk("有子项数据,不允许直接删除!"); + } + if ((await _doctorDictionaryRepository.AnyAsync(t => t.DictionaryId == id)) || (await _doctorRepository.AnyAsync(t => t.SpecialityId == id || t.PositionId == id || t.DepartmentId == id || t.RankId == id)) diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index bd3f72707..75eba7b84 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -10,6 +10,7 @@ using Microsoft.EntityFrameworkCore.ChangeTracking; using System.Reflection; using IRaCIS.Core.Domain.Share; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; using UserTypeGroup = IRaCIS.Core.Domain.Models.UserTypeGroup; namespace IRaCIS.Core.Infra.EFCore @@ -68,11 +69,7 @@ namespace IRaCIS.Core.Infra.EFCore protected override void OnModelCreating(ModelBuilder modelBuilder) { - //modelBuilder.Entity().HasMany(s => s.TrialSiteUserSurveyList).WithOne(sv => sv.TrialSiteSurvey); - //modelBuilder.Entity().HasMany(s => s.TrialSiteEquipmentSurveyList).WithOne(sv => sv.TrialSiteSurvey); - //modelBuilder.Entity().Ignore(t => t.MappedValue); - //modelBuilder.Entity().Property(t => t.MappedValue).HasComputedColumnSql(_userInfo.IsEn_Us? "[Value]":"[ValueCN]"); - //modelBuilder.Entity()// .HasQueryFilter(t => t.IsDeleted == false); + if (_userInfo.IsEn_Us) { @@ -84,8 +81,9 @@ namespace IRaCIS.Core.Infra.EFCore } - modelBuilder.Entity().Property(t => t.FullName) .HasComputedColumnSql("[LastName] + ' / ' + [FirstName]",false); - modelBuilder.Entity().Ignore(t => t.FullName); + + //modelBuilder.Entity().Property(t => t.FullName) .HasComputedColumnSql("[LastName] + ' / ' + [FirstName]",false); + //modelBuilder.Entity().Ignore(t => t.FullName); //遍历实体模型手动配置 diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs index 06fb8b963..ddef1e982 100644 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs +++ b/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs @@ -1,5 +1,6 @@ using IRaCIS.Core.Domain.Models; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -22,4 +23,15 @@ namespace IRaCIS.Core.Infra.EFCore.EntityConfigration .HasForeignKey(dd => dd.DictionaryId); } } + + public class DictionaryConfigration : IEntityTypeConfiguration + { + + + public void Configure(EntityTypeBuilder builder) + { + builder.Property(e => e.MappedValue).Metadata.SetBeforeSaveBehavior(PropertySaveBehavior.Ignore); + + } + } }