public async Task <SystemDataCategoryProfile> AddAsync([Required] EditSystemDataCategoryInput input) { // 判断分类名是否存在 var isExist = await _categoryRepository.AnyAsync(u => u.Name.Trim().Equals(input.Name.Trim())); if (isExist) { throw Oops.Oh(SystemErrorCodes.u1006); } var addCategory = input.Adapt <SystemDataCategory>(); var entryEntity = await _categoryRepository.InsertNowAsync(addCategory); return(entryEntity.Entity.Adapt <SystemDataCategoryProfile>()); }
/// <summary> /// 修改分类信息 /// </summary> /// <param name="categoryId"></param> /// <param name="input"></param> /// <returns></returns> public async Task ModifyAsync([Required, Range(1, int.MaxValue, ErrorMessage = "请输入有效的分类 Id"), ApiSeat(ApiSeats.ActionStart)] int categoryId, [Required] EditSystemDataCategoryInput input) { // 查询分类是否存在 var isExist = await _categoryRepository.AnyAsync(u => u.Id == categoryId, false); if (!isExist) { throw Oops.Oh(SystemErrorCodes.u1002); } var modifyCategory = input.Adapt <SystemDataCategory>(); // 配置主键和更新时间 modifyCategory.Id = categoryId; modifyCategory.UpdatedTime = DateTimeOffset.Now; await _categoryRepository.UpdateExcludeAsync(modifyCategory, new[] { nameof(Role.IsDeleted), nameof(Role.CreatedTime) }, ignoreNullValues : true); }