mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using TINK.Model.MiniSurvey;
|
|||
|
using TINK.Repository.Response;
|
|||
|
|
|||
|
namespace TINK.Model.Connector.Updater
|
|||
|
{
|
|||
|
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
|
|||
|
};
|
|||
|
|
|||
|
if (response?.user_miniquery == null)
|
|||
|
|
|||
|
{
|
|||
|
return bookingFinished;
|
|||
|
}
|
|||
|
|
|||
|
var miniquery = response.user_miniquery;
|
|||
|
bookingFinished.MiniSurvey = new MiniSurveyModel
|
|||
|
{
|
|||
|
Title = miniquery.title,
|
|||
|
Subtitle = miniquery.subtitle,
|
|||
|
Footer = miniquery.footer
|
|||
|
};
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
|
|||
|
bookingFinished.MiniSurvey.Questions.Add(
|
|||
|
question.Key,
|
|||
|
new QuestionModel());
|
|||
|
}
|
|||
|
|
|||
|
return bookingFinished;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|