コード例 #1
0
        private void BtnAdmin_Click(object sender, RoutedEventArgs e)
        {
            if (_isGame)
            {
                MessageBox.Show("At first you must end the game!");
                return;
            }
            this.Hide();
            AdminWindow admin = new AdminWindow(_hostUrl);

            admin.Owner = this;
            admin.ShowDialog();

            if (MainWindow.playerLogin == "none" && MainWindow.playerPassword == "none")
            {
                this.Close();
                return;
            }

            requestUrl     = _hostUrl + $"/api/jsstudygame/login?emailOrLogin={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _player        = ServerWorker.GetInfoFromServer <PlayerVM>(requestUrl);
            requestUrl     = _hostUrl + $"/api/jsstudygame/addinfo?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _playerAddInfo = ServerWorker.GetInfoFromServer <PlayerAdditionalInfoVM>(requestUrl);

            requestUrl   = _hostUrl + $"/api/jsstudygame/score?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _playerScore = ServerWorker.GetInfoFromServer <PlayerScoreVM>(requestUrl);
            _playerScore.IdPlayerScore = _player.Id;

            this.ShowDialog();
        }
コード例 #2
0
        public IActionResult GetPlayerAddInfo(string login, string password)
        {
            PlayerAdditionalInfoVM playerAddInfoVM = new PlayerAdditionalInfoVM()
            {
                IdPlayerAdditionalInfo = 0,
                Name      = "none",
                Surname   = "none",
                Photo     = "none",
                BirthDate = DateTime.Now,
                Gender    = true
            };

            var playerBasic = _context.Players.SingleOrDefault(p => p.Login == login && p.Password == password);

            if (playerBasic == null)
            {
                return(Ok(playerAddInfoVM));
            }

            var playerAddInfo = _context.PlayersAdditionalInfo.SingleOrDefault(p => p.IdPlayerAdditionalInfo == playerBasic.Id);

            if (playerAddInfo == null)
            {
                return(Ok(playerAddInfoVM));
            }

            playerAddInfoVM.IdPlayerAdditionalInfo = playerAddInfo.IdPlayerAdditionalInfo;
            playerAddInfoVM.Name      = playerAddInfo.Name;
            playerAddInfoVM.Surname   = playerAddInfo.Surname;
            playerAddInfoVM.Gender    = playerAddInfo.Gender;
            playerAddInfoVM.Photo     = playerAddInfo.Photo;
            playerAddInfoVM.BirthDate = playerAddInfo.BirthDate;

            return(Ok(playerAddInfoVM));
        }
コード例 #3
0
 public ProfileWindow(string hostUrl)
 {
     _hostUrl        = hostUrl;
     playerVM        = new PlayerVM();
     playerAddInfoVM = new PlayerAdditionalInfoVM();
     scoreVM         = new PlayerScoreVM();
     InitializeComponent();
 }
コード例 #4
0
        public RegistrationWindow(string hostUrl)
        {
            playerBasicInfo = new PlayerVM();
            playerAddInfo   = new PlayerAdditionalInfoVM();
            random          = new Random();
            _hostUrl        = hostUrl;

            InitializeComponent();
        }
コード例 #5
0
        public IActionResult ChangePlayerAdditionalInfo([FromBody] PlayerAdditionalInfoVM model)
        {
            if (model == null || model.IdPlayerAdditionalInfo <= 0)
            {
                return(Ok(0));
            }
            PlayerAdditionalInfo player = _context.PlayersAdditionalInfo.SingleOrDefault(p => p.IdPlayerAdditionalInfo == model.IdPlayerAdditionalInfo);

            if (player == null)
            {
                return(CreatePlayerAdditionalInfo(model));
            }
            else
            {
                try
                {
                    string imageName;
                    if (!string.IsNullOrWhiteSpace(model.Photo))
                    {
                        string fileDestDir = _env.ContentRootPath;
                        fileDestDir = Path.Combine(fileDestDir, "Photos");

                        imageName = Path.GetRandomFileName() + ".jpg";
                        var bitmap = model.Photo.FromBase64StringToImage();
                        bitmap.Save(Path.Combine(fileDestDir, imageName), ImageFormat.Jpeg);

                        if (player.Photo != "stepanPhoto.jpg" && System.IO.File.Exists(Path.Combine(fileDestDir, player.Photo)))
                        {
                            // If file found, delete it
                            System.IO.File.Delete(Path.Combine(fileDestDir, player.Photo));
                        }
                    }
                    else
                    {
                        imageName = player.Photo;
                    }

                    player.Name      = model.Name;
                    player.Surname   = model.Surname;
                    player.Photo     = imageName;
                    player.BirthDate = model.BirthDate;
                    player.Gender    = model.Gender;
                    _context.SaveChanges();
                }
                catch (Exception) { return(Ok(0)); }

                return(Ok(player.IdPlayerAdditionalInfo));
            }
        }
コード例 #6
0
 private void BtnLogout_Click(object sender, RoutedEventArgs e)
 {
     if (_isGame)
     {
         MessageBox.Show("At first you must end the game!");
         return;
     }
     MainWindow.playerLogin    = "******";
     MainWindow.playerPassword = "******";
     _isGame        = false;
     _player        = null;
     _playerAddInfo = null;
     _playerScore   = null;
     _isAnswer      = false;
     requestUrl     = _hostUrl + $"/api/jsstudygame/score";
     ServerWorker.ChangePlayerToServer(_playerScore, requestUrl);
     this.Close();
 }
コード例 #7
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string requestUrl = null;

            requestUrl                   = _hostUrl + $"/api/jsstudygame/login?emailOrLogin={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            playerVM                     = ServerWorker.GetInfoFromServer <PlayerVM>(requestUrl);
            txtLogin.Text                = playerVM.Login;
            txtLogin.IsReadOnly          = true;
            txtEmail.Text                = playerVM.Email;
            txtEmail.IsReadOnly          = true;
            txtEmail.Text                = playerVM.Email;
            txtPasswordOne.Password      = playerVM.Password;
            txtPasswordOne.IsEnabled     = false;
            txtPasswordOneTxt.Text       = playerVM.Password;
            txtPasswordOneTxt.IsReadOnly = true;

            txtPasswordTwo.Password      = playerVM.Password;
            txtPasswordTwoTxt.Text       = playerVM.Password;
            txtPasswordTwoTxt.IsReadOnly = true;

            requestUrl      = _hostUrl + $"/api/jsstudygame/addinfo?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            playerAddInfoVM = ServerWorker.GetInfoFromServer <PlayerAdditionalInfoVM>(requestUrl);

            txtName.Text          = playerAddInfoVM.Name;
            txtName.IsReadOnly    = true;
            txtSurname.Text       = playerAddInfoVM.Surname;
            txtSurname.IsReadOnly = true;

            dateChoose.SelectedDate = playerAddInfoVM.BirthDate;
            if (playerAddInfoVM.Gender == true)
            {
                radioBtnMale.IsChecked    = true;
                radioBtnFemale.Visibility = Visibility.Hidden;
            }
            else
            {
                radioBtnFemale.IsChecked = true;
                radioBtnMale.Visibility  = Visibility.Hidden;
            }

            ImgPhotoAndPicture_Loaded(sender, e);
        }
コード例 #8
0
        public IActionResult CreatePlayerAdditionalInfo([FromBody] PlayerAdditionalInfoVM model)
        {
            if (model == null)
            {
                return(Ok(0));
            }
            PlayerAdditionalInfo player;

            try
            {
                string imageName = "none";
                if (!string.IsNullOrWhiteSpace(model.Photo))
                {
                    string fileDestDir = _env.ContentRootPath;
                    fileDestDir = Path.Combine(fileDestDir, "Photos");
                    imageName   = Path.GetRandomFileName() + ".jpg";
                    var bitmap = model.Photo.FromBase64StringToImage();
                    bitmap.Save(Path.Combine(fileDestDir, imageName), ImageFormat.Jpeg);
                }
                player = new PlayerAdditionalInfo()
                {
                    IdPlayerAdditionalInfo = model.IdPlayerAdditionalInfo,
                    Name      = model.Name,
                    Surname   = model.Surname,
                    Photo     = imageName,
                    BirthDate = model.BirthDate,
                    Gender    = model.Gender
                };

                _context.PlayersAdditionalInfo.Add(player);
                _context.SaveChanges();
            }
            catch (Exception) { return(Ok(0)); }

            return(Ok(player.IdPlayerAdditionalInfo));
        }
コード例 #9
0
        public MainWindow(string hostUrl)
        {
            _hostUrl = hostUrl;
            InitializeComponent();

            requestUrl                 = _hostUrl + $"/api/jsstudygame/login?emailOrLogin={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _player                    = ServerWorker.GetInfoFromServer <PlayerVM>(requestUrl);
            requestUrl                 = _hostUrl + $"/api/jsstudygame/addinfo?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _playerAddInfo             = ServerWorker.GetInfoFromServer <PlayerAdditionalInfoVM>(requestUrl);
            requestUrl                 = _hostUrl + $"/api/jsstudygame/score?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _playerScore               = ServerWorker.GetInfoFromServer <PlayerScoreVM>(requestUrl);
            _playerScore.IdPlayerScore = _player.Id;

            requestUrl     = _hostUrl + $"/api/jsstudygame/amountoftests?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _amountoftests = ServerWorker.GetInfoFromServer <int>(requestUrl);
            if (_amountoftests == 0)
            {
                _amountoftests = 1;
            }

            if (_player.IsAdmin)
            {
                btnAdmin.Visibility = Visibility.Visible;
            }

            spStartGame.Visibility  = Visibility.Hidden;
            btnReference.Visibility = Visibility.Hidden;

            _skippedAnswer = new List <string>();
            _wrongAnswer   = new List <string>();
            if (!string.IsNullOrWhiteSpace(_playerScore.AnswersSkipped))
            {
                _skippedAnswer = _playerScore.AnswersSkipped.Split(',').ToList();
                if (_skippedAnswer != null)
                {
                    _skippedAnswer.Sort();
                }
                foreach (var item in _skippedAnswer)
                {
                    cbSkipped.Items.Add($"<<  {item}  >>");
                }
            }
            if (!string.IsNullOrWhiteSpace(_playerScore.AnswersWrong))
            {
                _wrongAnswer = _playerScore.AnswersWrong.Split(',').ToList();
                if (_wrongAnswer != null)
                {
                    _wrongAnswer.Sort();
                }

                foreach (var item in _wrongAnswer)
                {
                    cbWrong.Items.Add($"<<  {item}  >>");
                }
            }
            _stopwatch = new Stopwatch();
            Task.Run(() =>
            {
                string imgPathStr = _hostUrl + $"/images/jsImg2.jpg";
                Uri resourceUri   = new Uri(imgPathStr, UriKind.Absolute);
                this.Dispatcher.Invoke(() =>
                {
                    backgroundImg.ImageSource = new BitmapImage(resourceUri);
                });
            });
        }