32 lines
839 B
C#
32 lines
839 B
C#
using LibraryApp.Domain;
|
|
using LibraryApp.Domain.Entities;
|
|
|
|
namespace LibraryApp.Domain.Services;
|
|
|
|
public class BookCountService
|
|
{
|
|
private readonly IBookCountReportPrinter _printer;
|
|
|
|
public BookCountService(IBookCountReportPrinter printer)
|
|
{
|
|
_printer = printer;
|
|
}
|
|
|
|
public async Task<Result<BookCountReport>> PerformCountAsync(
|
|
Shelf shelf,
|
|
IReadOnlyList<BookInstanceBarcode> scannedBarcodes,
|
|
IReadOnlyList<BookInstance> allInstancesOnShelf)
|
|
{
|
|
shelf.RecordCount();
|
|
|
|
var report = new BookCountReport(shelf.Id, DateTime.UtcNow, allInstancesOnShelf, scannedBarcodes);
|
|
|
|
foreach (var instance in report.MissingInstances)
|
|
instance.MarkAsLost();
|
|
|
|
await _printer.PrintAsync(report);
|
|
|
|
return Result<BookCountReport>.Success(report);
|
|
}
|
|
}
|