public void ChangeUsername(string username, string password, string newUsername) { if (string.IsNullOrWhiteSpace(username) | string.IsNullOrWhiteSpace(password) | string.IsNullOrWhiteSpace(newUsername)) { SendCallbackMessage("Некоторые поля не заполнены!"); } else { using (var context = new ChessDb.Context()) { if (context.HasUser(newUsername)) { SendCallbackMessage("Такой пользователь уже существует!"); } else if (context.HasUser(username, password)) { context.Users.SingleOrDefault(item => item.Username == username).Username = newUsername; context.SaveChanges(); try { var callback = OperationContext.Current.GetCallbackChannel <IGameSessionEstablishmentCallback>(); callback.UsernameChanged(newUsername); } catch (Exception) { } } else { SendCallbackMessage("Неверный пароль!"); } } } }
public void LoginUser(string username, string password) { if (string.IsNullOrWhiteSpace(username) | string.IsNullOrWhiteSpace(password)) { SendCallbackMessage("Некоторые поля не заполнены!"); } else { using (var context = new ChessDb.Context()) { if (context.HasUser(username, password)) { try { var callback = OperationContext.Current.GetCallbackChannel <IGameSessionEstablishmentCallback>(); var rating = context.GetTotalScore(username); callback.SuccesfullAuthentificate(username, password, rating); } catch (Exception) { } } else { SendCallbackMessage("Такого пользователя не существует!"); } } } }
public void SignupUser(string username, string password, string confirmedPassword) { if (string.IsNullOrWhiteSpace(username) | string.IsNullOrWhiteSpace(password) | string.IsNullOrWhiteSpace(confirmedPassword)) { SendCallbackMessage("Некоторые поля не заполнены!"); } else if (password != confirmedPassword) { SendCallbackMessage("Пароли не совподают!"); } else { using (var context = new ChessDb.Context()) { if (context.HasUser(username)) { SendCallbackMessage("Такой пользователь уже существует!"); } else { context.CreateUser(username, password); try { var callback = OperationContext.Current.GetCallbackChannel <IGameSessionEstablishmentCallback>(); callback.SuccesfullAuthentificate(username, password, 2000); } catch (Exception) { } } } } }
private bool TryCreatePlayer(string username, string password) { bool playerIsConnected = false; bool isExistPlayer = _players.Exists(item => item.Name == username); bool inputDataIsNotNull = !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password); if (CurrentPlayer == null && inputDataIsNotNull && !isExistPlayer) { using (var context = new ChessDb.Context()) { if (context.HasUser(username, password)) { var callback = OperationContext.Current.GetCallbackChannel <IGameSessionEstablishmentCallback>(); CurrentPlayer = new Player(username, context.GetTotalScore(username), callback); _players.Add(CurrentPlayer); playerIsConnected = true; } } } return(playerIsConnected); }