2022-08-30 15:42:25 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using TINK.Model.MiniSurvey;
|
|
|
|
|
using TINK.Repository.Response;
|
|
|
|
|
|
|
|
|
|
namespace TINK.Model.Connector.Updater
|
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
|
public static class BookingFinishedModelFactory
|
|
|
|
|
{
|
|
|
|
|
/// <summary> Creates a booking finished object from response.</summary>
|
|
|
|
|
/// <param name="response">Response to create survey object from.</param>
|
|
|
|
|
public static BookingFinishedModel Create(this DoReturnResponse response)
|
|
|
|
|
{
|
|
|
|
|
var bookingFinished = new BookingFinishedModel
|
|
|
|
|
{
|
|
|
|
|
Co2Saving = response?.co2saving
|
|
|
|
|
};
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
if (response?.user_miniquery == null)
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
{
|
|
|
|
|
return bookingFinished;
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
var miniquery = response.user_miniquery;
|
|
|
|
|
bookingFinished.MiniSurvey = new MiniSurveyModel
|
|
|
|
|
{
|
|
|
|
|
Title = miniquery.title,
|
|
|
|
|
Subtitle = miniquery.subtitle,
|
|
|
|
|
Footer = miniquery.footer
|
|
|
|
|
};
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
foreach (var question in miniquery?.questions?.OrderBy(x => x.Key) ?? new Dictionary<string, MiniSurveyResponse.Question>().OrderBy(x => x.Key))
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(question.Key.Trim())
|
|
|
|
|
|| question.Value.query == null)
|
|
|
|
|
{
|
|
|
|
|
// Skip invalid entries.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
bookingFinished.MiniSurvey.Questions.Add(
|
|
|
|
|
question.Key,
|
|
|
|
|
new QuestionModel());
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
return bookingFinished;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
}
|