Skip to content

Commit 0952673

Browse files
committed
Adding ability to update file tags and properties in seperate api calls.
1 parent 7ae984b commit 0952673

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Controllers/FilesController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public async Task<OperationResult> UpdateTags([FromBody] BackendConfigurationFil
7676
return await _backendConfigurationFilesService.UpdateTags(model);
7777
}
7878

79+
[HttpPut("properties")]
80+
public async Task<OperationResult> UpdateProperties([FromBody] BackendConfigurationFileUpdateProperties model)
81+
{
82+
return await _backendConfigurationFilesService.UpdateProperties(model);
83+
}
84+
7985
[HttpPost]
8086
[Route("create")]
8187
public async Task<OperationResult> Create([FromForm] BackendConfigurationFileCreateList model)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Collections.Generic;
2+
3+
namespace BackendConfiguration.Pn.Infrastructure.Models.Files;
4+
5+
public class BackendConfigurationFileUpdateProperties
6+
{
7+
public int Id { get; set; }
8+
9+
public List<int> Properties { get; set; }
10+
= [];
11+
12+
}

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationFilesService/BackendConfigurationFilesService.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,41 @@ public async Task<OperationResult> UpdateTags(BackendConfigurationFileUpdateFile
266266
}
267267
}
268268

269+
public async Task<OperationResult> UpdateProperties(BackendConfigurationFileUpdateProperties model)
270+
{
271+
var fileProperties = await _dbContext.PropertyFiles
272+
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
273+
.Where(x => x.FileId == model.Id)
274+
.ToListAsync();
275+
276+
var propertiesForDelete = fileProperties
277+
.Where(x => !model.Properties.Contains(x.PropertyId)).ToList();
278+
279+
var propertiesForCreate = model.Properties
280+
.Where(x => !fileProperties.Select(y => y.PropertyId).Contains(x))
281+
.Select(propertyForCreateId => new PropertyFile
282+
{
283+
FileId = model.Id,
284+
PropertyId = propertyForCreateId,
285+
CreatedByUserId = _userService.UserId,
286+
UpdatedByUserId = _userService.UserId
287+
})
288+
.ToList();
289+
290+
foreach (var newProperty in propertiesForCreate)
291+
{
292+
await newProperty.Create(_dbContext);
293+
}
294+
295+
foreach (var property in propertiesForDelete)
296+
{
297+
property.UpdatedByUserId = _userService.UserId;
298+
await property.Delete(_dbContext);
299+
}
300+
301+
return new OperationResult(true);
302+
}
303+
269304
public async Task<OperationResult> Create(List<BackendConfigurationFileCreate> model)
270305
{
271306
try
@@ -357,7 +392,6 @@ public async Task<OperationResult> Create(List<BackendConfigurationFileCreate> m
357392
}
358393
}
359394

360-
361395
public async Task<OperationResult> Delete(int id)
362396
{
363397
try

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationFilesService/IBackendConfigurationFilesService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public interface IBackendConfigurationFilesService
1616

1717
Task<OperationResult> UpdateTags(BackendConfigurationFileUpdateFileTags model);
1818

19+
Task<OperationResult> UpdateProperties(BackendConfigurationFileUpdateProperties model);
20+
1921
Task<OperationResult> Create(List<BackendConfigurationFileCreate> model);
2022

2123
Task<OperationResult> Delete(int id);

0 commit comments

Comments
 (0)