예제 #1
0
        protected void LoadNextQuestion()
        {
            var nextQuestionResponse = _triviaApp.NextQuestion();

            if (nextQuestionResponse.Success)
            {
                _question = nextQuestionResponse.Data;
                this.entryQuestion.Text = _question.Question;

                _answers = _question.GetAnswers();
                foreach (AnswerDTO answer in _answers)
                {
                    this.cbbAnswers.AppendText(answer.Answer);
                }
            }
            else
            {
                if (ResponseCode.NoContent == nextQuestionResponse.Code)
                {
                    var sessionResultResponse = this._triviaApp.FinishSession();
                    if (sessionResultResponse.Success)
                    {
                        ModalMessage.Info(this, sessionResultResponse.Message);
                    }
                    else
                    {
                        ModalMessage.Error(this, sessionResultResponse.Message);
                    }
                }
                this._answerTimer.Stop();
                this._answerTimer.Dispose();
                this.Hide();
            }
        }
예제 #2
0
        /// <summary>
        /// Load questions sets into cbbQuestionsSets
        /// </summary>
        protected void LoadQuestionsSets()
        {
            var response = _triviaApp.GetQuestionsSets();

            if (response.Success)
            {
                _questionsSets = response.Data;

                ListStore store = new ListStore(typeof(string));
                this.cbbQuestionsSets.Model = store;

                foreach (var questionsSet in _questionsSets)
                {
                    this.cbbQuestionsSets.AppendText(questionsSet.Name);
                }
                if (_questionsSets.Any())
                {
                    cbbQuestionsSets.Active         = DEFAULT_QUESTIONS_SET_IDX;
                    _triviaApp.SelectedQuestionsSet = _questionsSets.ElementAt(DEFAULT_QUESTIONS_SET_IDX);
                }
            }
            else
            {
                ModalMessage.Error(this, response.Message);
            }
        }
예제 #3
0
        protected void Answer()
        {
            this._answerTimer.Stop();
            this._answerTimer.Dispose();

            var answers = new List <AnswerDTO>();

            if (cbbAnswers.Active >= 0)
            {
                answers.Add(_answers.ElementAt(cbbAnswers.Active));
            }
            var response = this._triviaApp.AddAnswer(_question, answers);

            if (response.Success)
            {
                var answerResult = response.Data;
                if (answerResult.IsCorrect)
                {
                    ModalMessage.Info(this, response.Message);
                }
                else
                {
                    ModalMessage.Error(this, $"{response.Message}. Correct Answer: {response.Data.GetCorrectAnswers()}");
                }
                new SessionDialog(_triviaApp).Show();
                this.Hide();
            }
            else
            {
                ModalMessage.Error(this, response.Message);
            }
        }
예제 #4
0
 public MainWindow(TriviaApp pTriviaApp) : base(Gtk.WindowType.Toplevel)
 {
     this._triviaApp = pTriviaApp;
     if (_triviaApp.LoggedUser == null)
     {
         this.Hide();
         ModalMessage.Error(this, "Permission denied");
     }
     this.Build();
     this.lblUsername.Text    = _triviaApp.LoggedUser.Username;
     this.btnSettings.Visible = _triviaApp.LoggedUser.IsAdmin;
     this.LoadQuestionsSets();
 }
예제 #5
0
        /// <summary>
        /// Event triggered when user clicks on LogIn button.
        /// Makes the login for the entered Username and Password
        /// </summary>
        protected void OnClickLogIn(object sender, EventArgs e)
        {
            var response = _triviaApp.Login(this.entUsername.Text, this.entPassword.Text);

            if (response.Success)
            {
                this.Hide();
                new MainWindow(_triviaApp).Show();
            }
            else
            {
                ModalMessage.Error(this, response.Message);
            }
        }
예제 #6
0
        protected void OnEntExpectedAnswerTimeChanged(object sender, EventArgs e)
        {
            if (entExpectedAnswerTime.Text.Length == 0)
            {
                return;
            }
            bool parseIntSuccess = int.TryParse(this.entExpectedAnswerTime.Text, out int expectedAnswerTimeValue);

            if (!parseIntSuccess)
            {
                this.entExpectedAnswerTime.Text = this._triviaApp.SelectedQuestionsSet.ExpectedAnswerTime.ToString();
                ModalMessage.Error(this, "Invalid number");
            }
        }
예제 #7
0
        protected void OnBtnConfirmClicked(object sender, EventArgs e)
        {
            var response = _triviaApp.SignUp(this.entUsername.Text, this.entPassword.Text, this.entConfirmPassword.Text);

            if (response.Success)
            {
                ModalMessage.Info(this, Gtk.ButtonsType.Ok, response.Message);
                this.Hide();
            }
            else
            {
                ModalMessage.Error(this, response.Message);
            }
        }
예제 #8
0
        protected void OnBtnUpdateDataClicked(object sender, EventArgs e)
        {
            this.lblLoading.Visible = true;
            var response = this._triviaApp.UpdateQuestionsSetData();

            if (response.Success)
            {
                this.lblLoading.Visible = false;
                ModalMessage.Info(this, Gtk.ButtonsType.Ok, response.Message);
            }
            else
            {
                ModalMessage.Error(this, response.Message);
            }
        }
예제 #9
0
        protected void OnBtnSaveClicked(object sender, EventArgs e)
        {
            int oldExpectedAnswerTime = this._triviaApp.SelectedQuestionsSet.ExpectedAnswerTime;

            this._triviaApp.SelectedQuestionsSet.ExpectedAnswerTime = int.Parse(this.entExpectedAnswerTime.Text);
            var response = this._triviaApp.SaveQuestionsSet();

            if (response.Success)
            {
                ModalMessage.Info(this, Gtk.ButtonsType.Ok, response.Message);
                this.Hide();
            }
            else
            {
                ModalMessage.Error(this, response.Message);
            }
        }
예제 #10
0
        protected void OnButtonOkClicked(object sender, EventArgs e)
        {
            var category        = _triviaApp.SelectedQuestionsSet.Categories.ElementAt(cbbCategories.Active);
            var level           = _triviaApp.SelectedQuestionsSet.Levels.ElementAt(cbbLevels.Active);
            var questionsNumber = _possiblesQuestionsNumber.ElementAt(cbbQuestionsNumber.Active);

            var response = _triviaApp.StartNewSession(category, level, questionsNumber);

            if (response.Success)
            {
                _triviaApp.CurrentSession = response.Data;
                new SessionDialog(_triviaApp).Show();
                this.Hide();
            }
            else
            {
                ModalMessage.Error(this, response.Message);
            }
        }
예제 #11
0
        protected void LoadData()
        {
            var response = _triviaApp.ShowRanking();

            if (response.Success)
            {
                var rankingListStore = new ListStore(typeof(string), typeof(string), typeof(string), typeof(string));
                var ranking          = response.Data;
                foreach (var sessionResult in ranking)
                {
                    rankingListStore.AppendValues(sessionResult.Username, sessionResult.Score.ToString(), sessionResult.Time.ToString(), sessionResult.Date.ToString());
                }
                this.treeviewRanking.Model = rankingListStore;
            }
            else
            {
                ModalMessage.Error(this, response.Message);
            }
        }