1010using System . Web . Http ;
1111using eFormAPI . Common . API ;
1212using eFormAPI . Common . Models ;
13+ using eFormAPI . Common . Models . Templates ;
1314using eFormAPI . Web . Infrastructure . Helpers ;
1415using eFormCore ;
1516using eFormShared ;
@@ -20,30 +21,38 @@ namespace eFormAPI.Web.Controllers
2021 public class TemplatesController : ApiController
2122 {
2223 private readonly EFormCoreHelper _coreHelper = new EFormCoreHelper ( ) ;
23-
24- [ HttpGet ]
25- public OperationDataResult < List < Template_Dto > > Index ( )
24+
25+ [ HttpPost ]
26+ public OperationDataResult < TemplateListModel > Index ( TemplateRequestModel templateRequestModel )
2627 {
2728 try
2829 {
2930 try
3031 {
3132 var core = _coreHelper . GetCore ( ) ;
3233 var templatesDto = core . TemplateItemReadAll ( false ) ;
33- return new OperationDataResult < List < Template_Dto > > ( true , templatesDto ) ;
34+
35+ var model = new TemplateListModel
36+ {
37+ NumOfElements = 40 ,
38+ PageNum = templateRequestModel . PageIndex ,
39+ Templates = templatesDto
40+ } ;
41+
42+
43+ return new OperationDataResult < TemplateListModel > ( true , model ) ;
3444 }
3545 catch ( Exception ex )
3646 {
3747 if ( ex . Message . Contains ( "PrimeDb" ) )
3848 {
39- var lines =
40- System . IO . File . ReadAllLines (
49+ var lines = File . ReadAllLines (
4150 System . Web . Hosting . HostingEnvironment . MapPath ( "~/bin/Input.txt" ) ) ;
4251
4352 var connectionStr = lines . First ( ) ;
4453 var adminTool = new AdminTools ( connectionStr ) ;
4554 adminTool . DbSettingsReloadRemote ( ) ;
46- return new OperationDataResult < List < Template_Dto > > ( false , "Check connection string" ) ;
55+ return new OperationDataResult < TemplateListModel > ( false , "Check connection string" ) ;
4756 }
4857 else
4958 {
@@ -55,12 +64,12 @@ public OperationDataResult<List<Template_Dto>> Index()
5564 }
5665 catch ( Exception ex2 )
5766 {
58- return new OperationDataResult < List < Template_Dto > > ( false , "Core is not started." ) ;
67+ return new OperationDataResult < TemplateListModel > ( false , "Core is not started." ) ;
5968 }
60- return new OperationDataResult < List < Template_Dto > > ( false , "Check settings before proceed" ) ;
69+ return new OperationDataResult < TemplateListModel > ( false , "Check settings before proceed" ) ;
6170 }
6271 }
63- return new OperationDataResult < List < Template_Dto > > ( false , "Check settings before proceed" ) ;
72+ return new OperationDataResult < TemplateListModel > ( false , "Check settings before proceed" ) ;
6473 }
6574 }
6675 catch ( Exception )
@@ -243,19 +252,18 @@ public OperationResult Deploy(DeployModel deployModel)
243252 public HttpResponseMessage Csv ( int id )
244253 {
245254 var core = _coreHelper . GetCore ( ) ;
246-
247255 var fileName = $ "{ id } _{ DateTime . Now . Ticks } .csv";
248- System . IO . Directory . CreateDirectory ( System . Web . Hosting . HostingEnvironment . MapPath ( "~/bin/output/" ) ) ;
256+ Directory . CreateDirectory ( System . Web . Hosting . HostingEnvironment . MapPath ( "~/bin/output/" ) ) ;
249257 var filePath = System . Web . Hosting . HostingEnvironment . MapPath ( $ "~/bin/output/{ fileName } ") ;
250258 var fullPath = core . CasesToCsv ( id , null , null , filePath ,
251- $ "{ core . GetHttpServerAddress ( ) } / api/template-files/get-image ?&filename=") ;
259+ $ "{ Request . RequestUri . Scheme } :// { Request . RequestUri . Authority } / api/templates/getimage ?&filename=") ;
252260
253261 var result = new HttpResponseMessage ( HttpStatusCode . OK ) ;
254262 var fileStream = new FileStream ( fullPath , FileMode . Open , FileAccess . Read ) ;
255263
256264 result . Content = new StreamContent ( fileStream ) ;
257- result . Content . Headers . ContentDisposition = new ContentDispositionHeaderValue ( "attachment" ) ;
258- result . Content . Headers . ContentDisposition . FileName = fileName ;
265+ result . Content . Headers . ContentDisposition =
266+ new ContentDispositionHeaderValue ( "attachment" ) { FileName = fileName } ;
259267 result . Content . Headers . ContentType =
260268 new MediaTypeHeaderValue ( "application/octet-stream" ) ;
261269 return result ;
@@ -340,7 +348,7 @@ public HttpResponseMessage GetPdfFile(string fileName)
340348 result . Content . Headers . ContentDisposition =
341349 new ContentDispositionHeaderValue ( "attachment" ) { FileName = fileName } ;
342350 result . Content . Headers . ContentType =
343- new MediaTypeHeaderValue ( $ "application/pdf") ;
351+ new MediaTypeHeaderValue ( "application/pdf" ) ;
344352 return result ;
345353 }
346354
@@ -365,7 +373,7 @@ public HttpResponseMessage DownloadEFormPDF(int templateId)
365373 result . Content . Headers . ContentDisposition =
366374 new ContentDispositionHeaderValue ( "attachment" ) { FileName = "" } ; // TODO: FIX
367375 result . Content . Headers . ContentType =
368- new MediaTypeHeaderValue ( $ "application/pdf") ;
376+ new MediaTypeHeaderValue ( "application/pdf" ) ;
369377 return result ;
370378 }
371379 catch ( Exception )
@@ -397,7 +405,7 @@ public HttpResponseMessage DownloadEFormXML(int templateId)
397405 result . Content . Headers . ContentDisposition =
398406 new ContentDispositionHeaderValue ( "attachment" ) { FileName = "" } ; // TODO: FIX
399407 result . Content . Headers . ContentType =
400- new MediaTypeHeaderValue ( $ "application/pdf") ;
408+ new MediaTypeHeaderValue ( "application/pdf" ) ;
401409 return result ;
402410 }
403411 catch ( Exception )
0 commit comments