public async Task <ADreamResult> SaveChangesAsync(CancellationToken cancellationToken = default) { if (!AutoSaveChanges) { return(ADreamResult.Failed(new ADreamError { Code = nameof(AutoSaveChanges), Description = $"没有设置{ nameof(AutoSaveChanges)}为真,所以没有保存到数据库" })); } using (var scope = dbContext.Database.BeginTransaction()) { try { var c = await dbContext.SaveChangesAsync(cancellationToken); scope.Commit(); var result = ADreamResult.Success; result.Result = c; return(result); } catch (DbUpdateConcurrencyException ex) { Logger.Error(ex.Message, ex); scope.Rollback(); return(ADreamResult.Failed(new ADreamError { Code = ex.HResult.ToString(), Description = ex.ToJson() })); } } }
protected IActionResult ValidFailed() { var err = GetModelError().Append(new ADreamError { Description = "请检测你的输入!" }); aDreamResult = ADreamResult.Failed(err.ToArray()); return(JsonOrView(ADreamResult.Failed(err.ToArray()))); }