94 lines
3.0 KiB
C#
94 lines
3.0 KiB
C#
using Microsoft.Data.SqlClient;
|
|
|
|
namespace Library;
|
|
|
|
public class BookData
|
|
{
|
|
public int ID { init; get; } = 0;
|
|
public string UUID { init; get; } = "";
|
|
|
|
public int CategoryID { init; get; } = 0;
|
|
public string CategoryName { init; get; } = "";
|
|
|
|
public int BookTypeID { init; get; } = 0;
|
|
public string BookTypeName { init; get; } = "";
|
|
|
|
public string Title { init; get; } = "";
|
|
public string Author { init; get; } = "";
|
|
public string Access { init; get; } = "";
|
|
public string Publisher { init; get; } = "";
|
|
public string PublishYear { init; get; } = "";
|
|
public string Keywords { init; get; } = "";
|
|
public string Description { init; get; } = "";
|
|
public DateTime CreateDate { init; get; } = DateTime.Now;
|
|
public string Opisanie { init; get; } = "";
|
|
public string KodDrugi { init; get; } = "";
|
|
|
|
|
|
public static BookData? WithID( SqlConnection connection , int id )
|
|
{
|
|
using SqlDataReader reader = new SQLBuilder( connection , "SELECT * FROM v_repository WHERE id = @id" )
|
|
.AddParameter( "@id" , id )
|
|
.ExecuteReader( );
|
|
|
|
if ( !reader.Read( ) )
|
|
return null;
|
|
|
|
return new BookData( )
|
|
{
|
|
ID = reader.Int( "id" ) ,
|
|
UUID = reader.StringSafe( "uuid" ) ,
|
|
CategoryID = reader.Int( "category_id" ) ,
|
|
CategoryName = reader.StringSafe( "category_name" ) ,
|
|
BookTypeID = reader.Int( "book_type_id" ) ,
|
|
BookTypeName = reader.StringSafe( "book_type_name" ) ,
|
|
Title = reader.StringSafe( "title" ) ,
|
|
Author = reader.StringSafe( "author" ) ,
|
|
Access = reader.StringSafe( "access" ) ,
|
|
Publisher = reader.StringSafe( "publisher" ) ,
|
|
PublishYear = reader.StringSafe( "publish_year" ) ,
|
|
Keywords = reader.StringSafe( "keywords" ) ,
|
|
Description = reader.StringSafe( "description" ) ,
|
|
CreateDate = reader.DateTime( "create_date" ) ,
|
|
Opisanie = reader.StringSafe( "opisanie" ) ,
|
|
KodDrugi = reader.StringSafe( "koddrugi" ) ,
|
|
};
|
|
}
|
|
}
|
|
public class BookDataMini
|
|
{
|
|
public int ID { init; get; } = 0;
|
|
public string UUID { init; get; } = "";
|
|
|
|
public int CategoryID { init; get; } = 0;
|
|
public string CategoryName { init; get; } = "";
|
|
|
|
public int BookTypeID { init; get; } = 0;
|
|
public string BookTypeName { init; get; } = "";
|
|
|
|
public string Title { init; get; } = "";
|
|
public string Author { init; get; } = "";
|
|
public string Access { init; get; } = "";
|
|
public static BookDataMini? WithID( SqlConnection connection , int id )
|
|
{
|
|
using SqlDataReader reader = new SQLBuilder( connection , "SELECT * FROM v_repository WHERE id = @id" )
|
|
.AddParameter( "@id" , id )
|
|
.ExecuteReader( );
|
|
|
|
if ( !reader.Read( ) )
|
|
return null;
|
|
|
|
return new BookDataMini( )
|
|
{
|
|
ID = reader.Int( "id" ) ,
|
|
UUID = reader.StringSafe( "uuid" ) ,
|
|
CategoryID = reader.Int( "category_id" ) ,
|
|
CategoryName = reader.StringSafe( "category_name" ) ,
|
|
BookTypeID = reader.Int( "book_type_id" ) ,
|
|
BookTypeName = reader.StringSafe( "book_type_name" ) ,
|
|
Title = reader.StringSafe( "title" ) ,
|
|
Author = reader.StringSafe( "author" ) ,
|
|
Access = reader.StringSafe( "access" ) ,
|
|
};
|
|
}
|
|
} |