back photo + event tags and persons
This commit is contained in:
48
back/context/UserContext.cs
Normal file
48
back/context/UserContext.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using back.DataModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace back.context;
|
||||
|
||||
public class UserContext : DbContext
|
||||
{
|
||||
public DbSet<UserModel> Users { get; set; }
|
||||
public UserContext(DbContextOptions<UserContext> options) : base(options)
|
||||
{
|
||||
// Ensure database is created
|
||||
Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public async Task<UserModel?> GetById(Guid id)
|
||||
{
|
||||
return await Users.FindAsync(id);
|
||||
}
|
||||
|
||||
public async Task<int> GetTotalItems()
|
||||
{
|
||||
return await Users.CountAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<UserModel>> GetPage(int page = 1, int pageSize = 20)
|
||||
{
|
||||
if (page < 1) page = 1;
|
||||
if (pageSize < 1) pageSize = 20;
|
||||
|
||||
return await Users
|
||||
.OrderByDescending(p => p.CreatedAt)
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> Exists(UserModel? photo)
|
||||
{
|
||||
if (photo == null) return false;
|
||||
if (string.IsNullOrEmpty(photo.Id)) return false;
|
||||
return await Users.AnyAsync(p => p.Id == photo.Id);
|
||||
}
|
||||
|
||||
public async Task<bool> Exists(string id)
|
||||
{
|
||||
return await Users.AnyAsync(p => p.Id == id);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user