Add project files.

This commit is contained in:
Sergio Matias Urquin
2025-04-29 18:39:57 -06:00
parent 116793710f
commit 6358f5f199
110 changed files with 4484 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
using Core.Blueprint.DAL.Infrastructure.Context;
using Core.Blueprint.DAL.Infrastructure.Contracts;
using Core.Blueprint.Domain.Entities;
namespace Core.Blueprint.DAL.Infrastructure.Repository
{
public abstract class RepositorySqlBase<T> : IRepositoryIdentityBase<T> where T: AbsEntity
{
protected SqlServerContext _dbContext;
protected RepositorySqlBase(SqlServerContext dbContext)
{
_dbContext = dbContext;
}
public async ValueTask<T> CreateAsync(T blueprint)
{
blueprint.Id = Guid.NewGuid().ToString();
_dbContext.Add(blueprint);
await _dbContext.SaveChangesAsync();
return blueprint;
}
public async Task<bool> DeleteAsync(string id)
{
var item = await GetByIdAsync(id);
if (item == null)
{
return false;
}
_dbContext.Remove(item);
await _dbContext.SaveChangesAsync();
return true;
}
public async ValueTask<IQueryable<T>> GetAllAsync()
{
return _dbContext.Set<T>();
}
public async ValueTask<T> GetByIdAsync(string id)
{
var result = await _dbContext.FindAsync<T>(id);
return result;
}
public async Task<bool> UpdateAsync(string id, T entity)
{
_dbContext.Update(entity);
await _dbContext.SaveChangesAsync();
return true;
}
}
}