/// <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); }
public ActionResult Create(int DictionaryTypeID, FormCollection formCollection) { try { DictionaryRepository ml = new DictionaryRepository(); Dictionary obj = new Dictionary() { CreateDate = DateTime.Now, CreateUserID = ID, IsDeleted = false }; UpdateModel(obj); bool result = ml.Insert(obj) > 0 ? true : false; return(result ? Content(ContentIcon.Succeed + "|操作成功|/Admin/Dictionary/Index?DictionaryTypeID=" + DictionaryTypeID) : Content(ContentIcon.Error + "|操作失败")); } catch (Exception ex) { return(Content(ContentIcon.Error + "|" + ErrorWirter(RouteData, ex.Message))); } }