|
|
@ -55,13 +55,9 @@ namespace Contextlib
|
|
|
|
List<Quote> quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang)
|
|
|
|
List<Quote> quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang)
|
|
|
|
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite)
|
|
|
|
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite)
|
|
|
|
.ToListAsync();
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
if (quotes.Count() == 0) return null;
|
|
|
|
Quote quote = quotes[date.DayNumber % quotes.Count()];
|
|
|
|
Quote quote = quotes[date.DayNumber % quotes.Count()];
|
|
|
|
/*Quote quote = await _context.quotes.Where(item => item.Id == date.DayNumber % quotes.Count())
|
|
|
|
|
|
|
|
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite)
|
|
|
|
|
|
|
|
.FirstOrDefaultAsync() ?? quotes.First();*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First();
|
|
|
|
|
|
|
|
return quote;
|
|
|
|
return quote;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -106,15 +102,12 @@ namespace Contextlib
|
|
|
|
return lastQuoteId;
|
|
|
|
return lastQuoteId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<Quote> GetQuoteById(int id)
|
|
|
|
public async Task<Quote?> GetQuoteById(int id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Quote? quote = _context.quotes.Where(item => item.Id == id)
|
|
|
|
Quote? quote = _context.quotes.Where(item => item.Id == id)
|
|
|
|
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
|
|
|
|
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
|
|
|
|
.First();
|
|
|
|
.FirstOrDefault();
|
|
|
|
if (quote == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new KeyNotFoundException($"Error : No quotes found with the ID: {id}.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return quote;
|
|
|
|
return quote;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -179,8 +172,9 @@ namespace Contextlib
|
|
|
|
|
|
|
|
|
|
|
|
public async Task RemoveQuote(int quoteId)
|
|
|
|
public async Task RemoveQuote(int quoteId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var quote = _repo.GetById(quoteId);
|
|
|
|
_repo.Delete( _repo.GetById(quoteId) );
|
|
|
|
if (quote == null) throw new KeyNotFoundException();
|
|
|
|
|
|
|
|
_repo.Delete( quote );
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -210,11 +204,27 @@ namespace Contextlib
|
|
|
|
q.IdUsersPropose = quote.IdUsersPropose;
|
|
|
|
q.IdUsersPropose = quote.IdUsersPropose;
|
|
|
|
change = true;
|
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (quote.Content != null || quote.Content =="")
|
|
|
|
if (quote.Content != null || quote.Content == "")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
q.Content = quote.Content;
|
|
|
|
q.Content = quote.Content;
|
|
|
|
change = true;
|
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quote.IsValid != q.IsValid)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
q.IsValid = quote.IsValid;
|
|
|
|
|
|
|
|
change = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quote.Likes != q.Likes)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
q.Likes = quote.Likes;
|
|
|
|
|
|
|
|
change = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quote.Langage != q.Langage)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
q.Langage = quote.Langage;
|
|
|
|
|
|
|
|
change = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_repo.Update(q);
|
|
|
|
_repo.Update(q);
|
|
|
|
if (change) _context.SaveChanges();
|
|
|
|
if (change) _context.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|