Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added Status mapping and query processors
  • Loading branch information
camjm committed Aug 12, 2015
1 parent 6ccb7d7 commit e5b88bc
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
Expand Up @@ -51,13 +51,16 @@
<Compile Include="Mapping\BuildingMap.cs" />
<Compile Include="Mapping\FactionMap.cs" />
<Compile Include="Mapping\GameMap.cs" />
<Compile Include="Mapping\StatusMap.cs" />
<Compile Include="Mapping\TechnologyMap.cs" />
<Compile Include="Mapping\UnitMap.cs" />
<Compile Include="Mapping\UserMap.cs" />
<Compile Include="Mapping\VersionedClassMap.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QueryProcessors\AddGameQueryProcessor.cs" />
<Compile Include="QueryProcessors\AddTechnologyQueryProcessor.cs" />
<Compile Include="QueryProcessors\GameByIdQueryProcessor.cs" />
<Compile Include="QueryProcessors\UpdateGameStatusQueryProcessor.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
19 changes: 19 additions & 0 deletions 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<Status>
{
public StatusMap()
{
Id(x => x.StatusId);
Map(x => x.Name).Not.Nullable();
Map(x => x.Ordinal).Not.Nullable();
}
}
}
@@ -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<Game>(gameId);
return game;
}
}
}
@@ -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<Status>().Where(x => x.Name == statusName).SingleOrDefault();
gameToUpdate.Status = status;

_session.SaveOrUpdate(gameToUpdate);
}
}
}
12 changes: 12 additions & 0 deletions src/BeyondEarthApp.Web.Api/App_Start/NinjectConfigurator.cs
Expand Up @@ -63,6 +63,16 @@ private void AddBindings(IKernel container)
.To<AddGameQueryProcessor>()
.InRequestScope();

container
.Bind<IGameByIdQueryProcessor>()
.To<IGameByIdQueryProcessor>()
.InSingletonScope();

container
.Bind<IUpdateGameStatusQueryProcessor>()
.To<UpdateGameStatusQueryProcessor>()
.InRequestScope();

// Maintenance processors
container
.Bind<IAddTechnologyMaintenanceProcessor>()
Expand All @@ -87,6 +97,7 @@ private void ConfigureAutoMapper(IKernel container)
MapConfigurator<EntityToService.BuildingConfigurator>(container);
MapConfigurator<EntityToService.UnitConfigurator>(container);
MapConfigurator<EntityToService.FactionConfigurator>(container);
MapConfigurator<EntityToService.StatusConfigurator>(container);
MapConfigurator<EntityToService.GameConfigurator>(container);
MapConfigurator<EntityToService.UserConfigurator>(container);

Expand All @@ -96,6 +107,7 @@ private void ConfigureAutoMapper(IKernel container)
MapConfigurator<ServiceToEntity.BuildingConfigurator>(container);
MapConfigurator<ServiceToEntity.UnitConfigurator>(container);
MapConfigurator<ServiceToEntity.FactionConfigurator>(container);
MapConfigurator<ServiceToEntity.StatusConfigurator>(container);
MapConfigurator<ServiceToEntity.NewGameConfigurator>(container);
MapConfigurator<ServiceToEntity.GameConfigurator>(container);
MapConfigurator<ServiceToEntity.UserConfigurator>(container);
Expand Down

0 comments on commit e5b88bc

Please sign in to comment.