using Microsoft.EntityFrameworkCore;
namespace Kruzya.TelegramBot.Core.Extensions
{
public static class RepositoryExtension
{
#region DbContext
///
/// Marks the entity as created.
///
///
/// Entity for marking as created.
public static void MarkAsCreated(this DbContext dbContext, object entity) =>
dbContext.Entry(entity).State = EntityState.Added;
///
/// Marks the entity as deleted.
///
///
/// Entity for marking as deleted.
public static void MarkAsDeleted(this DbContext dbContext, object entity) =>
dbContext.Entry(entity).State = EntityState.Deleted;
///
/// Marks the entity as modified.
///
///
/// Entity for marking as modified.
public static void MarkAsModified(this DbContext dbContext, object entity) =>
dbContext.Entry(entity).State = EntityState.Modified;
#endregion
#region Repository
public static TEntity Create(this DbSet repository) where TEntity : class, new()
{
var entity = new TEntity();
repository.Add(entity);
return entity;
}
#endregion
}
}