transactions
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using back.DataModels;
|
||||
using DependencyInjector.Lifetimes;
|
||||
using Transactional.Abstractions.Interfaces;
|
||||
|
||||
namespace back.persistance.data.repositories.Abstracts;
|
||||
|
||||
public interface IPersonRepository : IRepository<Person, string>, IScoped
|
||||
{
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
using back.DataModels;
|
||||
using DependencyInjector.Lifetimes;
|
||||
using Transactional.Abstractions.Interfaces;
|
||||
|
||||
namespace back.persistance.data.repositories.Abstracts;
|
||||
|
||||
public interface IPhotoRepository : IRepository<Photo, string>, IScoped
|
||||
{ }
|
@@ -0,0 +1,14 @@
|
||||
using back.DataModels;
|
||||
using DependencyInjector.Lifetimes;
|
||||
using Transactional.Abstractions.Interfaces;
|
||||
|
||||
namespace back.persistance.data.repositories.Abstracts;
|
||||
|
||||
public interface IUserRepository : IRepository<User, string>, IScoped
|
||||
{
|
||||
Task<User?> GetByEmail(string email);
|
||||
Task<string?> GetUserSaltByEmail(string email);
|
||||
Task<User?> Login(string email, string password);
|
||||
Task<bool> ExistsByEmail(string email);
|
||||
//Task<bool> IsContentManager(string userId);
|
||||
}
|
10
back/persistance/data/repositories/PersonRepository.cs
Normal file
10
back/persistance/data/repositories/PersonRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using back.DataModels;
|
||||
using back.persistance.data.repositories.Abstracts;
|
||||
using Transactional.Implementations.EntityFramework;
|
||||
|
||||
namespace back.persistance.data.repositories;
|
||||
|
||||
public class PersonRepository(DataContext context) : ReadWriteRepository<Person, string>(context), IPersonRepository
|
||||
{
|
||||
// Implement methods specific to Photo repository if needed
|
||||
}
|
10
back/persistance/data/repositories/PhotoRepository.cs
Normal file
10
back/persistance/data/repositories/PhotoRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using back.DataModels;
|
||||
using back.persistance.data.repositories.Abstracts;
|
||||
using Transactional.Implementations.EntityFramework;
|
||||
|
||||
namespace back.persistance.data.repositories;
|
||||
|
||||
public class PhotoRepository(DataContext context) : ReadWriteRepository<Photo, string>(context), IPhotoRepository
|
||||
{
|
||||
// Implement methods specific to Photo repository if needed
|
||||
}
|
70
back/persistance/data/repositories/UserRepository.cs
Normal file
70
back/persistance/data/repositories/UserRepository.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using back.DataModels;
|
||||
using back.persistance.data.repositories.Abstracts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Transactional.Implementations.EntityFramework;
|
||||
|
||||
namespace back.persistance.data.repositories;
|
||||
|
||||
public class UserRepository(DataContext context) : ReadWriteRepository<User, string>(context), IUserRepository
|
||||
{
|
||||
public async Task<User?> GetByEmail(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(email)) return null;
|
||||
return await Entity.FirstOrDefaultAsync(u => u.Email == email);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string?> GetUserSaltByEmail(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(email)) return string.Empty;
|
||||
var user = await Entity.FirstOrDefaultAsync(u => u.Email == email);
|
||||
return user?.Salt ?? string.Empty;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<User?> Login(string email, string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) return null;
|
||||
try
|
||||
{
|
||||
return await Entity.FirstOrDefaultAsync(u => u.Email == email && u.Password == password);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> ExistsByEmail(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(email)) return false;
|
||||
return await Entity.AnyAsync(u => u.Email == email);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//public async Task<bool> IsContentManager(string userId)
|
||||
//{
|
||||
// var user = await GetById(userId);
|
||||
// if (user == null)
|
||||
// return false;
|
||||
// return user.Roles.Any(role => role.IsContentManager() || role.IsAdmin());
|
||||
//}
|
||||
}
|
Reference in New Issue
Block a user