using LibraryDataModels.AbstractModels; using LibraryDataModels.Views; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LibraryDatabase.Models { [Table("books")] public class Book : IBook { [Column("book_id")] public int Id { get; private set; } [Required] [Column("book_name")] public string Name { get; private set; } = string.Empty; [Required] [Column("book_cover")] public string BookCover { get; private set; } = string.Empty; [Required] [Column("book_author_name")] public string Author { get; private set; } = string.Empty; [Required] [Column("book_release_date")] public string ReleaseDate { get; private set; } = string.Empty; public Book() {} public Book(IBook book) { Id = book.Id; Name = book.Name; BookCover = book.BookCover; Author = book.Author; ReleaseDate = book.ReleaseDate; } public static Book Create(IBook book) { if (book == null) throw new ArgumentNullException("Cannot create book because model is null"); return new Book(book); } public void Update(IBook book) { if (string.IsNullOrWhiteSpace(book?.Name) || string.IsNullOrWhiteSpace(book?.BookCover) || string.IsNullOrWhiteSpace(book?.Author) || string.IsNullOrWhiteSpace(book?.ReleaseDate)) { throw new ArgumentNullException("Cannot update book because model is null"); } Name = book.Name; BookCover = book.BookCover; Author = book.Author; ReleaseDate = book.ReleaseDate; } public BookView GetView => new BookView(this); } }