mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
added helpers
This commit is contained in:
parent
96a3970a53
commit
83ce84660a
12 changed files with 721 additions and 0 deletions
70
RequestPlex.Store/ISettingsRepository.cs
Normal file
70
RequestPlex.Store/ISettingsRepository.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
#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 RequestPlex.Store.Models;
|
||||
|
||||
namespace RequestPlex.Store
|
||||
{
|
||||
public interface ISettingsRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Inserts the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
long Insert(GlobalSettings entity);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<GlobalSettings> GetAll();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified identifier.
|
||||
/// </summary>
|
||||
/// <param name="settingsName">Name of the settings.</param>
|
||||
/// <returns></returns>
|
||||
GlobalSettings Get(string settingsName);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
bool Delete(GlobalSettings entity);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
bool Update(GlobalSettings entity);
|
||||
|
||||
|
||||
}
|
||||
}
|
39
RequestPlex.Store/Models/GlobalSettings.cs
Normal file
39
RequestPlex.Store/Models/GlobalSettings.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: GlobalSettings.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 Dapper.Contrib.Extensions;
|
||||
|
||||
namespace RequestPlex.Store.Models
|
||||
{
|
||||
|
||||
[Table("GlobalSettings")]
|
||||
public class GlobalSettings : Entity
|
||||
{
|
||||
public string Content { get; set; }
|
||||
public string SettingsName { get; set; }
|
||||
}
|
||||
|
||||
}
|
119
RequestPlex.Store/Repository/JsonRepository.cs
Normal file
119
RequestPlex.Store/Repository/JsonRepository.cs
Normal file
|
@ -0,0 +1,119 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: JsonRepository.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 Dapper.Contrib.Extensions;
|
||||
|
||||
using RequestPlex.Helpers;
|
||||
using RequestPlex.Store.Models;
|
||||
|
||||
namespace RequestPlex.Store.Repository
|
||||
{
|
||||
|
||||
|
||||
namespace NZBDash.DataAccessLayer.Repository
|
||||
{
|
||||
public class JsonRepository : ISettingsRepository
|
||||
{
|
||||
private ICacheProvider Cache { get; set; }
|
||||
|
||||
private string TypeName { get; set; }
|
||||
public JsonRepository(ISqliteConfiguration config, ICacheProvider cacheProvider)
|
||||
{
|
||||
Db = config;
|
||||
Cache = cacheProvider;
|
||||
TypeName = typeof(JsonRepository).Name;
|
||||
}
|
||||
|
||||
private ISqliteConfiguration Db { get; set; }
|
||||
|
||||
public long Insert(GlobalSettings entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return con.Insert(entity);
|
||||
}
|
||||
}
|
||||
|
||||
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 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 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,9 +53,12 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="DbConfiguration.cs" />
|
||||
<Compile Include="Entity.cs" />
|
||||
<Compile Include="ISettingsRepository.cs" />
|
||||
<Compile Include="ISqliteConfiguration.cs" />
|
||||
<Compile Include="IRepository.cs" />
|
||||
<Compile Include="Models\GlobalSettings.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Repository\JsonRepository.cs" />
|
||||
<Compile Include="SettingsModel.cs" />
|
||||
<Compile Include="GenericRepository.cs" />
|
||||
<Compile Include="RequestedModel.cs" />
|
||||
|
@ -83,6 +86,12 @@
|
|||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RequestPlex.Helpers\RequestPlex.Helpers.csproj">
|
||||
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
|
||||
<Name>RequestPlex.Helpers</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue