78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Päevaküsimus.Models;
|
|
|
|
namespace Päevaküsimus
|
|
{
|
|
public class MainWindowVM : NotificationBase
|
|
{
|
|
public ObservableCollection<Question> questions { get; set; }
|
|
private Question _seleceQuestion;
|
|
public Question selectedQuestion {
|
|
get { return _seleceQuestion;}
|
|
set
|
|
{
|
|
_seleceQuestion = value;
|
|
NotifyPropertyChanged();
|
|
}
|
|
}
|
|
|
|
private Question _dayQuestion;
|
|
public Question dayQuestion
|
|
{
|
|
get { return _dayQuestion; }
|
|
set
|
|
{
|
|
_dayQuestion = value;
|
|
NotifyPropertyChanged();
|
|
}
|
|
}
|
|
|
|
private Random _rnd;
|
|
|
|
public MainWindowVM()
|
|
{
|
|
this._rnd = new Random();
|
|
this.questions = SerializationService.DeSerialize();
|
|
if (this.questions == null)
|
|
{
|
|
this.questions = new ObservableCollection<Question>();
|
|
var question = new Question("Lisa uus küsimus");
|
|
this.questions.Add(question);
|
|
}
|
|
App.mwvm = this;
|
|
}
|
|
|
|
public Question CreateNewQuestion()
|
|
{
|
|
var question = new Question("Ja minu uueks küsimuseks on?");
|
|
question.AddAnswer(new Answer("Õige vastus 1", true));
|
|
foreach (var answer in new[] { "Vale vastus 1", "Vale vastus 2", "Vale vastus 3", "Vale vastus 4" })
|
|
{
|
|
question.AddAnswer(new Answer(answer));
|
|
}
|
|
this.questions.Insert(1, question);
|
|
this.selectedQuestion = question;
|
|
return question;
|
|
}
|
|
|
|
public Question GetQuestionOfTheDay()
|
|
{
|
|
try
|
|
{
|
|
return this.questions.ElementAt(this._rnd.Next(1, this.questions.Count));
|
|
}
|
|
catch (ArgumentOutOfRangeException e)
|
|
{
|
|
return new Question("Palun lisa süsteemi mõni küsimus!");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|