public void SaveAlias(AliasCollectionItem aliasToSave) { using (var session = ModelEntities.OpenSession()) { using (var transaction = session.BeginTransaction()) { var playersIds = aliasToSave.PlayersInAlias.Select(x => x.PlayerId).ToArray(); var players = session.Query <Players>().Where(x => playersIds.Contains(x.PlayerId)).ToArray(); var alias = new Aliases() { AliasId = aliasToSave.PlayerId, AliasName = aliasToSave.Name, Players = players }; session.SaveOrUpdate(alias); transaction.Commit(); if (aliasToSave.PlayerId == 0) { aliasToSave.PlayerId = alias.AliasId; } } } }
public void RemoveAlias(AliasCollectionItem aliasToRemove) { using (var session = ModelEntities.OpenSession()) { using (var transaction = session.BeginTransaction()) { var aliasEntity = session.Load <Aliases>(aliasToRemove.PlayerId); session.Delete(aliasEntity); transaction.Commit(); } } }
public IPlayer GetActivePlayer() { IPlayer activePlayer = new PlayerCollectionItem(); string dataPath = StringFormatter.GetActivePlayerFilePath(); if (File.Exists(dataPath)) { var splittedResult = File.ReadAllText(dataPath).Split(new string[] { Environment.NewLine }, StringSplitOptions.None); if (splittedResult.Length < 2) { try { using (var session = ModelEntities.OpenSession()) { var alias = session.Query <Aliases>().Fetch(x => x.Players).FirstOrDefault(x => x.AliasName.Equals(splittedResult[0])); if (alias != null) { activePlayer = new AliasCollectionItem { PlayerId = alias.AliasId, Name = alias.AliasName, PlayersInAlias = new ObservableCollection <PlayerCollectionItem>(alias.Players.Select(p => new PlayerCollectionItem { PlayerId = p.PlayerId, PokerSite = (EnumPokerSites)p.PokersiteId, Name = p.Playername })) }; } } } catch (Exception e) { LogProvider.Log.Error(this, "Couldn't get active alias", e); } return(activePlayer); } if (!short.TryParse(splittedResult[1], out short pokerSiteId)) { return(activePlayer); } try { using (var session = ModelEntities.OpenSession()) { var player = session.Query <Players>().FirstOrDefault(x => x.Playername.Equals(splittedResult[0]) && x.PokersiteId == pokerSiteId); if (player != null) { activePlayer = new PlayerCollectionItem { PlayerId = player.PlayerId, Name = player.Playername, PokerSite = (EnumPokerSites)player.PokersiteId }; } } } catch (Exception e) { LogProvider.Log.Error(this, "Couldn't get active player", e); } } return(activePlayer); }