mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
The move!
This commit is contained in:
parent
1daf480b1b
commit
25526cc4d9
1147 changed files with 85 additions and 8524 deletions
119
Old/Ombi.Store/Repository/BaseExternalUserRepository.cs
Normal file
119
Old/Ombi.Store/Repository/BaseExternalUserRepository.cs
Normal file
|
@ -0,0 +1,119 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: UserRepository.cs
|
||||
// Created By:
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Models.Emby;
|
||||
using Ombi.Store.Models.Plex;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class BaseExternalUserRepository<T> : BaseGenericRepository<T>, IExternalUserRepository<T> where T : Entity
|
||||
{
|
||||
public BaseExternalUserRepository(ISqliteConfiguration config, ICacheProvider cache) : base(config,cache)
|
||||
{
|
||||
DbConfig = config;
|
||||
}
|
||||
|
||||
private ISqliteConfiguration DbConfig { get; }
|
||||
private IDbConnection Db => DbConfig.DbConnection();
|
||||
|
||||
private string TableName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (typeof(T) == typeof(PlexUsers))
|
||||
{
|
||||
return "PlexUsers";
|
||||
}
|
||||
if (typeof(T) == typeof(EmbyUsers))
|
||||
{
|
||||
return "EmbyUsers";
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public T GetUser(string userGuid)
|
||||
{
|
||||
var sql = $@"SELECT * FROM {TableName}
|
||||
WHERE PlexUserId = @UserGuid
|
||||
COLLATE NOCASE";
|
||||
return Db.QueryFirstOrDefault<T>(sql, new {UserGuid = userGuid});
|
||||
}
|
||||
|
||||
public T GetUserByUsername(string username)
|
||||
{
|
||||
var sql = $@"SELECT * FROM {TableName}
|
||||
WHERE Username = @UserName
|
||||
COLLATE NOCASE";
|
||||
return Db.QueryFirstOrDefault<T>(sql, new {UserName = username});
|
||||
}
|
||||
|
||||
public async Task<T> GetUserAsync(string userguid)
|
||||
{
|
||||
var sql = $@"SELECT * FROM {TableName}
|
||||
WHERE PlexUserId = @UserGuid
|
||||
COLLATE NOCASE";
|
||||
return await Db.QueryFirstOrDefaultAsync<T>(sql, new {UserGuid = userguid});
|
||||
}
|
||||
|
||||
#region abstract implementation
|
||||
|
||||
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
|
||||
[Obsolete]
|
||||
public override T Get(string id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public override Task<T> GetAsync(int id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public override T Get(int id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public override Task<T> GetAsync(string id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
361
Old/Ombi.Store/Repository/BaseGenericRepository.cs
Normal file
361
Old/Ombi.Store/Repository/BaseGenericRepository.cs
Normal file
|
@ -0,0 +1,361 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: BaseGenericRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Dapper.Contrib.Extensions;
|
||||
using Mono.Data.Sqlite;
|
||||
using NLog;
|
||||
using Ombi.Helpers;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public abstract class BaseGenericRepository<T> where T : class
|
||||
{
|
||||
private const string CorruptMessage =
|
||||
"The database is corrupt, this could be due to the application exiting unexpectedly. See here to fix it: http://www.dosomethinghere.com/2013/02/20/fixing-the-sqlite-error-the-database-disk-image-is-malformed/";
|
||||
protected BaseGenericRepository(ISqliteConfiguration config, ICacheProvider cache)
|
||||
{
|
||||
Config = config;
|
||||
Cache = cache;
|
||||
}
|
||||
protected ICacheProvider Cache { get; }
|
||||
protected ISqliteConfiguration Config { get; }
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
public abstract T Get(string id);
|
||||
public abstract Task<T> GetAsync(int id);
|
||||
public abstract T Get(int id);
|
||||
public abstract Task<T> GetAsync(string id);
|
||||
private IDbConnection Connection => Config.DbConnection();
|
||||
|
||||
|
||||
public IEnumerable<T> Custom(Func<IDbConnection, IEnumerable<T>> func)
|
||||
{
|
||||
using (var cnn = Connection)
|
||||
{
|
||||
return func(cnn);
|
||||
}
|
||||
}
|
||||
|
||||
public T Custom(Func<IDbConnection, T> func)
|
||||
{
|
||||
using (var cnn = Connection)
|
||||
{
|
||||
return func(cnn);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<T>> CustomAsync(Func<IDbConnection, Task<IEnumerable<T>>> func)
|
||||
{
|
||||
using (var cnn = Connection)
|
||||
{
|
||||
return await func(cnn);
|
||||
}
|
||||
}
|
||||
public async Task<T> CustomAsync(Func<IDbConnection, Task<T>> func)
|
||||
{
|
||||
using (var cnn = Connection)
|
||||
{
|
||||
return await func(cnn);
|
||||
}
|
||||
}
|
||||
|
||||
public long Insert(T entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
using (var cnn = Config.DbConnection())
|
||||
{
|
||||
cnn.Open();
|
||||
return cnn.Insert(entity);
|
||||
}
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(T entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
db.Delete(entity);
|
||||
}
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(T entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
await db.DeleteAsync(entity).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Update(T entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
return db.Update(entity);
|
||||
}
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(T entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
return await db.UpdateAsync(entity).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdateAll(IEnumerable<T> entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
var result = new HashSet<bool>();
|
||||
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
foreach (var e in entity)
|
||||
{
|
||||
result.Add(db.Update(e));
|
||||
}
|
||||
}
|
||||
return result.All(x => true);
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAllAsync(IEnumerable<T> entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
var tasks = new List<Task<bool>>();
|
||||
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
foreach (var e in entity)
|
||||
{
|
||||
tasks.Add(db.UpdateAsync(e));
|
||||
}
|
||||
}
|
||||
var result = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
return result.All(x => true);
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> InsertAsync(T entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
using (var cnn = Config.DbConnection())
|
||||
{
|
||||
cnn.Open();
|
||||
return await cnn.InsertAsync(entity).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetCache()
|
||||
{
|
||||
Cache.Remove("Get");
|
||||
Cache.Remove("GetAll");
|
||||
}
|
||||
public IEnumerable<T> GetAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
var result = db.GetAll<T>();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
public async Task<IEnumerable<T>> GetAllAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
var result = await db.GetAllAsync<T>().ConfigureAwait(false);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public bool BatchInsert(IEnumerable<T> entities, string tableName)
|
||||
{
|
||||
// If we have nothing to update, then it didn't fail...
|
||||
var enumerable = entities as T[] ?? entities.ToArray();
|
||||
if (!enumerable.Any())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
using (var tran = db.BeginTransaction())
|
||||
{
|
||||
var result = enumerable.Sum(e => db.Insert(e));
|
||||
if (result != 0)
|
||||
{
|
||||
tran.Commit();
|
||||
return true;
|
||||
}
|
||||
tran.Rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void DeleteAll(string tableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
db.Execute($"delete from {tableName}");
|
||||
}
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public async Task DeleteAllAsync(string tableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCache();
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
await db.ExecuteAsync($"delete from {tableName}");
|
||||
}
|
||||
}
|
||||
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
|
||||
{
|
||||
Log.Fatal(CorruptMessage);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
89
Old/Ombi.Store/Repository/GenericRepository.cs
Normal file
89
Old/Ombi.Store/Repository/GenericRepository.cs
Normal file
|
@ -0,0 +1,89 @@
|
|||
#region Copyright
|
||||
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: GenericRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper.Contrib.Extensions;
|
||||
using Ombi.Helpers;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class GenericRepository<T> : BaseGenericRepository<T>, IRepository<T> where T : Entity
|
||||
{
|
||||
|
||||
public GenericRepository(ISqliteConfiguration config, ICacheProvider cache) : base(config, cache)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override T Get(string id)
|
||||
{
|
||||
throw new NotSupportedException("Get(string) is not supported. Use Get(int)");
|
||||
}
|
||||
|
||||
public override Task<T> GetAsync(string id)
|
||||
{
|
||||
throw new NotSupportedException("GetAsync(string) is not supported. Use GetAsync(int)");
|
||||
}
|
||||
|
||||
public override T Get(int id)
|
||||
{
|
||||
var key = "Get" + id;
|
||||
var item = Cache.GetOrSet(
|
||||
key,
|
||||
() =>
|
||||
{
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
return db.Get<T>(id);
|
||||
}
|
||||
});
|
||||
return item;
|
||||
}
|
||||
|
||||
public override async Task<T> GetAsync(int id)
|
||||
{
|
||||
var key = "Get" + id;
|
||||
var item = await Cache.GetOrSetAsync(
|
||||
key,
|
||||
async () =>
|
||||
{
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
return await db.GetAsync<T>(id).ConfigureAwait(false);
|
||||
}
|
||||
});
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
28
Old/Ombi.Store/Repository/IExternalUserRepository.cs
Normal file
28
Old/Ombi.Store/Repository/IExternalUserRepository.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public interface IExternalUserRepository<T> where T : Entity
|
||||
{
|
||||
T Get(string id);
|
||||
T Get(int id);
|
||||
Task<T> GetAsync(string id);
|
||||
Task<T> GetAsync(int id);
|
||||
T GetUser(string userGuid);
|
||||
Task<T> GetUserAsync(string userguid);
|
||||
T GetUserByUsername(string username);
|
||||
|
||||
IEnumerable<T> Custom(Func<IDbConnection, IEnumerable<T>> func);
|
||||
long Insert(T entity);
|
||||
void Delete(T entity);
|
||||
IEnumerable<T> GetAll();
|
||||
bool UpdateAll(IEnumerable<T> entity);
|
||||
bool Update(T entity);
|
||||
Task<IEnumerable<T>> GetAllAsync();
|
||||
Task<bool> UpdateAsync(T users);
|
||||
Task<int> InsertAsync(T users);
|
||||
}
|
||||
}
|
94
Old/Ombi.Store/Repository/IRepository.cs
Normal file
94
Old/Ombi.Store/Repository/IRepository.cs
Normal file
|
@ -0,0 +1,94 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: IRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public interface IRepository<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Inserts the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
long Insert(T entity);
|
||||
Task<int> InsertAsync(T entity);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<T> GetAll();
|
||||
Task<IEnumerable<T>> GetAllAsync();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier.</param>
|
||||
/// <returns></returns>
|
||||
T Get(string id);
|
||||
Task<T> GetAsync(string id);
|
||||
T Get(int id);
|
||||
Task<T> GetAsync(int id);
|
||||
/// <summary>
|
||||
/// Deletes the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
void Delete(T entity);
|
||||
Task DeleteAsync(T entity);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
bool Update(T entity);
|
||||
Task<bool> UpdateAsync(T entity);
|
||||
|
||||
/// <summary>
|
||||
/// Updates all.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
bool UpdateAll(IEnumerable<T> entity);
|
||||
Task<bool> UpdateAllAsync(IEnumerable<T> entity);
|
||||
|
||||
bool BatchInsert(IEnumerable<T> entities, string tableName);
|
||||
|
||||
IEnumerable<T> Custom(Func<IDbConnection, IEnumerable<T>> func);
|
||||
Task<IEnumerable<T>> CustomAsync(Func<IDbConnection, Task<IEnumerable<T>>> func);
|
||||
void DeleteAll(string tableName);
|
||||
Task DeleteAllAsync(string tableName);
|
||||
|
||||
T Custom(Func<IDbConnection, T> func);
|
||||
Task<T> CustomAsync(Func<IDbConnection, Task<T>> func);
|
||||
}
|
||||
}
|
77
Old/Ombi.Store/Repository/IRequestRepository.cs
Normal file
77
Old/Ombi.Store/Repository/IRequestRepository.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: ISettingsRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Store.Models;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public interface IRequestRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Inserts the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
long Insert(RequestBlobs entity);
|
||||
|
||||
Task<int> InsertAsync(RequestBlobs entity);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<RequestBlobs> GetAll();
|
||||
|
||||
Task<IEnumerable<RequestBlobs>> GetAllAsync();
|
||||
|
||||
RequestBlobs Get(int id);
|
||||
Task<RequestBlobs> GetAsync(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
bool Delete(RequestBlobs entity);
|
||||
Task<bool> DeleteAsync(RequestBlobs entity);
|
||||
|
||||
bool DeleteAll(IEnumerable<RequestBlobs> entity);
|
||||
Task<bool> DeleteAllAsync(IEnumerable<RequestBlobs> entity);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
bool Update(RequestBlobs entity);
|
||||
Task<bool> UpdateAsync(RequestBlobs entity);
|
||||
|
||||
bool UpdateAll(IEnumerable<RequestBlobs> entity);
|
||||
Task<bool> UpdateAllAsync(IEnumerable<RequestBlobs> entity);
|
||||
}
|
||||
}
|
76
Old/Ombi.Store/Repository/ISettingsRepository.cs
Normal file
76
Old/Ombi.Store/Repository/ISettingsRepository.cs
Normal file
|
@ -0,0 +1,76 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: ISettingsRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Store.Models;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public interface ISettingsRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Inserts the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
long Insert(GlobalSettings entity);
|
||||
Task<int> InsertAsync(GlobalSettings entity);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<GlobalSettings> GetAll();
|
||||
Task<IEnumerable<GlobalSettings>> GetAllAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified identifier.
|
||||
/// </summary>
|
||||
/// <param name="settingsName">Name of the settings.</param>
|
||||
/// <returns></returns>
|
||||
GlobalSettings Get(string settingsName);
|
||||
Task<GlobalSettings> GetAsync(string settingsName);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
Task<bool> DeleteAsync(GlobalSettings entity);
|
||||
bool Delete(GlobalSettings entity);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateAsync(GlobalSettings entity);
|
||||
bool Update(GlobalSettings entity);
|
||||
|
||||
|
||||
}
|
||||
}
|
230
Old/Ombi.Store/Repository/RequestJsonRepository.cs
Normal file
230
Old/Ombi.Store/Repository/RequestJsonRepository.cs
Normal file
|
@ -0,0 +1,230 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: SettingsJsonRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper.Contrib.Extensions;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Models;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class RequestJsonRepository : IRequestRepository
|
||||
{
|
||||
private ICacheProvider Cache { get; }
|
||||
|
||||
public RequestJsonRepository(ISqliteConfiguration config, ICacheProvider cacheProvider)
|
||||
{
|
||||
Db = config;
|
||||
Cache = cacheProvider;
|
||||
}
|
||||
|
||||
private ISqliteConfiguration Db { get; }
|
||||
|
||||
public long Insert(RequestBlobs entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var id = con.Insert(entity);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> InsertAsync(RequestBlobs entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var id = await con.InsertAsync(entity).ConfigureAwait(false);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<RequestBlobs> GetAll()
|
||||
{
|
||||
var key = "GetAll";
|
||||
var item = Cache.GetOrSet(key, () =>
|
||||
{
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var page = con.GetAll<RequestBlobs>();
|
||||
return page;
|
||||
}
|
||||
}, 5);
|
||||
return item;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RequestBlobs>> GetAllAsync()
|
||||
{
|
||||
var key = "GetAll";
|
||||
var item = await Cache.GetOrSetAsync(key, async() =>
|
||||
{
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var page = await con.GetAllAsync<RequestBlobs>().ConfigureAwait(false);
|
||||
return page;
|
||||
}
|
||||
}, 5);
|
||||
return item;
|
||||
}
|
||||
|
||||
public RequestBlobs Get(int id)
|
||||
{
|
||||
var key = "Get" + id;
|
||||
var item = Cache.GetOrSet(key, () =>
|
||||
{
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var page = con.Get<RequestBlobs>(id);
|
||||
return page;
|
||||
}
|
||||
}, 5);
|
||||
return item;
|
||||
}
|
||||
|
||||
public async Task<RequestBlobs> GetAsync(int id)
|
||||
{
|
||||
var key = "Get" + id;
|
||||
var item = await Cache.GetOrSetAsync(key, async () =>
|
||||
{
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var page = await con.GetAsync<RequestBlobs>(id).ConfigureAwait(false);
|
||||
return page;
|
||||
}
|
||||
}, 5);
|
||||
return item;
|
||||
}
|
||||
|
||||
public bool Delete(RequestBlobs entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return con.Delete(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(RequestBlobs entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return await con.DeleteAsync(entity).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAllAsync(IEnumerable<RequestBlobs> entity)
|
||||
{
|
||||
ResetCache();
|
||||
var tasks = new List<Task<bool>>();
|
||||
using (var db = Db.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
foreach (var e in entity)
|
||||
{
|
||||
tasks.Add(db.DeleteAsync(e));
|
||||
}
|
||||
}
|
||||
var result = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
return result.All(x => true);
|
||||
}
|
||||
|
||||
public bool Update(RequestBlobs entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return con.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(RequestBlobs entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return await con.UpdateAsync(entity).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetCache()
|
||||
{
|
||||
Cache.Remove("Get");
|
||||
Cache.Remove("GetAll");
|
||||
}
|
||||
|
||||
public bool UpdateAll(IEnumerable<RequestBlobs> entity)
|
||||
{
|
||||
ResetCache();
|
||||
var result = new HashSet<bool>();
|
||||
using (var db = Db.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
foreach (var e in entity)
|
||||
{
|
||||
result.Add(db.Update(e));
|
||||
}
|
||||
}
|
||||
return result.All(x => true);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAllAsync(IEnumerable<RequestBlobs> entity)
|
||||
{
|
||||
ResetCache();
|
||||
var tasks = new List<Task<bool>>();
|
||||
using (var db = Db.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
foreach (var e in entity)
|
||||
{
|
||||
tasks.Add(db.UpdateAsync(e));
|
||||
}
|
||||
}
|
||||
var result = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
return result.All(x => true);
|
||||
}
|
||||
|
||||
public bool DeleteAll(IEnumerable<RequestBlobs> entity)
|
||||
{
|
||||
ResetCache();
|
||||
var result = new HashSet<bool>();
|
||||
using (var db = Db.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
foreach (var e in entity)
|
||||
{
|
||||
result.Add(db.Delete(e));
|
||||
}
|
||||
}
|
||||
return result.All(x => true);
|
||||
}
|
||||
}
|
||||
}
|
167
Old/Ombi.Store/Repository/SettingsJsonRepository.cs
Normal file
167
Old/Ombi.Store/Repository/SettingsJsonRepository.cs
Normal file
|
@ -0,0 +1,167 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: SettingsJsonRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper.Contrib.Extensions;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Models;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class SettingsJsonRepository : ISettingsRepository
|
||||
{
|
||||
private ICacheProvider Cache { get; }
|
||||
|
||||
private string TypeName { get; }
|
||||
public SettingsJsonRepository(ISqliteConfiguration config, ICacheProvider cacheProvider)
|
||||
{
|
||||
Db = config;
|
||||
Cache = cacheProvider;
|
||||
TypeName = typeof(SettingsJsonRepository).Name;
|
||||
}
|
||||
|
||||
private ISqliteConfiguration Db { get; }
|
||||
|
||||
public long Insert(GlobalSettings entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return con.Insert(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> InsertAsync(GlobalSettings entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return await con.InsertAsync(entity).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<GlobalSettings> GetAll()
|
||||
{
|
||||
var key = TypeName + "GetAll";
|
||||
var item = Cache.GetOrSet(key, () =>
|
||||
{
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var page = con.GetAll<GlobalSettings>();
|
||||
return page;
|
||||
}
|
||||
}, 5);
|
||||
return item;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<GlobalSettings>> GetAllAsync()
|
||||
{
|
||||
var key = TypeName + "GetAll";
|
||||
var item = await Cache.GetOrSetAsync(key, async() =>
|
||||
{
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var page = await con.GetAllAsync<GlobalSettings>().ConfigureAwait(false);
|
||||
return page;
|
||||
}
|
||||
}, 5);
|
||||
return item;
|
||||
}
|
||||
|
||||
public GlobalSettings Get(string pageName)
|
||||
{
|
||||
var key = pageName + "Get";
|
||||
var item = Cache.GetOrSet(key, () =>
|
||||
{
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var page = con.GetAll<GlobalSettings>().SingleOrDefault(x => x.SettingsName == pageName);
|
||||
return page;
|
||||
}
|
||||
}, 5);
|
||||
return item;
|
||||
}
|
||||
|
||||
public async Task<GlobalSettings> GetAsync(string settingsName)
|
||||
{
|
||||
var key = settingsName + "Get";
|
||||
var item = await Cache.GetOrSetAsync(key, async() =>
|
||||
{
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var page = await con.GetAllAsync<GlobalSettings>().ConfigureAwait(false);
|
||||
return page.SingleOrDefault(x => x.SettingsName == settingsName);
|
||||
}
|
||||
}, 5);
|
||||
return item;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(GlobalSettings entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return await con.DeleteAsync(entity).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(GlobalSettings entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return await con.UpdateAsync(entity).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Delete(GlobalSettings entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return con.Delete(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Update(GlobalSettings entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return con.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetCache()
|
||||
{
|
||||
Cache.Remove("Get");
|
||||
Cache.Remove(TypeName + "GetAll");
|
||||
}
|
||||
}
|
||||
}
|
116
Old/Ombi.Store/Repository/UserRepository.cs
Normal file
116
Old/Ombi.Store/Repository/UserRepository.cs
Normal file
|
@ -0,0 +1,116 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: UserRepository.cs
|
||||
// Created By:
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Ombi.Helpers;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class UserRepository : BaseGenericRepository<UsersModel>, IUserRepository
|
||||
{
|
||||
public UserRepository(ISqliteConfiguration config, ICacheProvider cache) : base(config,cache)
|
||||
{
|
||||
DbConfig = config;
|
||||
}
|
||||
|
||||
private ISqliteConfiguration DbConfig { get; }
|
||||
private IDbConnection Db => DbConfig.DbConnection();
|
||||
|
||||
public UsersModel GetUser(string userGuid)
|
||||
{
|
||||
var sql = @"SELECT * FROM Users
|
||||
WHERE Userguid = @UserGuid
|
||||
COLLATE NOCASE";
|
||||
return Db.QueryFirstOrDefault<UsersModel>(sql, new {UserGuid = userGuid});
|
||||
}
|
||||
|
||||
public UsersModel GetUserByUsername(string username)
|
||||
{
|
||||
var sql = @"SELECT * FROM Users
|
||||
WHERE UserName = @UserName
|
||||
COLLATE NOCASE";
|
||||
return Db.QueryFirstOrDefault<UsersModel>(sql, new {UserName = username});
|
||||
}
|
||||
|
||||
public async Task<UsersModel> GetUserAsync(string userguid)
|
||||
{
|
||||
var sql = @"SELECT * FROM Users
|
||||
WHERE UserGuid = @UserGuid
|
||||
COLLATE NOCASE";
|
||||
return await Db.QueryFirstOrDefaultAsync<UsersModel>(sql, new {UserGuid = userguid});
|
||||
}
|
||||
|
||||
#region abstract implementation
|
||||
|
||||
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
|
||||
[Obsolete]
|
||||
public override UsersModel Get(string id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public override Task<UsersModel> GetAsync(int id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public override UsersModel Get(int id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public override Task<UsersModel> GetAsync(string id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
public interface IUserRepository
|
||||
{
|
||||
UsersModel GetUser(string userGuid);
|
||||
UsersModel GetUserByUsername(string username);
|
||||
Task<UsersModel> GetUserAsync(string userguid);
|
||||
IEnumerable<UsersModel> Custom(Func<IDbConnection, IEnumerable<UsersModel>> func);
|
||||
long Insert(UsersModel entity);
|
||||
void Delete(UsersModel entity);
|
||||
IEnumerable<UsersModel> GetAll();
|
||||
bool UpdateAll(IEnumerable<UsersModel> entity);
|
||||
bool Update(UsersModel entity);
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue