This commit is contained in:
		
							
								
								
									
										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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user