/// <summary> /// 添加数据字典信息信息 /// </summary> /// <param name="dtos">要添加的数据字典信息DTO信息</param> /// <returns>业务操作结果</returns> public OperationResult AddDictionarys(params DictionaryDto[] dtos) { dtos.CheckNotNull("dtos"); OperationResult result = DictionaryRepository.Insert(dtos, dto => { if (DictionaryRepository.CheckExists(m => m.Value == dto.Value)) { throw new Exception("值为“{0}”的数据字典已存在,不能重复添加。".FormatWith(dto.Value)); } }, (dto, entity) => { if (dto.ParentId.HasValue && dto.ParentId.Value > 0) { Dictionary parent = DictionaryRepository.GetByKey(dto.ParentId.Value); if (parent == null) { throw new Exception("指定父数据字典不存在。"); } entity.Parent = parent; } return(entity); }); return(result); }
/// <summary> /// 更新数据字典信息信息 /// </summary> /// <param name="dtos">包含更新信息的数据字典信息DTO信息</param> /// <returns>业务操作结果</returns> public OperationResult EditDictionarys(params DictionaryDto[] dtos) { dtos.CheckNotNull("dtos"); OperationResult result = DictionaryRepository.Update(dtos, dto => { if (DictionaryRepository.CheckExists(m => m.Value == dto.Value)) { throw new Exception("值为“{0}”的数据字典已存在,不能重复添加。".FormatWith(dto.Value)); } }, (dto, entity) => { if (!dto.ParentId.HasValue || dto.ParentId == 0) { entity.Parent = null; } else if (entity.Parent != null && entity.Parent.Id != dto.ParentId) { Dictionary parent = DictionaryRepository.GetByKey(dto.ParentId.Value); if (parent == null) { throw new Exception("指定父数据字典不存在。"); } entity.Parent = parent; } return(entity); }); return(result); }
/// <summary> /// 检查数据字典信息信息是否存在 /// </summary> /// <param name="predicate">检查谓语表达式</param> /// <param name="id">更新的数据字典信息编号</param> /// <returns>数据字典信息是否存在</returns> public bool CheckDictionaryExists(Expression <Func <Dictionary, bool> > predicate, int id = 0) { return(DictionaryRepository.CheckExists(predicate, id)); }