|
|
|
@ -31,24 +31,37 @@ namespace Contextlib
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task AddQuote(Quote quote)
|
|
|
|
|
public async Task<Quote> AddQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
if (quote == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(quote), "quote cannot be null.");
|
|
|
|
|
}
|
|
|
|
|
//Character
|
|
|
|
|
var c = await _dbC.GetCharByName(quote.Character.Name);
|
|
|
|
|
if (c != null)
|
|
|
|
|
{
|
|
|
|
|
quote.IdCharacter = c.Id;
|
|
|
|
|
quote.Character = c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Image
|
|
|
|
|
var i = await _dbI.GetImageByPath(quote.Character.Images.ImgPath);
|
|
|
|
|
if (i != null)
|
|
|
|
|
{
|
|
|
|
|
quote.Character.IdImage = i.Id;
|
|
|
|
|
quote.Character.Images = i;
|
|
|
|
|
}
|
|
|
|
|
//Source
|
|
|
|
|
var s = await _dbS.GetSourceByTitle(quote.Source.Title);
|
|
|
|
|
if (s != null)
|
|
|
|
|
{
|
|
|
|
|
quote.IdSource = s.Id;
|
|
|
|
|
quote.Source = s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_repo.Insert(quote);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return quote;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<PaginationResult<Quote>> GetAllQuote()
|
|
|
|
@ -197,6 +210,28 @@ namespace Contextlib
|
|
|
|
|
|
|
|
|
|
public async Task UpdateQuote(int quoteId, Quote quote)
|
|
|
|
|
{
|
|
|
|
|
//Character
|
|
|
|
|
var c = await _dbC.GetCharByName(quote.Character.Name);
|
|
|
|
|
if (c != null)
|
|
|
|
|
{
|
|
|
|
|
quote.IdCharacter = c.Id;
|
|
|
|
|
quote.Character = c;
|
|
|
|
|
}
|
|
|
|
|
//Image
|
|
|
|
|
var i = await _dbI.GetImageByPath(quote.Character.Images.ImgPath);
|
|
|
|
|
if (c != null)
|
|
|
|
|
{
|
|
|
|
|
quote.Character.IdImage = i.Id;
|
|
|
|
|
quote.Character.Images = i;
|
|
|
|
|
}
|
|
|
|
|
//Source
|
|
|
|
|
var s = await _dbS.GetSourceByTitle(quote.Source.Title);
|
|
|
|
|
if (c != null)
|
|
|
|
|
{
|
|
|
|
|
quote.IdSource = s.Id;
|
|
|
|
|
quote.Source = s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Quote? q = _repo.GetById(quoteId);
|
|
|
|
|
if (q != null)
|
|
|
|
|
{
|
|
|
|
|