Add project files.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user