/// <summary> /// 更新字典数据 /// </summary> /// <param name="categoryId"></param> /// <param name="dataId"></param> /// <param name="input"></param> /// <returns></returns> public async Task UpdateDictionaryDataAsync( [Required, Range(1, int.MaxValue, ErrorMessage = "请输入有效的字典分类Id"), ApiSeat(ApiSeats.ActionStart)] int categoryId, [Required, Range(1, int.MaxValue, ErrorMessage = "请输入有效的字典数据Id")] int dataId, [Required] EditSystemDataInput input) { // 查询字典分类是否存在 var isExist = await _categoryRepository.AnyAsync(u => u.Id == categoryId, false); if (!isExist) { throw Oops.Oh(SystemErrorCodes.u1002); } // 查询字典数据是否存在 isExist = await _dataRepository.AnyAsync(u => u.Id == dataId && u.CategoryId == categoryId, false); if (!isExist) { throw Oops.Oh(SystemErrorCodes.u1002); } var dictionaryData = input.Adapt <SystemData>(); // 配置主外键和更新时间 dictionaryData.Id = dataId; dictionaryData.CategoryId = categoryId; dictionaryData.UpdatedTime = DateTimeOffset.Now; await _dataRepository.UpdateExcludeAsync(dictionaryData, new[] { nameof(SystemData.IsDeleted), nameof(SystemData.CreatedTime) }, ignoreNullValues : true); }
/// <summary> /// 新增字典数据 /// </summary> /// <param name="categoryId"></param> /// <param name="input"></param> /// <returns></returns> public async Task <SystemDataProfile> AddDictionaryDataAsync([Required, Range(1, int.MaxValue, ErrorMessage = "请输入有效的字典分类Id"), ApiSeat(ApiSeats.ActionStart)] int categoryId, [Required] EditSystemDataInput input) { // 查询字典分类是否存在 var isExist = await _categoryRepository.AnyAsync(u => u.Id == categoryId, false); if (!isExist) { throw Oops.Oh(SystemErrorCodes.u1002); } var dictionaryData = input.Adapt <SystemData>(); // 配置分类主键 dictionaryData.CategoryId = categoryId; var newObj = await _dataRepository.InsertNowAsync(dictionaryData); return(newObj.Entity.Adapt <SystemDataProfile>()); }