@@ -21,6 +21,8 @@ namespace DocuSign.CodeExamples.WebForms.Controllers
2121 [ Route ( "web001" ) ]
2222 public class CreateAndEmbedForm : EgController
2323 {
24+ public const string TemplateName = "Web Form Example Template" ;
25+
2426 private IConfiguration configuration ;
2527
2628 public CreateAndEmbedForm (
@@ -31,7 +33,7 @@ public CreateAndEmbedForm(
3133 : base ( config , launcherTexts , requestItemsService )
3234 {
3335 this . configuration = configuration ;
34- this . CodeExampleText = this . GetExampleText ( this . EgName , ExamplesApiType . Connect ) ;
36+ this . CodeExampleText = this . GetExampleText ( this . EgName , ExamplesApiType . WebForms ) ;
3537 this . ViewBag . title = this . CodeExampleText . ExampleName ;
3638 }
3739
@@ -49,13 +51,18 @@ public ActionResult CheckTheTemplates()
4951 var docuSignClient = new DocuSignClient ( basePath ) ;
5052 docuSignClient . Configuration . DefaultHeader . Add ( "Authorization" , "Bearer " + accessToken ) ;
5153
52- List < EnvelopeTemplate > templates = CreateAndEmbedFormService . CheckIfTemplateExists ( docuSignClient , accountId ) ;
54+ List < EnvelopeTemplate > templates = CreateAndEmbedFormService . CheckIfTemplateExists (
55+ docuSignClient ,
56+ accountId ,
57+ TemplateName ) ;
58+
5359 if ( templates == null || templates . Count == 0 )
5460 {
55- var template = CreateAndEmbedFormService . CreateTemplate (
61+ TemplateSummary template = CreateAndEmbedFormService . CreateTemplate (
5662 docuSignClient ,
5763 accountId ,
58- this . Config . DocumentTemplatePdf ) ;
64+ this . Config . DocumentTemplatePdf ,
65+ TemplateName ) ;
5966
6067 this . RequestItemsService . WebFormsTemplateId = template . TemplateId ;
6168 }
@@ -68,6 +75,10 @@ public ActionResult CheckTheTemplates()
6875 this . Config . WebFormConfig ,
6976 this . RequestItemsService . WebFormsTemplateId ) ;
7077
78+ this . ViewBag . CodeExampleText = this . CodeExampleText ;
79+ this . ViewBag . Description = this . CodeExampleText . AdditionalPages
80+ . First ( x => x . Name == "create_web_form" ) . ResultsPageText ;
81+
7182 return this . View ( "embedForm" ) ;
7283 }
7384
@@ -76,7 +87,7 @@ public ActionResult CheckTheTemplates()
7687 [ Route ( "EmbedForm" ) ]
7788 [ HttpPost ]
7889 [ ValidateAntiForgeryToken ]
79- public ActionResult EmbedForm ( string formId )
90+ public ActionResult EmbedForm ( )
8091 {
8192 string basePath = this . RequestItemsService . Session . WebFormsBasePath ;
8293 string accessToken = this . RequestItemsService . User . AccessToken ;
@@ -85,6 +96,20 @@ public ActionResult EmbedForm(string formId)
8596 var docuSignClient = new DocuSign . WebForms . Client . DocuSignClient ( basePath ) ;
8697 docuSignClient . Configuration . DefaultHeader . Add ( "Authorization" , "Bearer " + accessToken ) ;
8798
99+ WebFormSummaryList forms = CreateAndEmbedFormService . GetForms (
100+ docuSignClient ,
101+ Guid . Parse ( accountId ) ) ;
102+
103+ if ( forms . Items == null || forms . Items . Count == 0 )
104+ {
105+ this . ViewBag . CodeExampleText = this . CodeExampleText ;
106+ this . ViewBag . Description = this . CodeExampleText . AdditionalPages
107+ . First ( x => x . Name == "create_web_form" ) . ResultsPageText ;
108+
109+ return this . View ( "embedForm" ) ;
110+ }
111+
112+ Guid ? formId = forms . Items . First ( x => x . FormProperties . Name == TemplateName ) . Id ;
88113 WebFormInstance form = CreateAndEmbedFormService . CreateInstance (
89114 docuSignClient ,
90115 Guid . Parse ( accountId ) ,
0 commit comments