Skip to content

Commit dd0c21c

Browse files
committed
UI fixes and picture functionality added
1 parent 35997d3 commit dd0c21c

File tree

91 files changed

+597
-1856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+597
-1856
lines changed

eFormAPI/eFormAPI/Controllers/TemplatesController.cs

Lines changed: 145 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Drawing;
34
using System.IO;
45
using System.Linq;
56
using System.Net;
@@ -27,20 +28,20 @@ public OperationDataResult<List<Template_Dto>> Index()
2728
{
2829
try
2930
{
30-
Core core = _coreHelper.GetCore();
31+
var core = _coreHelper.GetCore();
3132
var templatesDto = core.TemplateItemReadAll(false);
3233
return new OperationDataResult<List<Template_Dto>>(true, templatesDto);
3334
}
3435
catch (Exception ex)
3536
{
3637
if (ex.Message.Contains("PrimeDb"))
3738
{
38-
string[] lines =
39+
var lines =
3940
System.IO.File.ReadAllLines(
4041
System.Web.Hosting.HostingEnvironment.MapPath("~/bin/Input.txt"));
4142

42-
string connectionStr = lines.First();
43-
AdminTools adminTool = new AdminTools(connectionStr);
43+
var connectionStr = lines.First();
44+
var adminTool = new AdminTools(connectionStr);
4445
adminTool.DbSettingsReloadRemote();
4546
return new OperationDataResult<List<Template_Dto>>(false, "Check connection string");
4647
}
@@ -50,7 +51,7 @@ public OperationDataResult<List<Template_Dto>> Index()
5051
{
5152
try
5253
{
53-
Core core = _coreHelper.GetCore();
54+
var core = _coreHelper.GetCore();
5455
}
5556
catch (Exception ex2)
5657
{
@@ -62,7 +63,55 @@ public OperationDataResult<List<Template_Dto>> Index()
6263
return new OperationDataResult<List<Template_Dto>>(false, "Check settings before proceed");
6364
}
6465
}
65-
catch (Exception exception)
66+
catch (Exception)
67+
{
68+
throw new HttpResponseException(HttpStatusCode.Unauthorized);
69+
}
70+
}
71+
72+
[HttpGet]
73+
public OperationDataResult<Template_Dto> Get(int id)
74+
{
75+
try
76+
{
77+
try
78+
{
79+
var core = _coreHelper.GetCore();
80+
var templateDto = core.TemplateItemRead(id);
81+
return new OperationDataResult<Template_Dto>(true, templateDto);
82+
}
83+
catch (Exception ex)
84+
{
85+
if (ex.Message.Contains("PrimeDb"))
86+
{
87+
var lines =
88+
System.IO.File.ReadAllLines(
89+
System.Web.Hosting.HostingEnvironment.MapPath("~/bin/Input.txt"));
90+
91+
var connectionStr = lines.First();
92+
var adminTool = new AdminTools(connectionStr);
93+
adminTool.DbSettingsReloadRemote();
94+
return new OperationDataResult<Template_Dto>(false, "Check connection string");
95+
}
96+
else
97+
{
98+
if (ex.InnerException.Message.Contains("Cannot open database"))
99+
{
100+
try
101+
{
102+
var core = _coreHelper.GetCore();
103+
}
104+
catch (Exception ex2)
105+
{
106+
return new OperationDataResult<Template_Dto>(false, "Core is not started.");
107+
}
108+
return new OperationDataResult<Template_Dto>(false, "Check settings before proceed");
109+
}
110+
}
111+
return new OperationDataResult<Template_Dto>(false, "Check settings before proceed");
112+
}
113+
}
114+
catch (Exception)
66115
{
67116
throw new HttpResponseException(HttpStatusCode.Unauthorized);
68117
}
@@ -72,12 +121,12 @@ public OperationDataResult<List<Template_Dto>> Index()
72121
[HttpPost]
73122
public OperationResult Create(EFormXmlModel eFormXmlModel)
74123
{
75-
Core core = _coreHelper.GetCore();
124+
var core = _coreHelper.GetCore();
76125

77126
var newTemplate = core.TemplateFromXml(eFormXmlModel.EFormXml);
78127

79128
newTemplate = core.TemplateUploadData(newTemplate);
80-
List<string> errors = core.TemplateValidation(newTemplate);
129+
var errors = core.TemplateValidation(newTemplate);
81130

82131
if (!errors.Any())
83132
{
@@ -87,19 +136,25 @@ public OperationResult Create(EFormXmlModel eFormXmlModel)
87136
return new OperationResult(true, $"eForm \"{newTemplate.Label}\" created successfully");
88137
}
89138

90-
string message = errors.Aggregate("", (current, str) => current + ("<br>" + str));
139+
var message = errors.Aggregate("", (current, str) => current + ("<br>" + str));
91140

92141
return new OperationResult(false, "eForm could not be created!" + message);
93142
}
94143

95144
[HttpGet]
96145
public OperationResult Delete(int id)
97146
{
98-
Core core = _coreHelper.GetCore();
147+
var core = _coreHelper.GetCore();
99148
var templateDto = core.TemplateItemRead(id);
149+
foreach (var siteUId in templateDto.DeployedSites)
150+
{
151+
core.CaseDelete(templateDto.Id, siteUId.SiteUId);
152+
}
153+
var result = core.TemplateDelete(id);
154+
100155
try
101156
{
102-
return core.TemplateDelete(id)
157+
return result
103158
? new OperationResult(true, $"eForm \"{templateDto.Label}\" deleted successfully")
104159
: new OperationResult(false, $"eForm \"{templateDto.Label}\" could not be deleted!");
105160
}
@@ -112,7 +167,7 @@ public OperationResult Delete(int id)
112167
[HttpPost]
113168
public OperationDataResult<DeployToModel> DeployTo(int id)
114169
{
115-
Core core = _coreHelper.GetCore();
170+
var core = _coreHelper.GetCore();
116171
var templateDto = core.TemplateItemRead(id);
117172
var siteNamesDto = core.Advanced_SiteItemReadAll();
118173

@@ -127,20 +182,20 @@ public OperationDataResult<DeployToModel> DeployTo(int id)
127182
[HttpPost]
128183
public OperationResult Deploy(DeployModel deployModel)
129184
{
130-
List<int> deployedSiteIds = new List<int>();
185+
var deployedSiteIds = new List<int>();
131186

132-
List<int> sitesToBeRetractedFrom = new List<int>();
133-
List<int> sitesToBeDeployedTo = new List<int>();
187+
var sitesToBeRetractedFrom = new List<int>();
188+
var sitesToBeDeployedTo = new List<int>();
134189

135-
Core core = _coreHelper.GetCore();
190+
var core = _coreHelper.GetCore();
136191
var templateDto = core.TemplateItemRead(deployModel.Id);
137192

138193
foreach (var site in templateDto.DeployedSites)
139194
{
140195
deployedSiteIds.Add(site.SiteUId);
141196
}
142197

143-
List<int> requestedSiteIds = deployModel
198+
var requestedSiteIds = deployModel
144199
.DeployCheckboxes
145200
.Select(deployCheckbox => deployCheckbox.Id)
146201
.ToList();
@@ -183,22 +238,22 @@ public OperationResult Deploy(DeployModel deployModel)
183238
core.CaseDelete(deployModel.Id, siteUId);
184239
}
185240

186-
return new OperationResult(true, $"eForm \"{templateDto.Label}\" deployed successfully!");
241+
return new OperationResult(true, $"\"{templateDto.Label}\" paired successfully.");
187242
}
188243

189244
[HttpGet]
190245
public HttpResponseMessage Csv(int id)
191246
{
192-
Core core = _coreHelper.GetCore();
247+
var core = _coreHelper.GetCore();
193248

194-
string fileName = $"{id}_{DateTime.Now.Ticks}.csv";
249+
var fileName = $"{id}_{DateTime.Now.Ticks}.csv";
195250
System.IO.Directory.CreateDirectory(System.Web.Hosting.HostingEnvironment.MapPath("~/bin/output/"));
196-
string filePath = System.Web.Hosting.HostingEnvironment.MapPath($"~/bin/output/{fileName}");
251+
var filePath = System.Web.Hosting.HostingEnvironment.MapPath($"~/bin/output/{fileName}");
197252
var fullPath = core.CasesToCsv(id, null, null, filePath,
198-
$"{Request.RequestUri.Scheme}://{Request.RequestUri.DnsSafeHost}" +
199-
"/api/templates/getimage?&filename=");
253+
$"{Request.RequestUri.Scheme}://{Request.RequestUri.Authority}{Url.Content("~")}" +
254+
"output/dataFolder/");
200255

201-
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
256+
var result = new HttpResponseMessage(HttpStatusCode.OK);
202257
var fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
203258

204259
result.Content = new StreamContent(fileStream);
@@ -211,24 +266,85 @@ public HttpResponseMessage Csv(int id)
211266

212267
[HttpGet]
213268
[Authorize]
214-
public HttpResponseMessage GetImage(string fileName)
269+
public HttpResponseMessage GetImage(string fileName, string noCache = "noCache")
215270
{
216-
string filePath = HttpContext.Current.Server.MapPath($"~/output/datafolder/picture/{fileName}");
271+
var filePath = HttpContext.Current.Server.MapPath($"~/output/datafolder/picture/{fileName}");
217272
if (!File.Exists(filePath))
218273
{
219274
return new HttpResponseMessage(HttpStatusCode.NotFound);
220275
}
221276
var extention = Path.GetExtension(filePath).Replace(".", "");
222277

223-
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
278+
var result = new HttpResponseMessage(HttpStatusCode.OK);
224279
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
225280

226281
result.Content = new StreamContent(fileStream);
227-
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
228-
result.Content.Headers.ContentDisposition.FileName = fileName;
282+
result.Content.Headers.ContentDisposition =
283+
new ContentDispositionHeaderValue("attachment") {FileName = fileName};
229284
result.Content.Headers.ContentType =
230285
new MediaTypeHeaderValue($"image/{extention}");
231286
return result;
232287
}
288+
289+
[HttpGet]
290+
[Authorize]
291+
public OperationResult RotateImage(string fileName)
292+
{
293+
var filePath = HttpContext.Current.Server.MapPath($"~/output/datafolder/picture/{fileName}");
294+
if (!File.Exists(filePath))
295+
{
296+
return new OperationResult(false, "File not found");
297+
}
298+
299+
var img = Image.FromFile(filePath);
300+
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
301+
img.Save(filePath);
302+
img.Dispose();
303+
304+
return new OperationResult(true, "Image rotated successfully.");
305+
}
306+
307+
[HttpGet]
308+
[Authorize]
309+
public OperationResult DeleteImage(string fileName, int fieldId, int uploadedObjId)
310+
{
311+
try
312+
{
313+
var core = _coreHelper.GetCore();
314+
if (!core.Advanced_DeleteUploadedData(fieldId, uploadedObjId))
315+
{
316+
return new OperationResult(false, "Error: Image was not deleted");
317+
}
318+
}
319+
320+
catch (Exception e)
321+
{
322+
Console.WriteLine(e);
323+
return new OperationResult(false, "Error");
324+
}
325+
return new OperationResult(true, "Image deleted successfully.");
326+
}
327+
328+
329+
[HttpGet]
330+
[Authorize]
331+
public HttpResponseMessage GetPdfFile(string fileName)
332+
{
333+
var filePath = HttpContext.Current.Server.MapPath($"~/output/datafolder/pdf/{fileName}.pdf");
334+
if (!File.Exists(filePath))
335+
{
336+
return new HttpResponseMessage(HttpStatusCode.NotFound);
337+
}
338+
339+
var result = new HttpResponseMessage(HttpStatusCode.OK);
340+
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
341+
342+
result.Content = new StreamContent(fileStream);
343+
result.Content.Headers.ContentDisposition =
344+
new ContentDispositionHeaderValue("attachment") {FileName = fileName};
345+
result.Content.Headers.ContentType =
346+
new MediaTypeHeaderValue($"application/pdf");
347+
return result;
348+
}
233349
}
234350
}

eFormAPI/eFormAPI/Infrastructure/Helpers/EFormCoreHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public Core GetCore()
6767
_core.HandleCaseDeleted += EventCaseDeleted;
6868
_core.HandleFileDownloaded += EventFileDownloaded;
6969
_core.HandleSiteActivated += EventSiteActivated;
70+
//_core.HandleEventLog += EventLog;
71+
//_core.HandleEventMessage += EventMessage;
72+
//_core.HandleEventWarning += EventWarning;
7073
_core.HandleEventException += EventException;
7174

7275
running = _core.StartSqlOnly(connectionStr);

eFormAPI/eFormAPI/eFormAPI.Web.csproj

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<UseGlobalApplicationHostFile />
2626
<NuGetPackageImportStamp>
2727
</NuGetPackageImportStamp>
28+
<Use64BitIISExpress />
2829
</PropertyGroup>
2930
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3031
<DebugSymbols>true</DebugSymbols>
@@ -61,32 +62,32 @@
6162
<HintPath>..\packages\AutoMapper.6.1.1\lib\net45\AutoMapper.dll</HintPath>
6263
<Private>True</Private>
6364
</Reference>
64-
<Reference Include="AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
65-
<HintPath>..\packages\Microting.eForm.1.6.1.3\lib\AWSSDK.Core.dll</HintPath>
65+
<Reference Include="AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604">
66+
<HintPath>..\packages\Microting.eForm.1.6.1.8\lib\AWSSDK.Core.dll</HintPath>
6667
</Reference>
67-
<Reference Include="AWSSDK.SQS, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
68-
<HintPath>..\packages\Microting.eForm.1.6.1.3\lib\AWSSDK.SQS.dll</HintPath>
68+
<Reference Include="AWSSDK.SQS, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604">
69+
<HintPath>..\packages\Microting.eForm.1.6.1.8\lib\AWSSDK.SQS.dll</HintPath>
6970
</Reference>
70-
<Reference Include="eFormCommunicator, Version=1.6.1.3, Culture=neutral, processorArchitecture=MSIL">
71-
<HintPath>..\packages\Microting.eForm.1.6.1.3\lib\eFormCommunicator.dll</HintPath>
71+
<Reference Include="eFormCommunicator, Version=1.6.1.8, Culture=neutral, PublicKeyToken=null">
72+
<HintPath>..\packages\Microting.eForm.1.6.1.8\lib\eFormCommunicator.dll</HintPath>
7273
</Reference>
73-
<Reference Include="eFormCore, Version=1.6.1.3, Culture=neutral, processorArchitecture=MSIL">
74-
<HintPath>..\packages\Microting.eForm.1.6.1.3\lib\eFormCore.dll</HintPath>
74+
<Reference Include="eFormCore, Version=1.6.1.8, Culture=neutral, PublicKeyToken=null">
75+
<HintPath>..\packages\Microting.eForm.1.6.1.8\lib\eFormCore.dll</HintPath>
7576
</Reference>
76-
<Reference Include="eFormData, Version=1.6.1.3, Culture=neutral, processorArchitecture=MSIL">
77-
<HintPath>..\packages\Microting.eForm.1.6.1.3\lib\eFormData.dll</HintPath>
77+
<Reference Include="eFormData, Version=1.6.1.8, Culture=neutral, PublicKeyToken=null">
78+
<HintPath>..\packages\Microting.eForm.1.6.1.8\lib\eFormData.dll</HintPath>
7879
</Reference>
79-
<Reference Include="eFormOffice, Version=1.6.1.3, Culture=neutral, processorArchitecture=MSIL">
80-
<HintPath>..\packages\Microting.eForm.1.6.1.3\lib\eFormOffice.dll</HintPath>
80+
<Reference Include="eFormOffice, Version=1.6.1.3, Culture=neutral, PublicKeyToken=null">
81+
<HintPath>..\packages\Microting.eForm.1.6.1.8\lib\eFormOffice.dll</HintPath>
8182
</Reference>
82-
<Reference Include="eFormShared, Version=1.6.1.3, Culture=neutral, processorArchitecture=MSIL">
83-
<HintPath>..\packages\Microting.eForm.1.6.1.3\lib\eFormShared.dll</HintPath>
83+
<Reference Include="eFormShared, Version=1.6.1.8, Culture=neutral, PublicKeyToken=null">
84+
<HintPath>..\packages\Microting.eForm.1.6.1.8\lib\eFormShared.dll</HintPath>
8485
</Reference>
85-
<Reference Include="eFormSqlController, Version=1.6.1.3, Culture=neutral, processorArchitecture=MSIL">
86-
<HintPath>..\packages\Microting.eForm.1.6.1.3\lib\eFormSqlController.dll</HintPath>
86+
<Reference Include="eFormSqlController, Version=1.6.1.8, Culture=neutral, PublicKeyToken=null">
87+
<HintPath>..\packages\Microting.eForm.1.6.1.8\lib\eFormSqlController.dll</HintPath>
8788
</Reference>
88-
<Reference Include="eFormSubscriber, Version=1.6.1.3, Culture=neutral, processorArchitecture=MSIL">
89-
<HintPath>..\packages\Microting.eForm.1.6.1.3\lib\eFormSubscriber.dll</HintPath>
89+
<Reference Include="eFormSubscriber, Version=1.6.1.8, Culture=neutral, PublicKeyToken=null">
90+
<HintPath>..\packages\Microting.eForm.1.6.1.8\lib\eFormSubscriber.dll</HintPath>
9091
</Reference>
9192
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
9293
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
@@ -305,6 +306,7 @@
305306
<None Include="NLog.xsd">
306307
<SubType>Designer</SubType>
307308
</None>
309+
<None Include="packages.config" />
308310
</ItemGroup>
309311
<ItemGroup>
310312
<EmbeddedResource Include="Migrations\201707190837078_InitialCreate.resx">

eFormAPI/eFormAPI/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<package id="Microsoft.Owin.Security.Cookies" version="3.1.0" targetFramework="net46" />
3434
<package id="Microsoft.Owin.Security.OAuth" version="3.1.0" targetFramework="net46" />
3535
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
36-
<package id="Microting.eForm" version="1.6.1.3" targetFramework="net46" />
36+
<package id="Microting.eForm" version="1.6.1.8" targetFramework="net46" />
3737
<package id="Modernizr" version="2.8.3" targetFramework="net46" />
3838
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net46" />
3939
<package id="NLog" version="4.4.11" targetFramework="net46" />

0 commit comments

Comments
 (0)