in Webapp/SDAF/Controllers/FileController.cs [268:339]
public async Task<IActionResult> EditAsync(string id, string newId, string fileContent, string sourceController, int type)
{
AppFile file = null;
ViewBag.IsImagesFile = false;
int newType = type;
if (newId.EndsWith("_custom_naming.json"))
{
newType = 2;
}
else if (newId.EndsWith("_custom_sizes.json"))
{
newType = 1;
}
switch (newType)
{
case 0:
file = await GetImagesFile(newId, newType, "VM");
ViewBag.IsImagesFile = true;
break;
case 1:
case 2:
file = await GetImagesFile(newId, newType, GetPartitionKey(id));
ViewBag.IsImagesFile = true;
ViewBag.FilePattern = newId;
break;
default:
file = await _appFileService.GetByIdAsync(id, GetPartitionKey(id));
break;
}
if (file == null) return NotFound();
try
{
byte[] bytes = Encoding.UTF8.GetBytes(fileContent);
file.Content = bytes;
if (id != newId)
{
file.Id = newId;
await _appFileService.CreateAsync(file);
await _appFileService.DeleteAsync(id, GetPartitionKey(id));
}
else
{
await _appFileService.UpdateAsync(file);
}
TempData["success"] = "Successfully updated file " + id;
if (newType == 0)
{
return RedirectToAction("Index", sourceController);
}
else
{
string newName = id[..id.IndexOf("_custom")];
return RedirectToAction("Edit", sourceController, new { @id = newName, @partitionKey = GetPartitionKey(id) });
}
}
catch (Exception e)
{
ModelState.AddModelError("FileId", "Error updating file: " + e.Message);
}
ViewBag.Message = fileContent;
ViewBag.SourceController = sourceController;
ViewBag.Type = type;
return View(file);
}