Пример #1
0
        // POST: api/User?username=elad
        private void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {
            var controller = "User?username="******"&token=" + _user.token;
            var data       = "{\"Username\":\"" + Crypto.Encrypt(UsernameTxt.Text) + "\"," +
                             "\"Password\":\"" + Crypto.Encrypt(PasswordTxt.Text) + "\","
                             + "\"AvatarPath\":\"" + Picture + "\"," +
                             "\"Email\":\"" + Crypto.Encrypt(EmailTxt.Text) + "\"}";

            try
            {
                var ans     = RestClient.MakePostRequest(controller, data);
                var json    = JObject.Parse(ans);
                var tmpUser = json.ToObject <UserData>();
                if (tmpUser.Message == null)
                {
                    _user.Username   = Crypto.Decrypt(tmpUser.Username);
                    _user.Password   = Crypto.Decrypt(tmpUser.Password);
                    _user.Email      = Crypto.Decrypt(tmpUser.Email);
                    _user.AvatarPath = tmpUser.AvatarPath;
                    _mainWindow.UpdateAvatar(tmpUser.AvatarPath);
                    Close();
                }
                else
                {
                    MessageBox.Show(tmpUser.Message, "Error in edit profile", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch
            {
                this._mainWindow.HandleCrashing();
            }
        }
Пример #2
0
        private void LogInButtonClick(object sender, RoutedEventArgs e)
        {
            var data = "{\"username\":\"" + Crypto.Encrypt(UsernameTxt.Text) + "\",\"password\":\"" +
                       Crypto.Encrypt(PasswordTxt.Password) + "\"}";
            const string controller = "user";

            try
            {
                var ans        = RestClient.MakePostRequest(controller, data);
                var json       = JObject.Parse(ans);
                var loggedUser = json.ToObject <UserData>();

                if (loggedUser.Message == null)
                {
                    loggedUser.Username = Crypto.Decrypt(loggedUser.Username);
                    loggedUser.Password = Crypto.Decrypt(loggedUser.Password);
                    loggedUser.Email    = Crypto.Decrypt(loggedUser.Email);
                    var main = new MainWindow(loggedUser);
                    Application.Current.MainWindow = main;
                    Close();
                    main.Show();
                }
                else
                {
                    MessageBox.Show(loggedUser.Message, "Error in login", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch
            {
                MessageBox.Show("Server is not found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #3
0
        private void newRoomButton_Click(object sender, RoutedEventArgs e)
        {
            var room = SetRoom();

            if (room == null)
            {
                return;
            }

            var controller = "Room?token=" + LoggedUser.token;

            room.CreatorUserName = Crypto.Encrypt(room.CreatorUserName);
            var data = new JavaScriptSerializer().Serialize(room);

            try
            {
                var ans       = RestClient.MakePostRequest(controller, data);
                var json      = JObject.Parse(ans);
                var roomState = json.ToObject <RoomState>();
                if (roomState.Messege == null)
                {
                    var chip = (int)chipsLabel.Content;
                    if (room.ChipPolicy != 0)
                    {
                        LoggedUser.Chips = chip - room.ChipPolicy;
                    }
                    else
                    {
                        LoggedUser.Chips = 0;
                    }
                    RoomNameTxt.Text = "";
                    var gameWindow = new GameWindow(LoggedUser, LoggedUser.Username, roomState, this, null);
                    OpenWindows.Add(gameWindow);
                    Application.Current.MainWindow = gameWindow;
                    gameWindow.Show();
                }
                else
                {
                    MessageBox.Show(roomState.Messege, "Error in creation", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch
            {
                HandleCrashing();
            }
        }
Пример #4
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            var filter = SetFilter();

            if (filter == null)
            {
                return;
            }

            var controller = "Search?token=" + LoggedUser.token;

            filter.User = Crypto.Encrypt(filter.User);
            var data = new JavaScriptSerializer().Serialize(filter);

            try
            {
                var ans      = RestClient.MakePostRequest(controller, data);
                var json     = JObject.Parse(ans);
                var roomList = json.ToObject <RoomList>();
                if (roomList.Message == null)
                {
                    RoomResults           = roomList.Rooms.ToList();
                    RoomsGrid.ItemsSource = RoomResults;
                    RoomsGrid.Items.Refresh();
                }
                else
                {
                    MessageBox.Show("No rooms to show!", "No results", MessageBoxButton.OK, MessageBoxImage.Information);
                    RoomResults.Clear();
                    RoomsGrid.ItemsSource = RoomResults;
                    RoomsGrid.Items.Refresh();
                }
            }
            catch
            {
                HandleCrashing();
            }
        }