2020-05-28 11:47:02 +00:00
using System ;
2020-06-04 06:33:30 +00:00
using System.IO ;
2020-05-28 11:47:02 +00:00
using System.Collections.Generic ;
using System.Linq ;
using System.Threading.Tasks ;
2020-06-04 06:33:30 +00:00
using Microsoft.Data.Sqlite ;
2020-05-28 11:47:02 +00:00
using Microsoft.AspNetCore.Hosting ;
using Microsoft.Extensions.Configuration ;
using Microsoft.Extensions.Hosting ;
using Microsoft.Extensions.Logging ;
namespace BuecherwurmAPI
{
public class Program
{
public static void Main ( string [ ] args )
{
2020-06-04 06:33:30 +00:00
if ( ! File . Exists ( "LongWormMemory.db" ) )
{
CreateNewEmptyDB ( ) ;
MakeImports ( ) ;
}
2020-05-28 11:47:02 +00:00
CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
}
2020-06-04 06:33:30 +00:00
private static void MakeImports ( )
{
throw new NotImplementedException ( ) ;
}
private static void CreateNewEmptyDB ( )
{
File . Create ( "LongWormMemory.db" ) ;
var connectionBuilder = new SqliteConnectionStringBuilder { DataSource = "LongWormMemory.db" } ;
var connection = new SqliteConnection ( connectionBuilder . ConnectionString ) ;
connection . Open ( ) ;
using ( var command = connection . CreateCommand ( ) )
{
command . CommandText = "CREATE TABLE Lends (Id INTEGER NOT NULL PRIMARY KEY, ItemId INTEGER NOT NULL, ReturnDate TEXT NOT NULL, Customer TEXT NOT NULL, Returned INTEGER NOT NULL)" ;
command . ExecuteNonQuery ( ) ;
command . CommandText = "CREATE TABLE Items (ItemId INTEGER NOT NULL PRIMARY KEY, BookId INTEGER NOT NULL)" ;
command . ExecuteNonQuery ( ) ;
2020-06-04 07:39:27 +00:00
command . CommandText = "CREATE TABLE Products (ProductId INTEGER PRIMARY KEY, Name TEXT, Author TEXT, Country TEXT, Link TEXT, Language TEXT, Pages INTEGER, Year INTEGER, Category INTEGER, ImageLink TEXT, LendTime INTEGER, LendType INTEGER)" ;
2020-06-04 06:33:30 +00:00
command . ExecuteNonQuery ( ) ;
}
}
2020-05-28 11:47:02 +00:00
public static IHostBuilder CreateHostBuilder ( string [ ] args ) = >
Host . CreateDefaultBuilder ( args )
. ConfigureWebHostDefaults ( webBuilder = >
{
webBuilder . UseStartup < Startup > ( ) ;
} ) ;
}
}