initial commit
This commit is contained in:
37
Data/AttachmentData.cs
Normal file
37
Data/AttachmentData.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace Library;
|
||||
|
||||
public class AttachmentData
|
||||
{
|
||||
public int ID { init; get; } = 0;
|
||||
public string Title { init; get; } = null!;
|
||||
public string? UUID { init; get; } = null;
|
||||
public string? Link { init; get; } = null;
|
||||
public string? Format { init; get; } = null;
|
||||
|
||||
public static List<AttachmentData> GetList( SqlConnection connection , int repository_id )
|
||||
{
|
||||
using SqlDataReader reader = new SQLBuilder( connection , "SELECT * FROM [v_attachment] WHERE repository_id = @repository_id" )
|
||||
.AddParameter( "@repository_id" , repository_id )
|
||||
.ExecuteReader( );
|
||||
|
||||
List<AttachmentData> result = new( );
|
||||
while ( reader.Read( ) )
|
||||
{
|
||||
AttachmentData attachment = new( )
|
||||
{
|
||||
ID = reader.Int( "id" ) ,
|
||||
UUID = reader.StringSafe( "uuid" ) ,
|
||||
Title = reader.StringSafe( "title" ) ,
|
||||
Link = reader.StringSafe( "link" ) ,
|
||||
Format = reader.String( "format" ) ,
|
||||
};
|
||||
result.Add( attachment );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
94
Data/BookData.cs
Normal file
94
Data/BookData.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
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" ) ,
|
||||
};
|
||||
}
|
||||
}
|
||||
108
Data/BookListData.cs
Normal file
108
Data/BookListData.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System.Collections;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace Library;
|
||||
|
||||
public class BookListData : IEnumerable<BookData>
|
||||
{
|
||||
private readonly List<BookData> m_Elements = new( );
|
||||
|
||||
public IEnumerator<BookData> GetEnumerator( )
|
||||
{
|
||||
return m_Elements.GetEnumerator( );
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator( )
|
||||
{
|
||||
return m_Elements.GetEnumerator( );
|
||||
}
|
||||
|
||||
static public int GetCategoryCount( SqlConnection connection , int category_id )
|
||||
{
|
||||
return new SQLBuilder( connection , @"SELECT count(*) FROM v_repository WHERE category_id=@category and include_category_id=@category" )
|
||||
.AddParameter( "@category" , category_id )
|
||||
.ExecuteAndReadInteger( 0 );
|
||||
}
|
||||
|
||||
public static int GetTotalSearchCount( SqlConnection connection , string term )
|
||||
{
|
||||
return new SQLBuilder( connection , "SELECT count(*) FROM v_repository_search" )
|
||||
.AddLike( "search_index" , term )
|
||||
.ExecuteAndReadInteger( 0 );
|
||||
}
|
||||
|
||||
public void LoadSearch( SqlConnection connection , string term , int page , int items_per_page )
|
||||
{
|
||||
using SqlDataReader reader = new SQLBuilder( connection , "SELECT * FROM v_repository_search" , "title" )
|
||||
.AddLike( "search_index" , term )
|
||||
.SetPaging( page , items_per_page )
|
||||
.ExecuteReader( );
|
||||
|
||||
while ( reader.Read( ) )
|
||||
{
|
||||
BookData book = new( )
|
||||
{
|
||||
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" ) ,
|
||||
Keywords = reader.StringSafe( "keywords" ) ,
|
||||
/* 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" ) ,
|
||||
*/
|
||||
};
|
||||
m_Elements.Add( book );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void LoadCategory( SqlConnection connection , int category_id , int page , int books_per_page )
|
||||
{
|
||||
using SqlDataReader reader = new SQLBuilder( connection ,
|
||||
// "select * from v_repository where include_category_id=category_id"
|
||||
@"SELECT * FROM v_repository
|
||||
WHERE category_id=@category and include_category_id=@category
|
||||
ORDER BY sort, title
|
||||
OFFSET @offset ROWS
|
||||
FETCH NEXT @rows ROWS ONLY"
|
||||
)
|
||||
.AddParameter( "@category" , category_id )
|
||||
.AddParameter( "@offset" , page * books_per_page )
|
||||
.AddParameter( "@rows" , books_per_page )
|
||||
.ExecuteReader( );
|
||||
|
||||
while ( reader.Read( ) )
|
||||
{
|
||||
BookData book = new( )
|
||||
{
|
||||
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" ) , */
|
||||
};
|
||||
m_Elements.Add( book );
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Data/CategoryItemData.cs
Normal file
12
Data/CategoryItemData.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Library;
|
||||
|
||||
public class CategoryItemData
|
||||
{
|
||||
public int ID { init; get; } = 0;
|
||||
public int ParentID { init; get; } = 0;
|
||||
public int ElementCount { init; get; } = 0;
|
||||
public int Depth { init; get; } = 0;
|
||||
public string Name { init; get; } = "";
|
||||
public string Catego_opis { init; get; } = "";
|
||||
public List<CategoryItemData> Children { init; get; } = new( );
|
||||
}
|
||||
54
Data/CategoryTreeData.cs
Normal file
54
Data/CategoryTreeData.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace Library;
|
||||
|
||||
public class CategoryTreeData
|
||||
{
|
||||
private readonly List<CategoryItemData> m_RootElements = new( );
|
||||
public List<CategoryItemData> RootElements { get => m_RootElements; }
|
||||
|
||||
private readonly Dictionary<int,CategoryItemData> m_AllElements = new( );
|
||||
|
||||
public int GetRootID( )
|
||||
{
|
||||
if ( m_RootElements.Count == 0 )
|
||||
return 0;
|
||||
return m_RootElements[0].ID;
|
||||
}
|
||||
|
||||
public CategoryItemData? FindCategory( int id )
|
||||
{
|
||||
if ( m_AllElements.TryGetValue( id , out CategoryItemData? value ) )
|
||||
return value;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void LoadCategoryTree( SqlConnection connection )
|
||||
{
|
||||
using SqlDataReader reader = new SQLBuilder( connection , "select id,idfat,label,ime_x,cnt,lis_txt from [select_razdeli]" )
|
||||
.ExecuteReader( );
|
||||
|
||||
while ( reader.Read( ) )
|
||||
{
|
||||
CategoryItemData model = new( )
|
||||
{
|
||||
ID = reader.Int( "id" ) ,
|
||||
ParentID = reader.Int( "idfat" ) ,
|
||||
ElementCount = reader.Int( "cnt" ) ,
|
||||
Depth = reader.Int( "label" ) ,
|
||||
Name = reader.StringSafe( "ime_x" ).Trim( ),
|
||||
Catego_opis = reader.StringSafe( "lis_txt" ).Trim( )
|
||||
};
|
||||
m_AllElements[model.ID] = model;
|
||||
}
|
||||
|
||||
foreach ( CategoryItemData m in m_AllElements.Values )
|
||||
{
|
||||
if ( m_AllElements.TryGetValue( m.ParentID , out CategoryItemData? parent ) )
|
||||
parent.Children.Add( m );
|
||||
else
|
||||
m_RootElements.Add( m );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
19
Data/PagingData.cs
Normal file
19
Data/PagingData.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Library;
|
||||
|
||||
public class PagingData
|
||||
{
|
||||
public int CurrentPage { init; get; } = 0;
|
||||
public int LastPage { init; get; } = 0;
|
||||
public int TotalPages { init; get; } = 0;
|
||||
|
||||
private readonly string m_BaseURL = "";
|
||||
public string Url( int page ) => m_BaseURL + page.ToString( );
|
||||
|
||||
public PagingData( string base_url , int current_page , int total_items , int items_per_page )
|
||||
{
|
||||
m_BaseURL = base_url;
|
||||
CurrentPage = current_page;
|
||||
LastPage = ( total_items - 1 ) / items_per_page;
|
||||
TotalPages = ( total_items + items_per_page - 1 ) / items_per_page;
|
||||
}
|
||||
}
|
||||
65
Data/UserData.cs
Normal file
65
Data/UserData.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace Library;
|
||||
|
||||
public class UserData
|
||||
{
|
||||
public int ID = 0;
|
||||
public string Name = default!;
|
||||
public string Email = default!;
|
||||
public string SessionID = default!;
|
||||
public bool IsActive = true;
|
||||
public bool IsAdmin = false;
|
||||
|
||||
public static UserData? FromSession( SqlConnection connection , string session_id )
|
||||
{
|
||||
using SqlDataReader reader = new SQLBuilder( connection , "EXEC [usp_user_session_validate] @session_id" )
|
||||
.AddParameter( "@session_id" , session_id )
|
||||
.ExecuteReader( );
|
||||
|
||||
if ( reader == null || !reader.Read( ) )
|
||||
return null;
|
||||
|
||||
int user_id = reader.Int( "id" , 0 );
|
||||
if ( user_id <= 0 )
|
||||
return null;
|
||||
|
||||
return new( )
|
||||
{
|
||||
ID = user_id ,
|
||||
Name = reader.String( "display_name" ) ?? "" ,
|
||||
Email = reader.String( "email" ) ?? "" ,
|
||||
SessionID = session_id ,
|
||||
IsAdmin = reader.Int( "is_admin" , 0 ) == 1 ,
|
||||
IsActive = true
|
||||
};
|
||||
}
|
||||
|
||||
public static UserData? FromID( SqlConnection connection , int id )
|
||||
{
|
||||
using SqlDataReader reader = new SQLBuilder( connection , "SELECT [id],[ime],[user_tip],[mail],[is_active] FROM [dom] WHERE [id]=@id" )
|
||||
.AddParameter( "@id" , id )
|
||||
.ExecuteReader( );
|
||||
|
||||
if ( reader == null || !reader.Read( ) )
|
||||
return null;
|
||||
|
||||
return FromReader( reader );
|
||||
}
|
||||
|
||||
public static UserData? FromReader( SqlDataReader reader )
|
||||
{
|
||||
int user_id = reader.Int( "id" , 0 );
|
||||
if ( user_id <= 0 )
|
||||
return null;
|
||||
|
||||
return new( )
|
||||
{
|
||||
ID = user_id ,
|
||||
Name = reader.String( "ime" ) ?? "" ,
|
||||
Email = reader.String( "mail" ) ?? "" ,
|
||||
IsAdmin = ( reader.String( "user_tip" ) ?? "" ) == "admin" ,
|
||||
IsActive = reader.Int( "is_active" , 0 ) != 0
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user