public async Task EditAsync()

in Webapp/SDAF/Controllers/LandscapeController.cs [334:406]


        public async Task<IActionResult> EditAsync(LandscapeModel landscape)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string newId = Helper.GenerateId(landscape);
                    if (landscape.Id == null) landscape.Id = newId;
                    if (newId != landscape.Id)
                    {
                        landscape.Id = newId;
                        await SubmitNewAsync(landscape);
                        string id = landscape.Id;
                        string path = $"/LANDSCAPE/{id}/{id}.tfvars";
                        string content = Helper.ConvertToTerraform(landscape);
                        byte[] bytes = Encoding.UTF8.GetBytes(content);

                        AppFile file = new()
                        {
                            Id = WebUtility.HtmlEncode(path),
                            Content = bytes,
                            UntrustedName = path,
                            Size = bytes.Length,
                            UploadDT = DateTime.UtcNow
                        };

                        await _landscapeService.CreateTFVarsAsync(file);

                        return RedirectToAction("Edit", "Landscape", new { @id = landscape.Id, @partitionKey = landscape.environment });  //RedirectToAction("Index");
                    }
                    else
                    {
                        if (landscape.IsDefault)
                        {
                            await UnsetDefault(landscape.Id);
                        }
                        DateTime currentDateAndTime = DateTime.Now;
                        landscape.LastModified = currentDateAndTime.ToShortDateString();

                        await _landscapeService.UpdateAsync(new LandscapeEntity(landscape));
                        TempData["success"] = "Successfully updated workload zone " + landscape.Id;

                        string id = landscape.Id;
                        string path = $"/LANDSCAPE/{id}/{id}.tfvars";
                        string content = Helper.ConvertToTerraform(landscape);
                        byte[] bytes = Encoding.UTF8.GetBytes(content);

                        AppFile file = new()
                        {
                            Id = WebUtility.HtmlEncode(path),
                            Content = bytes,
                            UntrustedName = path,
                            Size = bytes.Length,
                            UploadDT = DateTime.UtcNow
                        };

                        await _landscapeService.CreateTFVarsAsync(file);

                        return RedirectToAction("Edit", "Landscape", new { @id = landscape.Id, @partitionKey = landscape.environment });  //RedirectToAction("Index");
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("LandscapeId", "Error editing workload zone: " + e.Message);
                }
            }

            landscapeView.SapObject = landscape;
            ViewBag.ValidImageOptions = (imagesOffered.Length != 0);
            ViewBag.ImageOptions = imageOptions;

            return View(landscapeView);
        }