Add project files.

This commit is contained in:
Sergio Matias Urquin
2025-04-29 18:42:29 -06:00
parent 9c1958d351
commit 83fc1878c4
67 changed files with 4586 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
using Core.Blueprint.SQLServer.Entities;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace Core.Blueprint.SQLServer
{
/// <summary>
/// Defines the interface for SQL Server entities, providing common properties for auditing and state management.
/// </summary>
public interface IBaseSQLAdapter
{
/// <summary>
/// Gets or sets the identifier for the entity.
/// </summary>
[Key]
[JsonPropertyName("id")]
int Id { get; }
/// <summary>
/// Gets or sets the GUID for the entity.
/// </summary>
[JsonPropertyName("guid")]
string Guid { get; }
/// <summary>
/// Gets or sets the timestamp when the entity was created.
/// </summary>
[JsonPropertyName("createdAt")]
DateTime? CreatedAt { get; }
/// <summary>
/// Gets or sets the identifier of the user or system that created the entity.
/// </summary>
[JsonPropertyName("createdBy")]
string? CreatedBy { get; set; }
/// <summary>
/// Gets or sets the timestamp when the entity was last updated.
/// </summary>
[JsonPropertyName("updatedAt")]
DateTime? UpdatedAt { get; set; }
/// <summary>
/// Gets or sets the identifier of the user or system that last updated the entity.
/// </summary>
[JsonPropertyName("updatedBy")]
string? UpdatedBy { get; set; }
/// <summary>
/// Gets or sets the status of the entity, indicating whether it is active, inactive, or in another state.
/// </summary>
[JsonPropertyName("status")]
[JsonConverter(typeof(JsonStringEnumConverter))]
StatusEnum Status { get; set; }
}
}

View File

@@ -0,0 +1,108 @@
using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;
namespace Core.Blueprint.DAL.SQLServer
{
/// <summary>
/// Defines the contract for a generic repository to manage entities in a SQL Server database.
/// </summary>
/// <typeparam name="TEntity">The type of the entity managed by the repository. Must be a class.</typeparam>
/// <typeparam name="TContext">The type of the database context used by the repository. Must inherit from <see cref="DbContext"/>.</typeparam>
public interface IEntityRepository<TEntity, TContext>
where TEntity : class
where TContext : DbContext
{
/// <summary>
/// Retrieves all entities of type <typeparamref name="T"/> from the database.
/// </summary>
/// <returns>A task representing the asynchronous operation, with a collection of entities as the result.</returns>
Task<IEnumerable<TEntity>> GetAllAsync();
/// <summary>
/// Retrieves all entities of type <typeparamref name="T"/> from the database that match a specified condition.
/// </summary>
/// <param name="predicate">An expression to filter the entities.</param>
/// <returns>A task representing the asynchronous operation, with a collection of matching entities as the result.</returns>
Task<IEnumerable<TEntity>> GetByConditionAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Retrieves a single entity of type <typeparamref name="T"/> by its identifier.
/// </summary>
/// <param name="id">The identifier of the entity to retrieve.</param>
/// <returns>A task representing the asynchronous operation, with the entity as the result, or null if not found.</returns>
Task<TEntity?> GetByIdAsync(int id);
/// <summary>
/// Retrieves the first entity of type <typeparamref name="T"/> that matches a specified condition, or null if no match is found.
/// </summary>
/// <param name="predicate">An expression to filter the entities.</param>
/// <returns>A task representing the asynchronous operation, with the matching entity as the result, or null if none match.</returns>
Task<TEntity?> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Adds a new entity of type <typeparamref name="T"/> to the database.
/// </summary>
/// <param name="entity">The entity to add.</param>
/// <returns>A task representing the asynchronous operation.</returns>
Task AddAsync(TEntity entity);
/// <summary>
/// Adds multiple entities of type <typeparamref name="T"/> to the database.
/// </summary>
/// <param name="entities">The collection of entities to add.</param>
/// <returns>A task representing the asynchronous operation.</returns>
Task AddRangeAsync(IEnumerable<TEntity> entities);
/// <summary>
/// Updates an existing entity of type <typeparamref name="T"/> in the database.
/// </summary>
/// <param name="entity">The entity to update.</param>
/// <returns>The updated entity.</returns>
TEntity Update(TEntity entity);
/// <summary>
/// Updates multiple entities of type <typeparamref name="T"/> in the database.
/// </summary>
/// <param name="entities">The collection of entities to update.</param>
void UpdateRange(IEnumerable<TEntity> entities);
/// <summary>
/// Deletes an entity of type <typeparamref name="T"/> from the database.
/// </summary>
/// <param name="entity">The entity to delete.</param>
void Delete(TEntity entity);
/// <summary>
/// Deletes multiple entities of type <typeparamref name="T"/> from the database.
/// </summary>
/// <param name="entities">The collection of entities to delete.</param>
void DeleteRange(IEnumerable<TEntity> entities);
/// <summary>
/// Determines whether any entities of type <typeparamref name="T"/> exist in the database that match a specified condition.
/// </summary>
/// <param name="predicate">An expression to filter the entities.</param>
/// <returns>A task representing the asynchronous operation, with a boolean result indicating whether any match exists.</returns>
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Executes a raw SQL query and maps the result to entities of type <typeparamref name="T"/>.
/// </summary>
/// <param name="sql">The raw SQL query to execute.</param>
/// <param name="parameters">Optional parameters for the SQL query.</param>
/// <returns>A task representing the asynchronous operation, with a collection of entities as the result.</returns>
Task<IEnumerable<TEntity>> ExecuteRawSqlAsync(string sql, params object[] parameters);
/// <summary>
/// Counts the total number of entities of type <typeparamref name="T"/> in the database.
/// </summary>
/// <returns>A task representing the asynchronous operation, with the count as the result.</returns>
Task<int> CountAsync();
/// <summary>
/// Saves all pending changes to the database.
/// </summary>
/// <returns>A task representing the asynchronous operation.</returns>
Task SaveAsync();
}
}