diff --git a/Models/CommonDbContext.cs b/Models/CommonDbContext.cs index 0b289e7..cc728c2 100644 --- a/Models/CommonDbContext.cs +++ b/Models/CommonDbContext.cs @@ -80,6 +80,20 @@ public abstract class CommonDbContext : DbContext else return SaveError; } + public async Task, Ok>>> ApiSaveChangesAsyncOk(IServiceProvider providers, IEnumerable value, bool apply = true, T2? response = null) where T2 : class, IAutomappedAttribute, new() + { + if(response == null) + response = new T2(); + if (!apply) + return TypedResults.Ok(value.Select(x=> new T2().ApplyFrom(providers, x)).ToList()); + + var res = await ApiSaveChangesAsync(); + + if (res) + return TypedResults.Ok(value.Select(x=> new T2().ApplyFrom(providers, x)).ToList()); + else + return SaveError; + } public async Task, Ok>> ApiSaveChangesAsyncOk() { var res = await ApiSaveChangesAsync();