Skip to content

Commit 41f8cae

Browse files
authored
Merge pull request #66 from Gid733/master
Tags functionality and fixes
2 parents e80a169 + 69d9b53 commit 41f8cae

Some content is hidden

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

53 files changed

+419
-199
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace eFormAPI.Common.Models
2+
{
3+
public class CommonDictionaryModel
4+
{
5+
public int? Id { get; set; }
6+
public string Name { get; set; }
7+
public string Description { get; set; }
8+
}
9+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
namespace eFormAPI.Common.Models
1+
using System.Collections.Generic;
2+
3+
namespace eFormAPI.Common.Models
24
{
35
public class EFormXmlModel
46
{
57
public string EFormXml { get; set; }
8+
public string NewTag { get; set; }
9+
public List<int> TagIds { get; set; }
10+
11+
public EFormXmlModel()
12+
{
13+
TagIds = new List<int>();
14+
}
615
}
716
}

eFormAPI/eFormAPI.Common/Models/Templates/TemplateRequestModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace eFormAPI.Common.Models.Templates
1+
using System.Collections.Generic;
2+
3+
namespace eFormAPI.Common.Models.Templates
24
{
35
public class TemplateRequestModel
46
{
@@ -8,6 +10,7 @@ public class TemplateRequestModel
810
public int PageSize { get; set; }
911
public bool IsSortDsc { get; set; }
1012
public int Offset { get; set; }
13+
public List<int> TagIds { get; set; }
1114

1215
public TemplateRequestModel()
1316
{
@@ -16,6 +19,7 @@ public TemplateRequestModel()
1619
PageSize = 10;
1720
PageIndex = 0;
1821
Offset = 0;
22+
TagIds = new List<int>();
1923
}
2024
}
2125
}

eFormAPI/eFormAPI.Common/eFormAPI.Common.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
<HintPath>..\packages\Microsoft.Office.Interop.Excel.15.0.4795.1000\lib\net20\Microsoft.Office.Interop.Excel.dll</HintPath>
5757
<Private>True</Private>
5858
</Reference>
59-
<Reference Include="Microting.eForm, Version=2.1.37.0, Culture=neutral, processorArchitecture=AMD64">
60-
<HintPath>..\packages\Microting.eForm.2.1.37\lib\net45\Microting.eForm.dll</HintPath>
59+
<Reference Include="Microting.eForm, Version=2.1.55.0, Culture=neutral, PublicKeyToken=null">
60+
<HintPath>..\packages\Microting.eForm.2.1.55\lib\net45\Microting.eForm.dll</HintPath>
6161
</Reference>
6262
<Reference Include="MySql.Data, Version=6.9.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
6363
<HintPath>..\packages\MySql.Data.6.9.10\lib\net45\MySql.Data.dll</HintPath>
@@ -95,6 +95,7 @@
9595
<Compile Include="Models\Auth\ChangePasswordModel.cs" />
9696
<Compile Include="Models\Auth\ForgotPasswordModel.cs" />
9797
<Compile Include="Models\Auth\ResetPasswordModel.cs" />
98+
<Compile Include="Models\CommonDictionaryModel.cs" />
9899
<Compile Include="Models\DisplayTemplateColumnsModel.cs" />
99100
<Compile Include="Models\Settings\Admin\AdminSettingsModel.cs" />
100101
<Compile Include="Models\Settings\Admin\HeaderSettingsModel.cs" />

eFormAPI/eFormAPI.Common/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<package id="EntityFramework" version="6.1.3" targetFramework="net46" />
88
<package id="EPPlus" version="4.1.1" targetFramework="net46" />
99
<package id="Microsoft.Office.Interop.Excel" version="15.0.4795.1000" targetFramework="net46" />
10-
<package id="Microting.eForm" version="2.1.37" targetFramework="net46" />
10+
<package id="Microting.eForm" version="2.1.55" targetFramework="net46" />
1111
<package id="MySql.Data" version="6.9.10" targetFramework="net46" />
1212
<package id="MySql.Data.Entity" version="6.9.10" targetFramework="net46" />
1313
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net46" />

eFormAPI/eFormAPI/Controllers/EntitySearchController.cs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ public class EntitySearchController : ApiController
1616
[HttpPost]
1717
[Route("api/searchable-groups")]
1818
public OperationDataResult<EntityGroupList> GetEntityGroupList(AdvEntityGroupListRequestModel requestModel)
19-
{
19+
{
2020
try
2121
{
2222
var core = _coreHelper.GetCore();
23-
var model = core.Advanced_EntityGroupAll(requestModel.Sort, requestModel.NameFilter, requestModel.PageIndex, requestModel.PageSize, "EntitySearch", requestModel.IsSortDsc, "not_removed");
23+
var model = core.Advanced_EntityGroupAll(requestModel.Sort, requestModel.NameFilter,
24+
requestModel.PageIndex, requestModel.PageSize, "EntitySearch", requestModel.IsSortDsc,
25+
"not_removed");
2426
return new OperationDataResult<EntityGroupList>(true, model);
2527
}
2628
catch (Exception e)
@@ -36,27 +38,19 @@ public OperationResult CreateEntityGroup(AdvEntityGroupEditModel editModel)
3638
try
3739
{
3840
var core = _coreHelper.GetCore();
39-
4041
var groupCreate = core.EntityGroupCreate("EntitySearch", editModel.Name);
41-
4242
if (editModel.AdvEntityItemModels.Any())
4343
{
44-
EntityGroup entityGroup = core.EntityGroupRead(groupCreate.EntityGroupMUId);
45-
44+
var entityGroup = core.EntityGroupRead(groupCreate.EntityGroupMUId);
4645
var nextItemUid = entityGroup.EntityGroupItemLst.Count;
47-
4846
foreach (var entityItem in editModel.AdvEntityItemModels)
4947
{
5048
entityGroup.EntityGroupItemLst.Add(new EntityItem(entityItem.Name,
5149
entityItem.Description, nextItemUid.ToString(), "created"));
5250
nextItemUid++;
5351
}
54-
5552
core.EntityGroupUpdate(entityGroup);
5653
}
57-
58-
59-
6054
return new OperationResult(true, $"{groupCreate.EntityGroupMUId} created successfully");
6155
}
6256
catch (Exception exception)
@@ -72,14 +66,10 @@ public OperationResult UpdateEntityGroup(AdvEntityGroupEditModel editModel)
7266
try
7367
{
7468
var core = _coreHelper.GetCore();
75-
76-
EntityGroup entityGroup = core.EntityGroupRead(editModel.GroupUid);
77-
78-
entityGroup.EntityGroupItemLst = editModel.AdvEntityItemModels;
79-
entityGroup.Name = editModel.Name;
80-
81-
core.EntityGroupUpdate(entityGroup);
82-
69+
var entityGroup = core.EntityGroupRead(editModel.GroupUid);
70+
entityGroup.EntityGroupItemLst = editModel.AdvEntityItemModels;
71+
entityGroup.Name = editModel.Name;
72+
core.EntityGroupUpdate(entityGroup);
8373
return new OperationResult(true, $"{editModel.GroupUid} updated successfully");
8474
}
8575
catch (Exception exception)
@@ -96,15 +86,15 @@ public OperationDataResult<EntityGroup> GetEntityGroup(string entityGroupUid)
9686
{
9787
var core = _coreHelper.GetCore();
9888

99-
EntityGroup entityGroup = core.EntityGroupRead(entityGroupUid);
89+
var entityGroup = core.EntityGroupRead(entityGroupUid);
10090

10191
return new OperationDataResult<EntityGroup>(true, entityGroup);
10292
}
10393
catch (Exception exception)
10494
{
10595
return new OperationDataResult<EntityGroup>(false, "Error when obtaining searchable list");
10696
}
107-
}
97+
}
10898

10999
[HttpGet]
110100
[Route("api/searchable-groups/delete/{entityGroupUid}")]
@@ -115,8 +105,8 @@ public OperationResult DeleteEntityGroup(string entityGroupUid)
115105
var core = _coreHelper.GetCore();
116106

117107

118-
return core.EntityGroupDelete(entityGroupUid)
119-
? new OperationResult(true, $"{entityGroupUid} deleted successfully")
108+
return core.EntityGroupDelete(entityGroupUid)
109+
? new OperationResult(true, $"{entityGroupUid} deleted successfully")
120110
: new OperationResult(false, "Error when deleting searchable list");
121111
}
122112
catch (Exception exception)

eFormAPI/eFormAPI/Controllers/SitesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class SitesController : ApiController
1919
public OperationDataResult<List<SiteName_Dto>> Index()
2020
{
2121
Core core = _coreHelper.GetCore();
22-
var siteNamesDto = core.Advanced_SiteItemReadAll();
22+
var siteNamesDto = core.Advanced_SiteItemReadAll(false);
2323

2424
return new OperationDataResult<List<SiteName_Dto>>(true, siteNamesDto);
2525
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Web.Http;
4+
using eFormAPI.Common.API;
5+
using eFormAPI.Common.Models;
6+
using eFormAPI.Web.Infrastructure.Helpers;
7+
8+
namespace eFormAPI.Web.Controllers
9+
{
10+
[Authorize]
11+
public class TagsController : ApiController
12+
{
13+
private readonly EFormCoreHelper _coreHelper = new EFormCoreHelper();
14+
15+
[HttpGet]
16+
[Route("api/tags")]
17+
public OperationDataResult<List<CommonDictionaryModel>> GetAllTags()
18+
{
19+
try
20+
{
21+
var core = _coreHelper.GetCore();
22+
var tags = core.GetAllTags(false);
23+
var model = new List<CommonDictionaryModel>(tags.Count);
24+
tags.ForEach(tag =>
25+
{
26+
model.Add(new CommonDictionaryModel()
27+
{
28+
Id = tag.Id,
29+
Name = tag.Name,
30+
});
31+
});
32+
return new OperationDataResult<List<CommonDictionaryModel>>(true, model);
33+
}
34+
catch (Exception ex)
35+
{
36+
return new OperationDataResult<List<CommonDictionaryModel>>(false, "Error while obtaining tags");
37+
}
38+
}
39+
40+
[HttpDelete]
41+
[Route("api/tags")]
42+
public OperationDataResult<bool> DeleteTag(int tagId)
43+
{
44+
try
45+
{
46+
var result = _coreHelper.GetCore().TagDelete(tagId);
47+
return new OperationDataResult<bool>(result, result);
48+
}
49+
catch (Exception ex)
50+
{
51+
return new OperationDataResult<bool>(false, "Error while deleting tags");
52+
}
53+
}
54+
}
55+
}

eFormAPI/eFormAPI/Controllers/TemplateColumnsController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Net.Http;
45
using System.Web.Http;
56
using eFormAPI.Common.API;
67
using eFormAPI.Common.Models;
@@ -28,7 +29,8 @@ public OperationDataResult<List<TemplateColumnModel>> GetAvailableColumns(int te
2829
if (field.FieldType != "Picture"
2930
&& field.FieldType != "Audio"
3031
&& field.FieldType != "Movie"
31-
&& field.FieldType != "Signature")
32+
&& field.FieldType != "Signature"
33+
&& field.FieldType != "SaveButton")
3234
templateColumns.Add(new TemplateColumnModel()
3335
{
3436
Id = field.Id,

eFormAPI/eFormAPI/Controllers/TemplatesController.cs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Net.Http.Headers;
99
using System.Web;
1010
using System.Web.Http;
11+
using Amazon.Runtime;
1112
using eFormAPI.Common.API;
1213
using eFormAPI.Common.Models;
1314
using eFormAPI.Common.Models.Templates;
@@ -21,7 +22,7 @@ namespace eFormAPI.Web.Controllers
2122
public class TemplatesController : ApiController
2223
{
2324
private readonly EFormCoreHelper _coreHelper = new EFormCoreHelper();
24-
25+
2526
[HttpPost]
2627
public OperationDataResult<TemplateListModel> Index(TemplateRequestModel templateRequestModel)
2728
{
@@ -30,7 +31,12 @@ public OperationDataResult<TemplateListModel> Index(TemplateRequestModel templat
3031
try
3132
{
3233
var core = _coreHelper.GetCore();
33-
var templatesDto = core.TemplateItemReadAll(false);
34+
var templatesDto = core.TemplateItemReadAll(false,
35+
"",
36+
templateRequestModel.NameFilter,
37+
templateRequestModel.IsSortDsc,
38+
templateRequestModel.Sort,
39+
templateRequestModel.TagIds);
3440

3541
var model = new TemplateListModel
3642
{
@@ -47,7 +53,7 @@ public OperationDataResult<TemplateListModel> Index(TemplateRequestModel templat
4753
if (ex.Message.Contains("PrimeDb"))
4854
{
4955
var lines = File.ReadAllLines(
50-
System.Web.Hosting.HostingEnvironment.MapPath("~/bin/Input.txt"));
56+
System.Web.Hosting.HostingEnvironment.MapPath("~/bin/Input.txt"));
5157

5258
var connectionStr = lines.First();
5359
var adminTool = new AdminTools(connectionStr);
@@ -128,24 +134,35 @@ public OperationDataResult<Template_Dto> Get(int id)
128134
[HttpPost]
129135
public OperationResult Create(EFormXmlModel eFormXmlModel)
130136
{
131-
var core = _coreHelper.GetCore();
132-
133-
var newTemplate = core.TemplateFromXml(eFormXmlModel.EFormXml);
134-
135-
newTemplate = core.TemplateUploadData(newTemplate);
136-
var errors = core.TemplateValidation(newTemplate);
137-
138-
if (!errors.Any())
137+
try
139138
{
140-
if (newTemplate == null) return new OperationResult(false, "eForm could not be created!");
141-
139+
var core = _coreHelper.GetCore();
140+
// Create tags
141+
var tagList = eFormXmlModel.NewTag.Replace(" ", "").Split(',');
142+
foreach (var tag in tagList)
143+
{
144+
eFormXmlModel.TagIds.Add(core.TagCreate(tag));
145+
}
146+
// Create eform
147+
var newTemplate = core.TemplateFromXml(eFormXmlModel.EFormXml);
148+
newTemplate = core.TemplateUploadData(newTemplate);
149+
// Check errors
150+
var errors = core.TemplateValidation(newTemplate);
151+
if (errors.Any())
152+
{
153+
var message = errors.Aggregate("", (current, str) => current + ("<br>" + str));
154+
throw new Exception("eForm could not be created!" + message);
155+
}
156+
if (newTemplate == null) throw new Exception("eForm could not be created!");
157+
// Set tags to eform
142158
core.TemplateCreate(newTemplate);
159+
core.TemplateSetTags(newTemplate.Id, eFormXmlModel.TagIds);
143160
return new OperationResult(true, $"eForm \"{newTemplate.Label}\" created successfully");
144161
}
145-
146-
var message = errors.Aggregate("", (current, str) => current + ("<br>" + str));
147-
148-
return new OperationResult(false, "eForm could not be created!" + message);
162+
catch (Exception e)
163+
{
164+
return new OperationResult(false, e.Message);
165+
}
149166
}
150167

151168
[HttpGet]
@@ -158,7 +175,7 @@ public OperationResult Delete(int id)
158175
core.CaseDelete(templateDto.Id, siteUId.SiteUId);
159176
}
160177
var result = core.TemplateDelete(id);
161-
178+
162179
try
163180
{
164181
return result
@@ -300,7 +317,7 @@ public OperationResult RotateImage(string fileName)
300317
{
301318
return new OperationResult(false, "File not found");
302319
}
303-
320+
304321
var img = Image.FromFile(filePath);
305322
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
306323
img.Save(filePath);
@@ -351,7 +368,7 @@ public HttpResponseMessage GetPdfFile(string fileName)
351368
new MediaTypeHeaderValue("application/pdf");
352369
return result;
353370
}
354-
371+
355372
[HttpGet]
356373
[Authorize]
357374
[Route("api/templates/download-eform-pdf/{templateId}")]
@@ -380,15 +397,13 @@ public HttpResponseMessage DownloadEFormPDF(int templateId)
380397
{
381398
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
382399
}
383-
384400
}
385-
401+
386402
[HttpGet]
387403
[Authorize]
388404
[Route("api/templates/download-eform-xml/{templateId}")]
389405
public HttpResponseMessage DownloadEFormXML(int templateId)
390406
{
391-
392407
try
393408
{
394409
var core = _coreHelper.GetCore();

0 commit comments

Comments
 (0)