Created Woodpecker CI/CD deployment
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- Created Dockerfile for packing up API and Web projects as Docker image
This commit is contained in:
35
API/YABA.Data/Extensions/GenericDbSetExtensions.cs
Normal file
35
API/YABA.Data/Extensions/GenericDbSetExtensions.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using YABA.Models.Interfaces;
|
||||
|
||||
namespace YABA.Data.Extensions
|
||||
{
|
||||
public static class GenericDbSetExtensions
|
||||
{
|
||||
public static void Upsert<T>(this DbSet<T> dbSet, T entity) where T : class, IIdentifiable
|
||||
{
|
||||
var entityInList = new List<T>() { entity };
|
||||
dbSet.UpsertRange(entityInList);
|
||||
}
|
||||
|
||||
public static void UpsertRange<T>(this DbSet<T> dbSet, IEnumerable<T> entities) where T : class, IIdentifiable
|
||||
{
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
var entityExists = dbSet.Any(x => x.Id == entity.Id);
|
||||
|
||||
if (entityExists)
|
||||
{
|
||||
EntityEntry<T> attachedEntity = dbSet.Attach(entity);
|
||||
attachedEntity.State = EntityState.Modified;
|
||||
}
|
||||
else
|
||||
{
|
||||
dbSet.Add(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user