You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.6 KiB

namespace Model;
public class Book : IEquatable<Book>
{
public long Id { get; private init; }
public string Title
{
get => title;
set => title = value ?? "";
}
private string title = null!;
public string Author
{
get => author;
set => author = value ?? "";
}
private string author = null!;
public string Isbn
{
get => isbn;
set => isbn = value ?? "";
}
private string isbn = null!;
public Person? Borrower { get; set; }
public Book(long id, string title, string author, string isbn)
{
Id = id;
Title = title;
Author = author;
Isbn = isbn;
}
public Book(string title, string author, string isbn)
: this(0, title, author, isbn)
{
}
public bool Equals(Book? other)
{
if (Id != 0)
return Id == (other?.Id ?? 0);
else
return Title.Equals(other?.Title)
&& Author.Equals(other?.Author)
&& Isbn.Equals(other?.Isbn);
}
public override bool Equals(object? obj)
{
if(ReferenceEquals(obj, null)) return false;
if(ReferenceEquals(obj, this)) return true;
if(GetType() != obj.GetType()) return false;
return Equals(obj as Book);
}
public override int GetHashCode()
{
if(Id != 0)
return (int)(Id % 7879);
else
return Isbn.GetHashCode();
}
public override string ToString()
=> $"{Id} - {Title} ({Isbn}) // {Author}";
}