public void ReturnBook(BookId bookId, BookAmount amount) { var book = Books.First(a => a.BookId == bookId); if (book.BookAmount == amount) { Books.RemoveAll(a => a.BookId == bookId); } else if (book.BookAmount > amount) { Books.RemoveAll(a => a.BookId == bookId); Books.Add(new BookRecord(book.BookId, book.BookAmount - amount, book.Title)); } else { throw new ArgumentException($"Cannot return book with title {book.Title.Value}. Amount to return is higher than {book.BookAmount.Amount}"); } AddEvent(new BookRemovedFromLibraryRecord(bookId, amount.Amount, (LibraryRecordId)Id)); if (ReturnDate < DateTime.UtcNow) { var oldFineValue = ReturnFine.Value; var daysBetweenTodayAndReturnDate = ((DateTime.UtcNow - ReturnDate)).Days; var newFineValue = daysBetweenTodayAndReturnDate * 10; ReturnFine = new ReturnFine(oldFineValue + newFineValue); } if (ReturnFine.Value == 0) { IsClosed = true; } }
public void RemoveStock(BookAmount amount) { this.Amount = new BookAmount(this.Amount.Amount - amount.Amount); if (this.Amount.Amount == 0) { this.State = BookState.InDatabase; } }
private Book(BookId id, string title, string description, AuthorId authorId, AuthorFullName authorName) { Id = id; Title = new BookTitle(title); Description = description; AuthorId = authorId; AuthorName = authorName; State = BookState.InDatabase; Amount = new BookAmount(0); }
public BookRecord(BookId bookId, BookAmount bookAmount, BookTitle title) { BookId = bookId; BookAmount = bookAmount; Title = title; }
public void AddStock(BookAmount amount) { this.Amount = new BookAmount(this.Amount.Amount + amount.Amount); this.State = BookState.InStock; }