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