From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../GenericRepository_T_.cs | 90 ++++++++++++++++++++++ .../IGenericRepository_TEntity_.cs | 31 ++++++++ 2 files changed, 121 insertions(+) create mode 100644 Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Generic/GenericRepository_T_.cs create mode 100644 Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Generic/IGenericRepository_TEntity_.cs (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Generic') diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Generic/GenericRepository_T_.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Generic/GenericRepository_T_.cs new file mode 100644 index 0000000..f0c15d7 --- /dev/null +++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Generic/GenericRepository_T_.cs @@ -0,0 +1,90 @@ +using Gestor.Infrastructure.Entities.Generic; +using NHibernate; +using NHibernate.Linq; +using NHibernate.Util; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; + +namespace Gestor.Infrastructure.Repository.Generic +{ + public class GenericRepository : IGenericRepository + where T : class + { + private readonly ISession _currentSession; + + public GenericRepository(ISession currentSession) + { + this._currentSession = currentSession; + } + + public virtual void Add(T entity) + { + this._currentSession.Save(entity); + } + + public void AddRange(IEnumerable entities) + { + if (entities != null) + { + entities.ForEach((T entity) => this._currentSession.Save(entity)); + } + } + + public IQueryable All() + { + return this._currentSession.Query(); + } + + public void Delete(T entity) + { + this._currentSession.Delete(entity); + } + + public void DeleteRange(IEnumerable entities) + { + if (entities != null) + { + entities.ForEach((T entity) => this._currentSession.Delete(entity)); + } + } + + public void Evict(TEntity entity) + where TEntity : EntityBase + { + this._currentSession.Evict(entity); + } + + public T FindEntityById(long id) + { + return this._currentSession.Get(id); + } + + protected void Load(TEntity entity) + where TEntity : EntityBase + { + EntityBase entityBase = entity; + if (entityBase == null) + { + return; + } + this._currentSession.Load(entity, entityBase.Id); + } + + public void Merge(T entity) + { + this._currentSession.Merge(entity); + } + + public virtual void SaveOrUpdate(T entity) + { + this._currentSession.SaveOrUpdate(entity); + } + + public void Update(T entity) + { + this._currentSession.Update(entity); + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Generic/IGenericRepository_TEntity_.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Generic/IGenericRepository_TEntity_.cs new file mode 100644 index 0000000..3f43a5c --- /dev/null +++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Generic/IGenericRepository_TEntity_.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Gestor.Infrastructure.Repository.Generic +{ + public interface IGenericRepository + where TEntity : class + { + void Add(TEntity entity); + + void AddRange(IEnumerable entities); + + IQueryable All(); + + void Delete(TEntity entity); + + void DeleteRange(IEnumerable entities); + + void Evict(TE entity) + where TE : EntityBase; + + TEntity FindEntityById(long id); + + void Merge(TEntity entity); + + void SaveOrUpdate(TEntity entity); + + void Update(TEntity entity); + } +} \ No newline at end of file -- cgit v1.2.3