private static void MapItems(IContainItems itemContainer, IContainItemDefinitions itemDefinitionContainer, AssessmentInstance assessmentInstance)
        {
            foreach (var itemDefinition in itemDefinitionContainer.ItemDefinitions)
            {
                if (itemDefinition.ItemType == ItemType.Question)
                {
                    itemContainer.Items.Add(CreateQuestion(itemDefinition, assessmentInstance));
                }
                else if (itemDefinition.ItemType == ItemType.Group)
                {
                    var groupItemDto = new ItemDto
                    {
                        Metadata           = itemDefinition.ItemMetadata,
                        Key                = assessmentInstance.Key,
                        ItemDefinitionCode = itemDefinition.CodedConcept.Code,
                        ItemDefinitionName = itemDefinition.CodedConcept.Name,
                        Items              = new List <ItemDto>(),
                        ItemType           = itemDefinition.ItemType.CodedConcept.Code
                    };

                    MapItems(groupItemDto, itemDefinition, assessmentInstance);

                    itemContainer.Items.Add(groupItemDto);
                }
            }
        }
Example #2
0
 private static ItemDto GetItemDtoByCode(IContainItems sectionDto, string code)
 {
     foreach (var itemDto in sectionDto.Items)
     {
         if (itemDto.ItemDefinitionCode == code && itemDto.ItemType == ItemType.Question.CodedConcept.Code)
         {
             return(itemDto);
         }
         if (itemDto.Items != null)
         {
             foreach (
                 var childItemDto in
                 itemDto.Items.Where(childItemDto => childItemDto.ItemDefinitionCode == code && childItemDto.ItemType == ItemType.Question.CodedConcept.Code))
             {
                 return(childItemDto);
             }
             foreach (var containerDto in itemDto.Items.Where(i => i.ItemType != ItemType.Question.CodedConcept.Code).OfType <IContainItems> ())
             {
                 var childItem = GetItemDtoByCode(containerDto, code);
                 if (childItem != null)
                 {
                     return(childItem);
                 }
             }
         }
     }
     return(null);
 }
Example #3
0
 /// <summary>
 ///     Gets the items to render.
 /// </summary>
 /// <param name="html">The HTML.</param>
 /// <returns>
 ///     List of <see cref="ItemDto" /> to render.
 /// </returns>
 public static IEnumerable <ItemDto> GetItemsToRender(this HtmlHelper html, IContainItems itemContainer)
 {
     return
         (itemContainer.Items.Where(item => item.Metadata == null || !item.Metadata.MetadataItemExists <HiddenMetadataItem>(mi => mi.IsHidden))
          .OrderBy(item =>
     {
         var metaItem = item.Metadata == null ? null : item.Metadata.FindMetadataItem <DisplayOrderMetadataItem>();
         return metaItem == null ? 0 : metaItem.Order;
     }));
 }