From 9659027b7858d6fa53ee5ace059cf3b80869d521 Mon Sep 17 00:00:00 2001 From: honzapatCZ Date: Fri, 20 Jun 2025 20:34:03 +0200 Subject: [PATCH] add new quickups --- Models/CommonDbContext.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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();