Done most on #59

This commit is contained in:
tidusjar 2016-03-23 13:43:27 +00:00
commit c7ac8a7d99
32 changed files with 345 additions and 2283 deletions

View file

@ -32,6 +32,7 @@ using Newtonsoft.Json;
using PlexRequests.Store;
using PlexRequests.Store.Models;
using PlexRequests.Store.Repository;
namespace PlexRequests.Core
{

View file

@ -81,7 +81,6 @@
<Compile Include="SettingModels\CouchPotatoSettings.cs" />
<Compile Include="SettingModels\PlexRequestSettings.cs" />
<Compile Include="SettingModels\Settings.cs" />
<Compile Include="RequestService.cs" />
<Compile Include="SettingsServiceV2.cs" />
<Compile Include="Setup.cs" />
<Compile Include="StatusChecker.cs" />

View file

@ -1,84 +0,0 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: RequestService.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 PlexRequests.Store;
namespace PlexRequests.Core
{
public class RequestService : IRequestService
{
public RequestService(IRepository<RequestedModel> db)
{
Repo = db;
}
private IRepository<RequestedModel> Repo { get; set; }
public long AddRequest(RequestedModel model)
{
return Repo.Insert(model);
}
public bool CheckRequest(int providerId)
{
return Repo.GetAll().Any(x => x.ProviderId == providerId);
}
public void DeleteRequest(RequestedModel model)
{
var entity = Repo.Get(model.Id);
Repo.Delete(entity);
}
public bool UpdateRequest(RequestedModel model)
{
return Repo.Update(model);
}
/// <summary>
/// Updates all the entities. NOTE: we need to Id to be the original entity
/// </summary>
/// <param name="model">The model.</param>
/// <returns></returns>
public bool BatchUpdate(List<RequestedModel> model)
{
return Repo.UpdateAll(model);
}
public RequestedModel Get(int id)
{
return Repo.Get(id);
}
public IEnumerable<RequestedModel> GetAll()
{
return Repo.GetAll();
}
}
}

View file

@ -30,6 +30,7 @@ using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Store;
using PlexRequests.Store.Models;
using PlexRequests.Store.Repository;
namespace PlexRequests.Core
{

View file

@ -75,7 +75,7 @@ namespace PlexRequests.Core
{
var result = new List<long>();
RequestedModel[] requestedModels;
var repo = new GenericRepository<RequestedModel>(Db);
var repo = new GenericRepository<RequestedModel>(Db, new MemoryCacheProvider());
try
{
var records = repo.GetAll();

View file

@ -88,12 +88,12 @@ namespace PlexRequests.Core
return users.Any();
}
public static Guid? CreateUser(string username, string password)
public static Guid? CreateUser(string username, string password, string[] claims = default(string[]))
{
var repo = new UserRepository<UsersModel>(Db);
var salt = PasswordHasher.GenerateSalt();
var userModel = new UsersModel { UserName = username, UserGuid = Guid.NewGuid().ToString(), Salt = salt, Hash = PasswordHasher.ComputeHash(password, salt)};
var userModel = new UsersModel { UserName = username, UserGuid = Guid.NewGuid().ToString(), Salt = salt, Hash = PasswordHasher.ComputeHash(password, salt), Claims = claims};
repo.Insert(userModel);
var userRecord = repo.Get(userModel.UserGuid);