From d9e10ae4715708ffdec98ff89b320f34fe9024ec Mon Sep 17 00:00:00 2001 From: jojo aquino Date: Fri, 28 Mar 2025 18:08:54 +0000 Subject: [PATCH] new dbcontext UpdateOrCreate --- EnotaryoPH/EnotaryoPH.Data/NotaryoDBContext.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/EnotaryoPH/EnotaryoPH.Data/NotaryoDBContext.cs b/EnotaryoPH/EnotaryoPH.Data/NotaryoDBContext.cs index 0ad5e93..e300789 100644 --- a/EnotaryoPH/EnotaryoPH.Data/NotaryoDBContext.cs +++ b/EnotaryoPH/EnotaryoPH.Data/NotaryoDBContext.cs @@ -38,5 +38,18 @@ namespace EnotaryoPH.Data public DbSet TransactionSignatoryDeclineReasons { get; set; } public DbSet Users { get; set; } public DbSet VideoRecordings { get; set; } + + public TEntity UpdateOrCreate(TEntity entity) where TEntity : class + { + if (Entry(entity).State == EntityState.Detached) + { + Set().Add(entity); + } + else + { + Set().Update(entity); + } + return entity; + } } } \ No newline at end of file