ProjectLib/ProjectLibrary/Entites/Library.cs

52 lines
1.5 KiB
C#

using ProjectLibrary.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Entites
{
public class Library
{
public int Id { get; private set; }
[DisplayName("Название")]
public string Name { get; private set; } = string.Empty;
[DisplayName("Адрес")]
public string Address { get; private set; } = string.Empty;
[Browsable(false)]
public IEnumerable<Book_Library> BookLibrary
{
get;
private set;
}
[DisplayName("Перечень книг в библиотеке")]
public string ListBookInLibrary => BookLibrary != null ?
string.Join("; ", BookLibrary.Select(x => $"{x.BookID},{x.Count}")): string.Empty;
public static Library CreateEntity(int id, string name, string address, IEnumerable<Book_Library> bookLibrary)
{
return new Library
{
Id = id,
Name = name ?? string.Empty,
Address = address ?? string.Empty,
BookLibrary = bookLibrary
};
}
public void SetLibraryForBook(IEnumerable<Book_Library> book_Library)
{
if (book_Library != null && book_Library.Any())
{
BookLibrary = book_Library;
}
}
}
}