This commit is contained in:
20
TelebilbaoEpg.Database/Models/BroadCast.cs
Normal file
20
TelebilbaoEpg.Database/Models/BroadCast.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using SQLite;
|
||||
using System;
|
||||
namespace TelebilbaoEpg.Database.Models
|
||||
{
|
||||
public class BroadCast
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
|
||||
public DateTime From { get; set; }
|
||||
|
||||
public DateTime To { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public string ImageUrl { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
26
TelebilbaoEpg.Database/Repositories/BaseRepository.cs
Normal file
26
TelebilbaoEpg.Database/Repositories/BaseRepository.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using SQLite;
|
||||
using System.IO;
|
||||
using TelebilbaoEpg.Database.Models;
|
||||
|
||||
namespace TelebilbaoEpg.Database.Repository
|
||||
{
|
||||
public abstract class BaseRepository
|
||||
{
|
||||
protected SQLiteConnection _db;
|
||||
|
||||
public BaseRepository()
|
||||
{
|
||||
var storeFile = "/data/telebilbaoEpg.db";
|
||||
|
||||
#if DEBUG
|
||||
storeFile = storeFile.Replace("/data/", "");
|
||||
#endif
|
||||
|
||||
// Get an absolute path to the database file
|
||||
var databasePath = Path.Combine(Directory.GetCurrentDirectory(), storeFile);
|
||||
|
||||
_db = new SQLiteConnection(databasePath);
|
||||
_db.CreateTable<BroadCast>();
|
||||
}
|
||||
}
|
||||
}
|
33
TelebilbaoEpg.Database/Repositories/BroadCastRepository.cs
Normal file
33
TelebilbaoEpg.Database/Repositories/BroadCastRepository.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TelebilbaoEpg.Database.Models;
|
||||
|
||||
namespace TelebilbaoEpg.Database.Repository
|
||||
{
|
||||
public class BroadCastRepository : BaseRepository, IBroadCastRepository
|
||||
{
|
||||
public void Add(BroadCast broadCast)
|
||||
{
|
||||
_db.Insert(broadCast);
|
||||
}
|
||||
|
||||
public List<BroadCast> GetBroadCasts(DateOnly day)
|
||||
{
|
||||
return _db.Table<BroadCast>()
|
||||
.ToList()
|
||||
.Where(b => DateOnly.FromDateTime(b.From.Date) == day || DateOnly.FromDateTime(b.To) == day)
|
||||
.OrderBy(b => b.From)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<BroadCast> GetBroadCasts(DateOnly from, DateOnly to)
|
||||
{
|
||||
return _db.Table<BroadCast>()
|
||||
.ToList()
|
||||
.Where(b => (DateOnly.FromDateTime(b.From) >= from || DateOnly.FromDateTime(b.To) >= from) && (DateOnly.FromDateTime(b.From) <= to || DateOnly.FromDateTime(b.To) <= to))
|
||||
.OrderBy(b => b.From)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
15
TelebilbaoEpg.Database/Repositories/IBroadCastRepository.cs
Normal file
15
TelebilbaoEpg.Database/Repositories/IBroadCastRepository.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TelebilbaoEpg.Database.Models;
|
||||
|
||||
namespace TelebilbaoEpg.Database.Repository
|
||||
{
|
||||
public interface IBroadCastRepository
|
||||
{
|
||||
List<BroadCast> GetBroadCasts(DateOnly day);
|
||||
|
||||
List<BroadCast> GetBroadCasts(DateOnly from, DateOnly to);
|
||||
|
||||
void Add(BroadCast broadCast);
|
||||
}
|
||||
}
|
12
TelebilbaoEpg.Database/TelebilbaoEpg.Database.csproj
Normal file
12
TelebilbaoEpg.Database/TelebilbaoEpg.Database.csproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user