public async Task ConvertFileToObject()

in Webapp/SDAF/Controllers/FileController.cs [141:173]


        public async Task<IActionResult> ConvertFileToObject(string id, string sourceController)
        {
            try
            {
                // Convert a file to a landscape or system object
                AppFile file = await _appFileService.GetByIdAsync(id, GetPartitionKey(id));
                if (file == null) return NotFound();

                id = id[..id.IndexOf('.')];
                byte[] bytes = file.Content;
                string bitString = Encoding.UTF8.GetString(bytes);
                string jsonString = Helper.TfvarToJson(bitString);
                if (file.Id.EndsWith("INFRASTRUCTURE.tfvars"))
                {
                    LandscapeModel landscape = JsonSerializer.Deserialize<LandscapeModel>(jsonString);
                    landscape.Id = id;
                    await _landscapeService.CreateAsync(new LandscapeEntity(landscape));
                    TempData["success"] = "Successfully converted file " + id + " to a workload zone object";
                }
                else
                {
                    SystemModel system = JsonSerializer.Deserialize<SystemModel>(jsonString);
                    system.Id = id;
                    await _systemService.CreateAsync(new SystemEntity(system));
                    TempData["success"] = "Successfully converted file " + id + " to a system object";
                }
            }
            catch (Exception e)
            {
                TempData["error"] = "Error converting file: " + e.Message;
            }
            return RedirectToAction("Index", sourceController);
        }