commit fc0e5b361c76648546077f3ff4777e0de59e98b1
Author: Vojtěch Bartička <aitakaitov@gmail.com>
Date:   Sun Apr 3 18:38:56 2022 +0200

    Changed formatting, added comments, database check

diff --git a/Backend/Backend/Program.cs b/Backend/Backend/Program.cs
index 6241bdd..d7f1aee 100644
--- a/Backend/Backend/Program.cs
+++ b/Backend/Backend/Program.cs
@@ -18,10 +18,12 @@ Registration.RegisterServices(builder);
 builder.Services.AddEndpointsApiExplorer();
 builder.Services.AddSwaggerGen();
 
+// Database
 builder.Services.AddDbContext<DatabaseContext>();
 
 var app = builder.Build();
 
+// Enable DateTime in PostgreSQL
 AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
 
 
@@ -45,6 +47,11 @@ app.Logger.LogInformation("Starting up");
 using (var scope = app.Services.CreateScope())
 {
     var context = scope.ServiceProvider.GetService<DatabaseContext>();
+    if (context == null)
+    {
+        app.Logger.LogCritical("Could not initialize database context, shutting down.");
+        Environment.Exit(101);
+    }
 
     // In development we seed dummy data
     if (app.Environment.IsDevelopment())
diff --git a/Backend/Backend/RestAPI.csproj b/Backend/Backend/RestAPI.csproj
index 77e645b..51fe23e 100644
--- a/Backend/Backend/RestAPI.csproj
+++ b/Backend/Backend/RestAPI.csproj
@@ -24,4 +24,8 @@
     <ProjectReference Include="..\Core\Core.csproj" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Folder Include="Controllers\" />
+  </ItemGroup>
+
 </Project>
diff --git a/Backend/Core/Seeding/Seeder.cs b/Backend/Core/Seeding/Seeder.cs
index 8cbedba..aa28079 100644
--- a/Backend/Core/Seeding/Seeder.cs
+++ b/Backend/Core/Seeding/Seeder.cs
@@ -16,13 +16,31 @@ namespace Core.Seeding
         {
             if (!context.Documents.Any())
             {
-                DocumentContent content = new DocumentContent() { Content = "Dummy content" };
+                DocumentContent content = new DocumentContent()
+                {
+                    Content = "Dummy content"
+                };
                 context.DocumentContents.Add(content);
 
-                User user = new User() { Username = "testuser", Name = "Test", Surname = "User", Password = "password", Role = ERole.ANNOTATOR };
+                User user = new User()
+                {
+                    Username = "testuser",
+                    Name = "Test",
+                    Surname = "User",
+                    Password = "password",
+                    Role = ERole.ANNOTATOR
+                };
                 context.Users.Add(user);
 
-                Document document = new Document() { Content = content, Name = "Test document", DateAdded = DateTime.Now, Length = 10, RequiredAnnotations = 3, UserAdded = user };
+                Document document = new Document()
+                {
+                    Content = content,
+                    Name = "Test document",
+                    DateAdded = DateTime.Now,
+                    Length = 10,
+                    RequiredAnnotations = 3,
+                    UserAdded = user
+                };
                 context.Documents.Add(document);
                 context.SaveChanges();
 
@@ -38,20 +56,49 @@ namespace Core.Seeding
                 };
                 context.Annotations.Add(annotation);
 
-                Class clss = new Class() { Color = "rgb(...)", Description = "Dummy description", Name = "Dummy class name" };
+                Class clss = new Class()
+                {
+                    Color = "rgb(...)",
+                    Description = "Dummy description",
+                    Name = "Dummy class name"
+                };
                 context.Classes.Add(clss);
 
                 annotation.Classes.Add(clss);
 
-                TagCategory category = new TagCategory() { Name = "Dummy category", Color = "rgb(...)", Description = "Dummy category description" };
+                TagCategory category = new TagCategory()
+                {
+                    Name = "Dummy category",
+                    Color = "rgb(...)",
+                    Description = "Dummy category description"
+                };
                 context.TagCategories.Add(category);
 
-                Tag tag = new Tag() { Name = "Dummy tag", Category = category, Description = "Dummy tag", Color = "rgb(...)" };
+                Tag tag = new Tag()
+                {
+                    Name = "Dummy tag",
+                    Category = category,
+                    Description = "Dummy tag",
+                    Color = "rgb(...)"
+                };
                 context.Tags.Add(tag);
-                SubTag subTag = new SubTag() { Description = "Dummy subtag", Name = "Dummy subtag", Tag = tag };
+                SubTag subTag = new SubTag()
+                {
+                    Description = "Dummy subtag",
+                    Name = "Dummy subtag",
+                    Tag = tag
+                };
                 context.SubTags.Add(subTag);
 
-                AnnotationTag annotationTag = new AnnotationTag() { Annotation = annotation, Instance = 0, Length = 1, Position = 0, Tag = tag, Note = "Dummy note" };
+                AnnotationTag annotationTag = new AnnotationTag()
+                {
+                    Annotation = annotation,
+                    Instance = 0,
+                    Length = 1,
+                    Position = 0,
+                    Tag = tag,
+                    Note = "Dummy note"
+                };
                 context.AnnotationTags.Add(annotationTag);
 
                 context.SaveChanges();
@@ -62,7 +109,14 @@ namespace Core.Seeding
         {
             if (!context.Documents.Any())
             {
-                User admin = new User() { Name = "Admin", Surname = "Admin", Role = ERole.ADMINISTRATOR, Username = "admin", Password = "123a456b789c" };
+                User admin = new User()
+                {
+                    Name = "Admin",
+                    Surname = "Admin",
+                    Role = ERole.ADMINISTRATOR,
+                    Username = "admin",
+                    Password = "123a456b789c"
+                };
                 context.Users.Add(admin);
                 context.SaveChanges();
             }
diff --git a/Backend/Core/Services/UserService/UserServiceEF.cs b/Backend/Core/Services/UserService/UserServiceEF.cs
index 60ee80e..60a14de 100644
--- a/Backend/Core/Services/UserService/UserServiceEF.cs
+++ b/Backend/Core/Services/UserService/UserServiceEF.cs
@@ -49,7 +49,7 @@ namespace Core.Services
                 }
                 return u;
             }
-            catch (Exception ex)
+            catch (Exception)
             {
                 _logger.Information($"No user with username {username} found.");
                 return null;
@@ -65,7 +65,14 @@ namespace Core.Services
                 return null;
             }
 
-            User user = new User() { Username = username, Name = name, Surname = surname, Password = BCrypt.Net.BCrypt.HashPassword(password), Role = role };
+            User user = new User()
+            {
+                Username = username,
+                Name = name,
+                Surname = surname,
+                Password = BCrypt.Net.BCrypt.HashPassword(password),
+                Role = role
+            };
             _databaseContext.Users.Add(user);
             _databaseContext.SaveChanges();
             return user;
@@ -79,7 +86,7 @@ namespace Core.Services
                 User user = _databaseContext.Users.First(u => u.Username == username);
                 return user;
             }
-            catch (InvalidOperationException ex)
+            catch (InvalidOperationException)
             {
                 _logger.Warning($"No user with the username {username} found.");
                 return null;
@@ -94,7 +101,7 @@ namespace Core.Services
                 User user = _databaseContext.Users.First(u => u.Id == id);
                 return user;
             }
-            catch (InvalidOperationException ex)
+            catch (InvalidOperationException)
             {
                 _logger.Warning($"No user with the GUID {id} found.");
                 return null;
