From 84ea45ebaa18e87fa7be11999824052a95060e19 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Mon, 14 Nov 2016 10:06:35 +0000 Subject: [PATCH] Fixed #665 --- .../MigrationRunner.cs | 4 --- .../Migrations/Version1100.cs | 25 ++++++++++++------- .../PlexRequests.Core.Migration.csproj | 4 +++ .../Repository/UserRepository.cs | 3 +++ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/PlexRequests.Core.Migration/MigrationRunner.cs b/PlexRequests.Core.Migration/MigrationRunner.cs index 5a1a67f10..5535782a6 100644 --- a/PlexRequests.Core.Migration/MigrationRunner.cs +++ b/PlexRequests.Core.Migration/MigrationRunner.cs @@ -39,10 +39,6 @@ namespace PlexRequests.Core.Migration foreach (var param in ctor.GetParameters()) { - Console.WriteLine(string.Format( - "Param {0} is named {1} and is of type {2}", - param.Position, param.Name, param.ParameterType)); - var dep = Kernel.Get(param.ParameterType); dependencies.Add(dep); } diff --git a/PlexRequests.Core.Migration/Migrations/Version1100.cs b/PlexRequests.Core.Migration/Migrations/Version1100.cs index 804dfa438..3238b9c27 100644 --- a/PlexRequests.Core.Migration/Migrations/Version1100.cs +++ b/PlexRequests.Core.Migration/Migrations/Version1100.cs @@ -26,6 +26,8 @@ #endregion using System.Data; +using System.Linq; +using PlexRequests.Helpers.Permissions; using PlexRequests.Store; using PlexRequests.Store.Repository; @@ -36,17 +38,17 @@ namespace PlexRequests.Core.Migration.Migrations { public Version1100(IUserRepository userRepo) { - + UserRepo = userRepo; } public int Version => 11000; - public IUserRepository UserRepo {get;set;} + private IUserRepository UserRepo { get; } public void Start(IDbConnection con) { UpdateDb(con); // Update the current admin permissions set - UpdateAdmin(con); + UpdateAdmin(); UpdateSchema(con, Version); } @@ -56,19 +58,24 @@ namespace PlexRequests.Core.Migration.Migrations // Create the two new columns con.AlterTable("Users", "ADD", "Permissions", true, "INTEGER"); con.AlterTable("Users", "ADD", "Features", true, "INTEGER"); - + } - private void UpdateAdmin(IDbConnection con) + private void UpdateAdmin() { - var users = UserRepo.GetAll(); + var users = UserRepo.GetAll().ToList(); foreach (var user in users) { - user.Permissions = Permissions.Administrator | ReportIssue | RequestMusic - | RequestTvShow - | RequestMovie; + user.Permissions = (int) + (Permissions.Administrator + | Permissions.ReportIssue + | Permissions.RequestMusic + | Permissions.RequestTvShow + | Permissions.RequestMovie); } + + UserRepo.UpdateAll(users); } } } \ No newline at end of file diff --git a/PlexRequests.Core.Migration/PlexRequests.Core.Migration.csproj b/PlexRequests.Core.Migration/PlexRequests.Core.Migration.csproj index 2881f95ed..e724145c4 100644 --- a/PlexRequests.Core.Migration/PlexRequests.Core.Migration.csproj +++ b/PlexRequests.Core.Migration/PlexRequests.Core.Migration.csproj @@ -74,6 +74,10 @@ {DD7DC444-D3BF-4027-8AB9-EFC71F5EC581} PlexRequests.Core + + {1252336D-42A3-482A-804C-836E60173DFA} + PlexRequests.Helpers + {92433867-2B7B-477B-A566-96C382427525} PlexRequests.Store diff --git a/PlexRequests.Store/Repository/UserRepository.cs b/PlexRequests.Store/Repository/UserRepository.cs index b05609c82..d661a30ec 100644 --- a/PlexRequests.Store/Repository/UserRepository.cs +++ b/PlexRequests.Store/Repository/UserRepository.cs @@ -105,6 +105,9 @@ namespace PlexRequests.Store.Repository IEnumerable Custom(Func> func); long Insert(UsersModel entity); void Delete(UsersModel entity); + IEnumerable GetAll(); + bool UpdateAll(IEnumerable entity); + bool Update(UsersModel entity); } }