public ActivateKeyOutput ActivateKey(ActivateKeyInput input) { IList <Key> keys = KeyRepository.GetAll().Where(r => r.KeyValue == input.Key && r.OwnerUserId == null).ToList(); if (keys.Count != 1) { throw new KeyActivationException(input.Key); } Key keyEntity = keys.Single(); keyEntity.OwnerUserId = Session.UserId; KeyRepository.Update(keyEntity); GameRepository.Includes.Add(r => r.Location); GameRepository.Includes.Add(r => r.GameStatus); GameRepository.Includes.Add(r => r.GameTasks); GameRepository.Includes.Add(r => r.LastModifierUser); GameRepository.Includes.Add(r => r.CreatorUser); GameLightDto activatedGame = GameRepository.Get(keyEntity.GameId).MapTo <GameLightDto>(); GameRepository.Includes.Clear(); UowManager.Current.Completed += (sender, e) => { GameChangesNotifier.RaiseOnKeyActivated(new KeyActivatedMessage(activatedGame, Session.UserId, input.Key)); }; return(new ActivateKeyOutput() { ActivatedGame = activatedGame }); }
public RetrieveGameLightOutput RetrieveGameLight(RetrieveGameLightInput input) { KeyRepository.Includes.Add(r => r.Game); KeyRepository.Includes.Add(r => r.Game.Location); KeyRepository.Includes.Add(r => r.Game.GameStatus); KeyRepository.Includes.Add(r => r.Game.GameTasks); KeyRepository.Includes.Add(r => r.Game.GameTasks.Select(e => e.GameTaskType)); //KeyRepository.Includes.Add(r => r.Game.GameTasks.SelectMany(e => e.Conditions)); //KeyRepository.Includes.Add(r => r.Game.GameTasks.SelectMany(e => e.Conditions.Select(k => k.ConditionType))); //KeyRepository.Includes.Add(r => r.Game.GameTasks.SelectMany(e => e.Tips)); Game gameEntity = GameRepository.Get(input.GameId); if (gameEntity == null || !GamePolicy.CanRetrieveEntityLight(gameEntity)) { return(new RetrieveGameLightOutput()); } GameLightDto game = gameEntity.MapTo <GameLightDto>(); KeyRepository.Includes.Clear(); return(new RetrieveGameLightOutput() { Game = game }); }
public KeyActivatedMessage(GameLightDto game, long?userId, string key) { Game = game; UserId = userId; Key = key; }