From ade961a4d3ddb3d8773f54f498c150d0ae0dadce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Janis=20Daniel=20Da=CC=88hne?=
 <janis.daehne2@student.uni-halle.de>
Date: Mon, 11 Nov 2019 16:09:35 +0100
Subject: [PATCH] - added example appsettings - removed local appsettings -
 added some debug output to track down an error

---
 .gitignore                                           |  1 +
 src/ClientServer/Config/Constants.cs                 |  2 +-
 .../Core/Exercises/ExerciseEditorController.cs       | 12 ++++++++++++
 .../{appsettings.json => appsettings_example.json}   |  6 +++---
 4 files changed, 17 insertions(+), 4 deletions(-)
 rename src/ClientServer/{appsettings.json => appsettings_example.json} (68%)

diff --git a/.gitignore b/.gitignore
index 6f8b91d..679caeb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ src/ClientServer/wwwroot/*
 !src/ClientServer/wwwroot/.gitkeep
 src/ClientServer/output
 src/ClientServer/wwwUploaded_Files/*
+src/ClientServer/appsettings.json
diff --git a/src/ClientServer/Config/Constants.cs b/src/ClientServer/Config/Constants.cs
index bbf2915..71fa0dc 100644
--- a/src/ClientServer/Config/Constants.cs
+++ b/src/ClientServer/Config/Constants.cs
@@ -13,7 +13,7 @@ namespace ClientServer.Helpers
     /// </summary>
     public static class Constants
     {
-        public static string VersionString = "2.5.5";
+        public static string VersionString = "2.5.6";
 
         /// <summary>
         /// this is only set once at program.cs!!
diff --git a/src/ClientServer/Controllers/Core/Exercises/ExerciseEditorController.cs b/src/ClientServer/Controllers/Core/Exercises/ExerciseEditorController.cs
index ea8f588..18713a1 100644
--- a/src/ClientServer/Controllers/Core/Exercises/ExerciseEditorController.cs
+++ b/src/ClientServer/Controllers/Core/Exercises/ExerciseEditorController.cs
@@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Mvc;
 using Microsoft.EntityFrameworkCore;
 using ClientServer.Models.Exercises.Solution;
 using ClientServer.Models.Files;
+using Newtonsoft.Json;
 
 namespace ClientServer.Controllers.Core.Exercises
 {
@@ -1657,6 +1658,8 @@ namespace ClientServer.Controllers.Core.Exercises
                 },
             };
 
+            string jsonTests = "";
+            string jsonTests2 = "";
             try
             {
                 
@@ -1679,6 +1682,10 @@ namespace ClientServer.Controllers.Core.Exercises
                     try
                     {
                         _context.Exercises.Add(exCopy);
+
+                        jsonTests = JsonConvert.SerializeObject(exCopy.Tests, Formatting.Indented,
+                            new JsonSerializerSettings() {ReferenceLoopHandling = ReferenceLoopHandling.Serialize});
+                        
                         await _context.SaveChangesAsync();
 
                         //now set main files...
@@ -1709,6 +1716,11 @@ namespace ClientServer.Controllers.Core.Exercises
             }
             catch (Exception e)
             {
+                
+                //we get the error here: ERROR:  insert or update on table "TestCaseSettingses" violates foreign key constraint "FK_TestCaseSettingses_Tests_TestId
+                //DETAIL:  Key (TestId)=(0) is not present in table "Tests".
+                Console.WriteLine("DBG: " + jsonTests);
+                
                 //see https://www.npgsql.org/doc/transactions.html
                 await base.HandleDbError(e);
                 return;
diff --git a/src/ClientServer/appsettings.json b/src/ClientServer/appsettings_example.json
similarity index 68%
rename from src/ClientServer/appsettings.json
rename to src/ClientServer/appsettings_example.json
index 9d2da60..003c882 100644
--- a/src/ClientServer/appsettings.json
+++ b/src/ClientServer/appsettings_example.json
@@ -10,15 +10,15 @@
   
   "IsDebugMode": true,
   "IsDbBootstrapEnabled": false,
-  "DbConnectionString": "Username=postgres;Password=janis;Host=localhost;Database=yapexDb;Pooling=true",
+  "DbConnectionString": "Username=XXX;Password=YYY;Host=localhost;Database=yapexDb;Pooling=true",
   "SystemSalt": "NeverChangeThisAfterFirstStartup",
-  "ExternalLoginUrl": "https://uebungsportal.informatik.uni-halle.de/ostepu/DB/DBTransaction/transaction/authentication/redirect/transaction/",
+  "ExternalLoginUrl": "URL",
   "MainEntrySite": "/",
   "LoginExternalFirstTimeSite": "/firstLoginExternalLogin.html",
   "RunAssessmentsAsync":  false,
   "DashboardScriptPathRelativeToCurrentDir": "dashboard.php",
   "DebugOriginUrl": "http://localhost:8080",
-  "DeployOriginUrls": ["https://yapex.informatik.uni-halle.de"],
+  "DeployOriginUrls": ["DEPLOY URL"],
   "IsSlave": false,
   "EnsureFileUploadDirStructure": true,
   "OnlySecureFlaggedCookies": false,
-- 
GitLab