public ResultDto Put(int id, [FromBody] CreateUpdateBaseItemDto updateBaseItem) { BaseItem baseItem = _baseItemRepository.Select.Where(r => r.Id == id).ToOne(); if (baseItem == null) { throw new LinCmsException("该数据不存在"); } bool typeExist = _baseTypeRepository.Select.Any(r => r.Id == updateBaseItem.BaseTypeId); if (!typeExist) { throw new LinCmsException("请选择正确的类别"); } bool exist = _baseItemRepository.Select.Any(r => r.BaseTypeId == updateBaseItem.BaseTypeId && r.ItemCode == updateBaseItem.ItemCode && r.Id != id); if (exist) { throw new LinCmsException($"编码[{updateBaseItem.ItemCode}]已存在"); } _mapper.Map(updateBaseItem, baseItem); _baseItemRepository.Update(baseItem); return(ResultDto.Success("更新字典成功")); }
public async Task UpdateAsync(int id, CreateUpdateBaseItemDto updateBaseItem) { BaseItem baseItem = await _baseItemRepository.Select.Where(r => r.Id == id).ToOneAsync(); if (baseItem == null) { throw new LinCmsException("该数据不存在"); } bool typeExist = await _baseTypeRepository.Select.AnyAsync(r => r.Id == updateBaseItem.BaseTypeId); if (!typeExist) { throw new LinCmsException("请选择正确的类别"); } bool exist = await _baseItemRepository.Select.AnyAsync(r => r.BaseTypeId == updateBaseItem.BaseTypeId && r.ItemCode == updateBaseItem.ItemCode && r.Id != id); if (exist) { throw new LinCmsException($"编码[{updateBaseItem.ItemCode}]已存在"); } _mapper.Map(updateBaseItem, baseItem); await _baseItemRepository.UpdateAsync(baseItem); }
public async Task CreateAsync(CreateUpdateBaseItemDto createBaseItem) { bool exist = await _baseItemRepository.Select.AnyAsync(r => r.BaseTypeId == createBaseItem.BaseTypeId && r.ItemCode == createBaseItem.ItemCode); if (exist) { throw new LinCmsException($"编码[{createBaseItem.ItemCode}]已存在"); } BaseItem baseItem = _mapper.Map <BaseItem>(createBaseItem); await _baseItemRepository.InsertAsync(baseItem); }
public ResultDto Post([FromBody] CreateUpdateBaseItemDto createBaseItem) { bool exist = _baseItemRepository.Select.Any(r => r.BaseTypeId == createBaseItem.BaseTypeId && r.ItemCode == createBaseItem.ItemCode); if (exist) { throw new LinCmsException($"编码[{createBaseItem.ItemCode}]已存在"); } BaseItem baseItem = _mapper.Map <BaseItem>(createBaseItem); _baseItemRepository.Insert(baseItem); return(ResultDto.Success("新建字典成功")); }
public async Task <UnifyResponseDto> UpdateAsync(int id, [FromBody] CreateUpdateBaseItemDto updateBaseItem) { await _baseItemService.UpdateAsync(id, updateBaseItem); return(UnifyResponseDto.Success("更新字典成功")); }
public async Task <UnifyResponseDto> CreateAsync([FromBody] CreateUpdateBaseItemDto createBaseItem) { await _baseItemService.CreateAsync(createBaseItem); return(UnifyResponseDto.Success("新建字典成功")); }