public async Task <ResultEntity> AddOrUpdateAsync(Rule barcodeRule) { var result = new ResultEntity(); var exist = await _ruleRepository.GetQueryable().Where(a => a.Name == barcodeRule.Name && a.Id != barcodeRule.Id).CountAsync() > 0; if (exist) { result.Message = "规则名称已存在"; } else { if (barcodeRule.Id > 0) { _ruleRepository.Update(barcodeRule); } else { await _ruleRepository.AddAsync(barcodeRule); } result.Success = true; } return(result); }
public async Task <RuleResponse> SaveAsync(Rule rule) { try { await _ruleRepository.AddAsync(rule); await _unitOfWork.CompleteAsync(); return(new RuleResponse(rule)); } catch (Exception e) { return(new RuleResponse($"An error occurred when saving the rule: {e.Message}")); } }