first commit
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Fitness_core_BE.Interfaces;
|
||||
using Fitness_core_BE.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Fitness_core_BE.Repos
|
||||
{
|
||||
public class DocumentRepository : IDocumentRepository
|
||||
{
|
||||
private readonly CentralDbContext _context;
|
||||
|
||||
public DocumentRepository(CentralDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<UserDocument> UploadDocumentAsync(UserDocument userDocument)
|
||||
{
|
||||
await _context.UserDocuments.AddAsync(userDocument);
|
||||
return userDocument;
|
||||
}
|
||||
|
||||
public async Task<string> GetLastSequnce()
|
||||
{
|
||||
var lastDoc = await _context.UserDocuments
|
||||
.OrderByDescending(d => d.Created_At)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (lastDoc == null)
|
||||
return "00001";
|
||||
|
||||
// Extract sequence number from Doc_Name or generate new one
|
||||
var docs = await _context.UserDocuments.CountAsync();
|
||||
return (docs + 1).ToString("D5");
|
||||
}
|
||||
|
||||
public async Task<List<UserDocument>> GetDocumentsByUserId(Guid userId)
|
||||
{
|
||||
return await _context.UserDocuments
|
||||
.Include(d => d.DocumentType)
|
||||
.Where(d => d.UserId == userId && d.IsActive)
|
||||
.OrderByDescending(d => d.Created_At)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<UserDocument?> GetDocumentById(int documentId)
|
||||
{
|
||||
return await _context.UserDocuments
|
||||
.Include(d => d.DocumentType)
|
||||
.FirstOrDefaultAsync(d => d.DocumentId == documentId && d.IsActive);
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveDocument(int documentId)
|
||||
{
|
||||
var document = await _context.UserDocuments.FindAsync(documentId);
|
||||
|
||||
if (document == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
document.IsActive = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user