51 lines
No EOL
1.7 KiB
C#
51 lines
No EOL
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BuecherwurmAPI.Models;
|
|
using Microsoft.Data.Sqlite;
|
|
|
|
namespace BuecherwurmAPI.Data
|
|
{
|
|
internal class Repository : IRepository
|
|
{
|
|
private SqliteConnection _dbConnection;
|
|
|
|
public Repository()
|
|
{
|
|
var connectionBuilder = new SqliteConnectionStringBuilder {DataSource = "LongWormMemory.db"};
|
|
_dbConnection = new SqliteConnection(connectionBuilder.ConnectionString);
|
|
_dbConnection.Open();
|
|
}
|
|
|
|
public IEnumerable<Lend> GetAllLends()
|
|
{
|
|
var lends = new List<Lend>();
|
|
|
|
// using automatically disposes the command after completion
|
|
using (var command = _dbConnection.CreateCommand())
|
|
{
|
|
command.CommandText = @"SELECT * FROM Lends";
|
|
var dataReader = command.ExecuteReader();
|
|
|
|
while (dataReader.Read())
|
|
{
|
|
var returned = (long) dataReader["Returned"] == 0;
|
|
|
|
lends.Add(new Lend
|
|
{
|
|
Id = (long) dataReader["Id"],
|
|
Customer = (string) dataReader["Customer"],
|
|
ItemId = (long) dataReader["ItemId"],
|
|
Returned = !returned,
|
|
ReturnDate = DateTime.Parse((string)dataReader["ReturnDate"])
|
|
});
|
|
}
|
|
}
|
|
return lends;
|
|
}
|
|
|
|
public Lend GetLendById(int id)
|
|
{
|
|
return new Lend{Id = 1, Customer = "Nek0", ItemId = 1337, Returned = false, ReturnDate = DateTime.Now};
|
|
}
|
|
}
|
|
} |