|
|
|
@ -10,7 +10,7 @@ using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Contextlib
|
|
|
|
|
{
|
|
|
|
|
public class DbCommentaryManager : ICommentService<Commentary>
|
|
|
|
|
public class DbCommentaryManager : ICommentaryService<Commentary>
|
|
|
|
|
{
|
|
|
|
|
private WTFContext _context;
|
|
|
|
|
private GenericRepository<Commentary> _repo;
|
|
|
|
@ -44,7 +44,7 @@ namespace Contextlib
|
|
|
|
|
/// <param name="quoteId">The ID of the quote whose comments need to be deleted.</param>
|
|
|
|
|
/// <returns>A task representing the asynchronous operation.</returns>
|
|
|
|
|
/// <exception cref="KeyNotFoundException">Thrown when no comments are found for the provided quote ID.</exception>
|
|
|
|
|
public async Task DeleteCommentForQuote(int quoteId)
|
|
|
|
|
public async Task DeleteCommentaryForQuote(int quoteId)
|
|
|
|
|
{
|
|
|
|
|
var comments = await _context.comments.Where(x => x.IdQuote == quoteId).ToListAsync();
|
|
|
|
|
if (!comments.Any())
|
|
|
|
@ -62,7 +62,7 @@ namespace Contextlib
|
|
|
|
|
/// <param name="userId">The ID of the user whose comments need to be deleted.</param>
|
|
|
|
|
/// <returns>A task representing the asynchronous operation.</returns>
|
|
|
|
|
/// <exception cref="KeyNotFoundException">Thrown when no comments are found for the provided user ID.</exception>
|
|
|
|
|
public async Task DeleteCommentForUser(int userId)
|
|
|
|
|
public async Task DeleteCommentaryForUser(int userId)
|
|
|
|
|
{
|
|
|
|
|
var comments = await _context.comments.Include(c => c.User).Where(x => x.IdUser == userId).ToListAsync();
|
|
|
|
|
if (!comments.Any())
|
|
|
|
@ -74,13 +74,13 @@ namespace Contextlib
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<PaginationResult<Commentary>> GetAllComment()
|
|
|
|
|
public async Task<PaginationResult<Commentary>> GetAllCommentary()
|
|
|
|
|
{
|
|
|
|
|
var comments = await _context.comments.Include(c => c.User).ToListAsync();
|
|
|
|
|
return new PaginationResult<Commentary>(comments.Count, 0, comments.Count, comments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Commentary> GetCommentById(int id)
|
|
|
|
|
public async Task<Commentary> GetCommentaryById(int id)
|
|
|
|
|
{
|
|
|
|
|
var comment = await _context.comments.Include(c => c.User).Where(x => x.Id == id).FirstOrDefaultAsync();
|
|
|
|
|
if(comment == null)
|
|
|
|
@ -90,7 +90,7 @@ namespace Contextlib
|
|
|
|
|
return comment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<PaginationResult<Commentary>> GetCommentByQuote(int quoteId, int index, int pageSize)
|
|
|
|
|
public async Task<PaginationResult<Commentary>> GetCommentaryByQuote(int quoteId, int index, int pageSize)
|
|
|
|
|
{
|
|
|
|
|
var comments = await _context.comments.Include(c => c.User).Where(x => x.IdQuote == quoteId).ToListAsync();
|
|
|
|
|
if (!comments.Any())
|
|
|
|
@ -112,7 +112,7 @@ namespace Contextlib
|
|
|
|
|
return new PaginationResult<Commentary>(comments.Count, index, pageSize, comments.Skip(index * pageSize).Take(pageSize).ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<PaginationResult<Commentary>> GetCommentByUser(int userId, int index, int pageSize)
|
|
|
|
|
public async Task<PaginationResult<Commentary>> GetCommentaryByUser(int userId, int index, int pageSize)
|
|
|
|
|
{
|
|
|
|
|
var comments = await _context.comments.Include(c => c.User).Where(x => x.IdUser == userId).ToListAsync();
|
|
|
|
|
if (!comments.Any())
|
|
|
|
@ -134,7 +134,7 @@ namespace Contextlib
|
|
|
|
|
return new PaginationResult<Commentary>(comments.Count, index, pageSize, comments.Skip(index * pageSize).Take(pageSize).ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> LastCommentId()
|
|
|
|
|
public async Task<int> LastCommentaryId()
|
|
|
|
|
{
|
|
|
|
|
var last = await _context.comments.OrderByDescending(x => x.Id).FirstOrDefaultAsync();
|
|
|
|
|
if(last == null)
|
|
|
|
@ -144,13 +144,13 @@ namespace Contextlib
|
|
|
|
|
return last.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task RemoveComment(int id)
|
|
|
|
|
public async Task RemoveCommentary(int id)
|
|
|
|
|
{
|
|
|
|
|
_repo.Delete(id);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task UpdateComment(int id, Commentary comment)
|
|
|
|
|
public async Task UpdateCommentary(int id, Commentary comment)
|
|
|
|
|
{
|
|
|
|
|
var modif = false;
|
|
|
|
|
var com = await _context.comments.Where(x => x.Id == id).FirstOrDefaultAsync();
|
|
|
|
|