sharee.bike-App/SharedBusinessLogic/ViewModel/MiniSurvey/Question/CheckOneViewModel.cs

46 lines
1.6 KiB
C#
Raw Normal View History

2021-08-01 17:24:15 +02:00
using System.Collections.Generic;
using System.Linq;
2024-04-09 12:53:23 +02:00
namespace ShareeBike.ViewModel.MiniSurvey.Question
2021-08-01 17:24:15 +02:00
{
2022-09-06 16:08:19 +02:00
public class CheckOneViewModel : IMiniSurveyQuestion
{
/// <summary> Constructs object. </summary>
/// <param name="question">Holds the question with key asked to user.</param>
/// <param name="answers">Holds the list of possible answers with their option keys.</param>
public CheckOneViewModel(
KeyValuePair<string, string> question,
Dictionary<string, string> answers)
{
Question = question;
Answers = answers ?? new Dictionary<string, string>();
}
2021-08-01 17:24:15 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the question with key asked to user. </summary>
public KeyValuePair<string, string> Question { get; }
2021-08-01 17:24:15 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the question with key asked to user exposed to GUI. </summary>
public string QuestionText => Question.Value;
2021-08-01 17:24:15 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the list of possible answers with their option keys. </summary>
public Dictionary<string, string> Answers { get; }
2021-08-01 17:24:15 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the list of possible answers exposed to GUI. </summary>
public IEnumerable<string> AnswersText
{
get => Answers.Select(x => x.Value).ToList();
set => AnswersText = Answers.Select(x => x.Value).ToList();
}
2021-08-01 17:24:15 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the users selected answer (one of answers) with its option key. </summary>
public KeyValuePair<string, string> Answer { get; private set; }
2021-08-01 17:24:15 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the users selected answer (one of answers) in GUI. </summary>
public string AnswerText
{
get => Answer.Value;
set => Answer = Answers.FirstOrDefault(x => x.Value == value);
}
}
2021-08-01 17:24:15 +02:00
}