fronted: login
This commit is contained in:
@@ -162,36 +162,71 @@ public class PhotoContext : DbContext
|
||||
|
||||
public async Task<PhotoModel?> GetById(Guid id)
|
||||
{
|
||||
return await Photos.FindAsync(id);
|
||||
try
|
||||
{
|
||||
return await Photos.FindAsync(id);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> GetTotalItems()
|
||||
{
|
||||
return await Photos.CountAsync();
|
||||
try
|
||||
{
|
||||
return await Photos.CountAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PhotoModel>> GetPage(int page = 1, int pageSize = 20)
|
||||
public async Task<IEnumerable<PhotoModel>?> GetPage(int page = 1, int pageSize = 20)
|
||||
{
|
||||
if (page < 1) page = 1;
|
||||
if (pageSize < 1) pageSize = 20;
|
||||
|
||||
return await Photos
|
||||
try
|
||||
{
|
||||
return await Photos
|
||||
.OrderByDescending(p => p.CreatedAt)
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> Exists(PhotoModel? photo)
|
||||
{
|
||||
if (photo == null) return false;
|
||||
if (string.IsNullOrEmpty(photo.Id)) return false;
|
||||
return await Photos.AnyAsync(p => p.Id == photo.Id);
|
||||
try
|
||||
{
|
||||
if (photo == null) return false;
|
||||
if (string.IsNullOrEmpty(photo.Id)) return false;
|
||||
return await Photos.AnyAsync(p => p.Id == photo.Id);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false; // Handle exceptions gracefully
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> Exists(string id)
|
||||
{
|
||||
return await Photos.AnyAsync(p => p.Id == id);
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return false;
|
||||
return await Photos.AnyAsync(p => p.Id == id);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false; // Handle exceptions gracefully
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Delete(PhotoModel photo)
|
||||
|
Reference in New Issue
Block a user