public Form ToForm() { var formId = Guid.NewGuid(); var sections = SectionRules?.Select(sr => sr.ToSection(formId)).ToList(); Dictionary <Guid, Guid> mapQuestions = new Dictionary <Guid, Guid>(); List <FormItem> items = new List <FormItem>(); Questions?.ForEach((question) => { FormItem item = question.ToFormItem(formId, sections); mapQuestions.Add(question.Id, item.Id); items.Add(item); }); sections.ForEach((section) => { if (section.VisibleCondition != null) { FormFilterCondition.MapVisibleConditionQuestionToItemId(section.VisibleCondition, mapQuestions); } }); items.ForEach((item) => { if (item.VisibleCondition != null) { FormFilterCondition.MapVisibleConditionQuestionToItemId(item.VisibleCondition, mapQuestions); } }); return(new Form { Id = formId, TemplateId = Id, Subject = Subject, MustDisplayElementsCode = MustDisplayElementsCode, Type = Type, Language = Language, Sections = sections, Items = items, IsSignatureAllowed = IsSignatureAllowed, }); }
public FormItem ToFormItem(Guid formId, List <FormSection> sections) { FormSection section = sections.Find(x => x.SectionRuleId == SectionRuleId); var formItem = new FormItem { FormId = formId, Template = Template, SectionId = section.Id, QuestionId = Id, DisplayOrder = DisplayOrder, Title = Title, ItemType = ItemType, Description = Description, Code = Code, VisibleCondition = VisibleCondition == null ? null : VisibleCondition.Copy(), ConformityRules = ConformityRules, AllowAttachComment = AllowAttachComment, AllowAttachPicture = AllowAttachPicture, }; return(formItem); }