54 lines
2.2 KiB
C#
54 lines
2.2 KiB
C#
using Bibblan.Models;
|
|
using Bibblan.ViewModels;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Bibblan.Business.Services
|
|
{
|
|
public class CalibreService
|
|
{
|
|
private readonly BibblanOptions _options;
|
|
SqliteCalibreContext _context;
|
|
public CalibreService(SqliteCalibreContext context, IOptions<BibblanOptions> options)
|
|
{
|
|
_options = options.Value;
|
|
_context = context;
|
|
}
|
|
|
|
public byte[] Cover(string path)
|
|
{
|
|
var fullPath = Path.Combine(_options.CalibreRoot, path, "cover.jpg");
|
|
return File.ReadAllBytes(fullPath);
|
|
}
|
|
|
|
public IQueryable<BookVm> GetAllBooks()
|
|
{
|
|
return from b in _context.Books
|
|
join ba in _context.BooksAuthorsLink on b.Id equals ba.Book
|
|
join a in _context.Authors on ba.Author equals a.Id
|
|
join comment in _context.Comments on b.Id equals comment.Book into comments
|
|
from comment in comments.DefaultIfEmpty()
|
|
join bl in _context.BooksLanguagesLink on b.Id equals bl.Book
|
|
join l in _context.Languages on bl.LangCode equals l.Id
|
|
join bs in _context.BooksSeriesLink on b.Id equals bs.Book into book_series_link
|
|
from bs in book_series_link.DefaultIfEmpty()
|
|
join s in _context.Series on bs.Series equals s.Id into series
|
|
from s in series.DefaultIfEmpty()
|
|
orderby b.Title
|
|
select new BookVm
|
|
{
|
|
Id = b.Id,
|
|
Title = b.Title,
|
|
AuthorId = a.Id,
|
|
Author = a.Sort,
|
|
Comments = comment.Text,
|
|
Language = l.LangCode,
|
|
Path = b.Path,
|
|
HasCover = b.HasCover,// == "1",
|
|
Formats = (from d in _context.Data where d.Book == b.Id orderby d.Format select new DataVm { Id = d.Id, Format = d.Format, FileName = d.Name + "." + d.Format.ToLower() }).ToList(),
|
|
SeriesName = s.Name,
|
|
SeriesNumber = b.SeriesIndex
|
|
};
|
|
}
|
|
}
|
|
}
|