public async Task <CrispyKeyValuePair> AddAsync([NotNull] CrispyKeyValuePairAddtionContext context) { if (await Query().AnyAsync(x => x.EnvironmentId == context.EnvironmentId && x.Key == context.Key)) { throw new ArgumentException($"{ (context.EnvironmentId == null ? "全局配置" : "当前环境")}已存在 Key 为 {context.Key} 的配置项"); } var pair = new CrispyKeyValuePair { EnvironmentId = context.EnvironmentId, Key = context.Key, Value = context.Value, ValueType = context.ValueType, Description = context.Description }; Store.KeyValuePairs.Add(pair); Store.KeyValuePairHistories.Add(new CrispyKeyValuePairHistory(pair.Id, pair.Value, pair.ValueType)); await SaveChangesAsync(); return(pair); }
public async Task <IActionResult> AddAsync([NotNull, FromBody] CrispyKeyValuePairAddtionContext context) { await KeyValuePairService.AddAsync(context); return(Ok()); }