From e5b88bc261c26d920a247baff463c08c16edea38 Mon Sep 17 00:00:00 2001 From: Cam Date: Wed, 12 Aug 2015 21:58:16 +1200 Subject: [PATCH] added Status mapping and query processors --- .../BeyondEarthApp.Data.SqlServer.csproj | 3 +++ .../Mapping/StatusMap.cs | 19 +++++++++++++++ .../QueryProcessors/GameByIdQueryProcessor.cs | 22 +++++++++++++++++ .../UpdateGameStatusQueryProcessor.cs | 24 +++++++++++++++++++ .../App_Start/NinjectConfigurator.cs | 12 ++++++++++ 5 files changed, 80 insertions(+) create mode 100644 src/BeyondEarthApp.Data.SqlServer/Mapping/StatusMap.cs create mode 100644 src/BeyondEarthApp.Data.SqlServer/QueryProcessors/GameByIdQueryProcessor.cs create mode 100644 src/BeyondEarthApp.Data.SqlServer/QueryProcessors/UpdateGameStatusQueryProcessor.cs diff --git a/src/BeyondEarthApp.Data.SqlServer/BeyondEarthApp.Data.SqlServer.csproj b/src/BeyondEarthApp.Data.SqlServer/BeyondEarthApp.Data.SqlServer.csproj index 05c5554..36fea50 100644 --- a/src/BeyondEarthApp.Data.SqlServer/BeyondEarthApp.Data.SqlServer.csproj +++ b/src/BeyondEarthApp.Data.SqlServer/BeyondEarthApp.Data.SqlServer.csproj @@ -51,6 +51,7 @@ + @@ -58,6 +59,8 @@ + + diff --git a/src/BeyondEarthApp.Data.SqlServer/Mapping/StatusMap.cs b/src/BeyondEarthApp.Data.SqlServer/Mapping/StatusMap.cs new file mode 100644 index 0000000..b4eb6c9 --- /dev/null +++ b/src/BeyondEarthApp.Data.SqlServer/Mapping/StatusMap.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BeyondEarthApp.Data.Entities; + +namespace BeyondEarthApp.Data.SqlServer.Mapping +{ + public class StatusMap : VersionedClassMap + { + public StatusMap() + { + Id(x => x.StatusId); + Map(x => x.Name).Not.Nullable(); + Map(x => x.Ordinal).Not.Nullable(); + } + } +} diff --git a/src/BeyondEarthApp.Data.SqlServer/QueryProcessors/GameByIdQueryProcessor.cs b/src/BeyondEarthApp.Data.SqlServer/QueryProcessors/GameByIdQueryProcessor.cs new file mode 100644 index 0000000..10edd25 --- /dev/null +++ b/src/BeyondEarthApp.Data.SqlServer/QueryProcessors/GameByIdQueryProcessor.cs @@ -0,0 +1,22 @@ +using BeyondEarthApp.Data.Entities; +using BeyondEarthApp.Data.QueryProcessors; +using NHibernate; + +namespace BeyondEarthApp.Data.SqlServer.QueryProcessors +{ + public class GameByIdQueryProcessor : IGameByIdQueryProcessor + { + private readonly ISession _session; + + public GameByIdQueryProcessor(ISession session) + { + _session = session; + } + + public Game GetGame(long gameId) + { + var game = _session.Get(gameId); + return game; + } + } +} diff --git a/src/BeyondEarthApp.Data.SqlServer/QueryProcessors/UpdateGameStatusQueryProcessor.cs b/src/BeyondEarthApp.Data.SqlServer/QueryProcessors/UpdateGameStatusQueryProcessor.cs new file mode 100644 index 0000000..9a598ac --- /dev/null +++ b/src/BeyondEarthApp.Data.SqlServer/QueryProcessors/UpdateGameStatusQueryProcessor.cs @@ -0,0 +1,24 @@ +using BeyondEarthApp.Data.Entities; +using BeyondEarthApp.Data.QueryProcessors; +using NHibernate; + +namespace BeyondEarthApp.Data.SqlServer.QueryProcessors +{ + public class UpdateGameStatusQueryProcessor : IUpdateGameStatusQueryProcessor + { + private readonly ISession _session; + + public UpdateGameStatusQueryProcessor(ISession session) + { + _session = session; + } + + public void UpdateGameStatus(Game gameToUpdate, string statusName) + { + var status = _session.QueryOver().Where(x => x.Name == statusName).SingleOrDefault(); + gameToUpdate.Status = status; + + _session.SaveOrUpdate(gameToUpdate); + } + } +} diff --git a/src/BeyondEarthApp.Web.Api/App_Start/NinjectConfigurator.cs b/src/BeyondEarthApp.Web.Api/App_Start/NinjectConfigurator.cs index 812b383..2fcebed 100644 --- a/src/BeyondEarthApp.Web.Api/App_Start/NinjectConfigurator.cs +++ b/src/BeyondEarthApp.Web.Api/App_Start/NinjectConfigurator.cs @@ -63,6 +63,16 @@ private void AddBindings(IKernel container) .To() .InRequestScope(); + container + .Bind() + .To() + .InSingletonScope(); + + container + .Bind() + .To() + .InRequestScope(); + // Maintenance processors container .Bind() @@ -87,6 +97,7 @@ private void ConfigureAutoMapper(IKernel container) MapConfigurator(container); MapConfigurator(container); MapConfigurator(container); + MapConfigurator(container); MapConfigurator(container); MapConfigurator(container); @@ -96,6 +107,7 @@ private void ConfigureAutoMapper(IKernel container) MapConfigurator(container); MapConfigurator(container); MapConfigurator(container); + MapConfigurator(container); MapConfigurator(container); MapConfigurator(container); MapConfigurator(container);