in Webapp/SDAF/Controllers/SystemController.cs [431:525]
public async Task<IActionResult> EditAsync(SystemModel system)
{
if (ModelState.IsValid)
{
try
{
string newId = Helper.GenerateId(system);
if (system.Id == null) system.Id = newId;
if (newId != system.Id)
{
if (String.IsNullOrEmpty(system.Description))
{
if ((bool)system.database_high_availability || (bool)system.scs_high_availability)
{
system.Description = system.database_platform + " high availability system on " + system.scs_server_image.publisher + " " + system.scs_server_image.offer + " " + system.scs_server_image.sku;
}
else
{
system.Description = system.database_platform + " distributed system on " + system.scs_server_image.publisher + " " + system.scs_server_image.offer + " " + system.scs_server_image.sku;
}
}
system.subscription_id = system.subscription.Replace("/subscriptions/", "");
await SubmitNewAsync(system);
string id = system.Id;
string path = $"/SYSTEM/{id}/{id}.tfvars";
string content = Helper.ConvertToTerraform(system);
byte[] bytes = Encoding.UTF8.GetBytes(content);
AppFile file = new()
{
Id = WebUtility.HtmlEncode(path),
Content = bytes,
UntrustedName = path,
Size = bytes.Length,
UploadDT = DateTime.UtcNow
};
await _systemService.CreateTFVarsAsync(file);
return RedirectToAction("Edit", "System", new { @id = system.Id, @partitionKey = system.environment }); //RedirectToAction("Index");
}
else
{
if (system.IsDefault)
{
await UnsetDefault(system.Id);
}
if (String.IsNullOrEmpty(system.Description))
{
if ((bool)system.database_high_availability || (bool)system.scs_high_availability)
{
system.Description = system.database_platform + " high availability system on " + system.scs_server_image.publisher + " " + system.scs_server_image.offer + " " + system.scs_server_image.sku;
}
else
{
system.Description = system.database_platform + " distributed system on " + system.scs_server_image.publisher + " " + system.scs_server_image.offer + " " + system.scs_server_image.sku;
}
}
DateTime currentDateAndTime = DateTime.Now;
system.LastModified = currentDateAndTime.ToShortDateString();
await _systemService.UpdateAsync(new SystemEntity(system));
TempData["success"] = "Successfully updated system " + system.Id;
string id = system.Id;
string path = $"/SYSTEM/{id}/{id}.tfvars";
string content = Helper.ConvertToTerraform(system);
byte[] bytes = Encoding.UTF8.GetBytes(content);
AppFile file = new()
{
Id = WebUtility.HtmlEncode(path),
Content = bytes,
UntrustedName = path,
Size = bytes.Length,
UploadDT = DateTime.UtcNow
};
await _systemService.CreateTFVarsAsync(file);
return RedirectToAction("Edit", "System", new { @id = system.Id, @partitionKey = system.environment }); //RedirectToAction("Index");
}
}
catch (Exception e)
{
ModelState.AddModelError("SystemId", "Error editing system: " + e.Message);
}
}
systemView.SapObject = system;
ViewBag.ValidImageOptions = (imagesOffered.Length != 0);
ViewBag.ImageOptions = imageOptions;
return View(systemView);
}