public static UserFormSubmission WithDefaults(UserFormSubmission partialSubmission, UserPrompt prompt)
 {
     partialSubmission ??= new UserFormSubmission();
     partialSubmission.SubForms ??= prompt.SubPrompts?.Select <SubPrompt, UserSubForm>(_ => null).ToList();
     return(new UserFormSubmission()
     {
         Id = prompt.Id,
         SubForms = (prompt.SubPrompts == null) ? null : partialSubmission.SubForms.Zip(prompt.SubPrompts)
                    .Select <(UserSubForm, SubPrompt), UserSubForm>(
             (tuple) => UserSubForm.WithDefaults(tuple.Item1, tuple.Item2)).ToList()
     });
Exemplo n.º 2
0
 public static UserSubForm WithDefaults(UserSubForm partialSubmission, SubPrompt prompt)
 {
     if (prompt == null)
     {
         throw new ArgumentNullException($"prompt was null");
     }
     // TODO: default to selecting random choice.
     return(new UserSubForm()
     {
         Id = prompt.Id,
         ShortAnswer = prompt.ShortAnswer ? (partialSubmission?.ShortAnswer ?? "N/A") : null,
         Drawing = (prompt.Drawing != null) ? (partialSubmission?.Drawing ?? Constants.Drawings.DefaultDrawing(prompt.Drawing.DrawingType)) : null,
         Selector = (prompt.Selector != null) ? (partialSubmission?.Selector ?? (int?)0) : null,
         Slider = (prompt.Slider != null) ? (partialSubmission?.Slider ?? (prompt.Slider.Range ? new List <int> {
             prompt.Slider.Min, prompt.Slider.Max
         } : new List <int> {
             prompt.Slider.Min
         })): null,
         DropdownChoice = (prompt.Dropdown != null) ? (partialSubmission?.DropdownChoice ?? (int?)0): null,
         RadioAnswer = (prompt.Answers != null) ? (partialSubmission?.RadioAnswer ?? (int?)0) : null,
         Color = prompt.ColorPicker ? (partialSubmission?.Color ?? Constants.Colors.DarkGray) : null,
     });
 }