private void OnSubmitSubscription(object sender, RoutedEventArgs e)
 {
     if (_login.Text.Trim() != "" && _password.Text.Trim() != "")
     {
         try
         {
             mainWindow.ChannelFactory = new DuplexChannelFactory<IBomberService>(mainWindow, "BomberServiceEndpoint");
             mainWindow.Server = mainWindow.ChannelFactory.CreateChannel();
             var account = new AccountDC()
             {
                 Login = _login.Text,
                 Password = _password.Text
             };
             var player = new PlayerDC()
             {
                 Pseudonym = _pseudonym.Text,
                 PlayerDescription = _playerDescription.Text,
             };
             if (player.Pseudonym.Trim() == "")
                 player.Pseudonym = account.Login;
             mainWindow.Server.CreateAccount(account, player);
             mainWindow.IsEnabled = false;
         }
         catch
         {
             MessageBox.Show("Conexion failure... Please try again later.");
         }
     }
     else
     {
         MessageBox.Show("Please choose a login and password before submitting.");
     }
 }
 public void StartSession(AccountDC a)
 {
     Callback = OperationContext.Current.GetCallbackChannel<IBomberCallback>();
     using (var db = new BomberDbContext())
     {
         var query = from ac in db.Accounts
                     where ac.Login == a.Login
                     && ac.Password == a.Password
                     select ac;
         if (query.Count() == 0)
         {
             Callback.RejectConnection();
             ConnexionDenied = true;
         }
         else
         {
             var p = query.ToList<Account>().ElementAt(0).Player;
             if (Sessions.Keys.Contains(p.PlayerId))
             {
                 p.PlayerStatus = "Offline";
                 db.SaveChanges();
                 Sessions[p.PlayerId].Callback.DisconnectPlayer();
                 Callback.DisconnectPlayer();
                 return;
             }
             p.PlayerStatus = "Online";
             db.SaveChanges();
             Sessions.Add(p.PlayerId, this);
             this.Player = p;
             var profil = EntityContractTranslator.PlayerToPlayerDC(p);
             var friendShipRequests = EntityContractTranslator.PlayersToPlayerDCs(p.PlayersRequestingFriendship);
             //notifying connected friends:
             var connectedFriends = from f in p.Friends
                                    where Sessions.Keys.Contains(f.PlayerId)
                                    select f;
             foreach (var f in connectedFriends)
             {
                 var session = Sessions[f.PlayerId];
                 session.Callback.NotifyPlayerStatusChange(profil);
             }
             //retrieving conversations
             List<Conversation> convs = new List<Conversation>();
             foreach (var c in db.Conversations)
             {
                 if (c.Host.PlayerId == p.PlayerId || (from pl in c.Players select pl.PlayerId).Contains(p.PlayerId))
                     convs.Add(c);
             }
             List<ConversationDC> playerConvDCs = new List<ConversationDC>();
             if (convs.Count > 0)
             {
                 foreach (var c in convs)
                 {
                     ConversationManager cm = null;
                     if (Conversations.Keys.Contains(c.ConversationId))
                     {
                         cm = Conversations[c.ConversationId];
                     }
                     else
                     {
                         cm = new ConversationManager(new ConversationDC()
                         {
                             ConversationId = c.ConversationId,
                             Host = EntityContractTranslator.PlayerToPlayerDC(c.Host),
                             ConversationLog = c.ConversationLog,
                             Participants = EntityContractTranslator.PlayersToPlayerDCs(c.Players),
                             NewMessage = ""
                         });
                         Conversations.Add(cm.Conv.ConversationId, cm);
                     }
                     playerConvDCs.Add(cm.Conv);
                     cm.EndOfConvEvent += EndOfConvEventHandler;
                     cm.JoinEvent += JoinConvEventHandler;
                     cm.KickEvent += KickFromConvEventHandler;
                     cm.LeaveEvent += LeaveConvEventHandler;
                     cm.MessageEvent += ConvMessageEventHandler;
                 }
             }
             Callback.ReceiveProfil(profil, friendShipRequests, playerConvDCs);
         }
     }
 }
 public void CreateAccount(AccountDC newAccount, PlayerDC player)
 {
     Callback = OperationContext.Current.GetCallbackChannel<IBomberCallback>();
     using (var db = new BomberDbContext())
     {
         var p = new Player()
         {
             Pseudonym = player.Pseudonym,
             PlayerStatus = "Offline",
             PlayerDescription = player.PlayerDescription
         };
         var a = new Account()
         {
             Login = newAccount.Login,
             Password = newAccount.Password,
             AccountType = "normal",
             Player = p
         };
         p.Account = a;
         db.Accounts.AddObject(a);
         db.Players.AddObject(p);
         try
         {
             db.SaveChanges();
             Callback.NotifySubscriptionSuccess();
         }
         catch
         {
             Callback.RefuseSubscription();
         }
     }
 }