diff --git a/FlightJournal.Web/Controllers/ErrorController.cs b/FlightJournal.Web/Controllers/ErrorController.cs
index 8156d838..1ed61e11 100644
--- a/FlightJournal.Web/Controllers/ErrorController.cs
+++ b/FlightJournal.Web/Controllers/ErrorController.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Web.Mvc;
+using System.Web.Mvc;
namespace FlightJournal.Web.Controllers
{
@@ -10,8 +6,8 @@ public class ErrorController : Controller
{
public ActionResult PageNotFound()
{
- Response.StatusCode = 404;
- return View();
+ Response.StatusCode = 404; // Set the 404 status code
+ return new ContentResult { Content = " ________________________________________ \r\n
< 404 Page Not Found - Udelanding! >\r\n
---------------------------------------- \r\n
\\ ^__^\r\n
\\ (oo)\\_______\r\n
(__)\\ )\\/\\\r\n
||----w |\r\n
|| ||\r\n
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿\r\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⣽⣿\r\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⠀⢀⣾⣿⣿\r\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠀⠀⠀⣠⣾⣿⣿⣿\r\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⠀⣠⣾⣿⣿⣿⣿⣿\r\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣻⣾⡍⠻⣿⣿⣿⠟⠁⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿\r\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⡙⠁⠀⠈⠻⣧⡀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿\r\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠈⠻⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\r\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠉⠻⣦⡀⠀⠀⠙⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\r\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⠀⣠⣾⣿⣷⣤⡀⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿\r\n⣿⣿⣿⣿⣿⣿⡿⠋⠁⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣦⡀⢈⣿⠟⠉⠉⢻⣿⣿⣿\r\n⣿⣿⣿⣿⣿⠏⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⢀⣴⣿⣿⣿⣿\r\n⣿⣿⣿⠟⠁⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⢀⣴⣿⣿⣿⣿⣿⣿\r\n⣿⣟⠁⠀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣿⣿⣿⣿⣿⣿⣿⣿\r\n⣿⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
" }; // Return an empty ContentResult
}
public ActionResult PilotNotFound()
diff --git a/FlightJournal.Web/FlightJournal.Web.csproj b/FlightJournal.Web/FlightJournal.Web.csproj
index 3530f3dd..d844e7b6 100644
--- a/FlightJournal.Web/FlightJournal.Web.csproj
+++ b/FlightJournal.Web/FlightJournal.Web.csproj
@@ -568,6 +568,7 @@
+
diff --git a/FlightJournal.Web/Global.asax.cs b/FlightJournal.Web/Global.asax.cs
index aae7826d..f226baf5 100644
--- a/FlightJournal.Web/Global.asax.cs
+++ b/FlightJournal.Web/Global.asax.cs
@@ -1,9 +1,11 @@
-using System.Web.Http;
+using System.Web.Helpers;
+using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Boerman.AprsClient;
using FlightJournal.Web.App_Start;
+using FlightJournal.Web.Repositories;
using WebGrease.Configuration;
namespace FlightJournal.Web
@@ -27,7 +29,7 @@ protected void Application_Start()
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
- RouteConfig.RegisterRoutes(RouteTable.Routes);
+ RouteConfig.RegisterRoutes(RouteTable.Routes, new ClubRepository(() => new FlightJournal.Web.Models.FlightContext()));
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
diff --git a/FlightJournal.Web/Repositories/ClubRepository.cs b/FlightJournal.Web/Repositories/ClubRepository.cs
new file mode 100644
index 00000000..91321415
--- /dev/null
+++ b/FlightJournal.Web/Repositories/ClubRepository.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Linq;
+using System.Windows.Forms;
+using FlightJournal.Web.Models;
+
+namespace FlightJournal.Web.Repositories
+{
+ public interface IClubRepository
+ {
+ bool ClubExists(string shortName);
+ ///
+ /// Retrieving a club by its short name and creating a new Club object (a clone) and populating its properties with the values from the original club found in the database
+ ///
+ ///
+ ///
+ Club CloneClubByShortName(string shortName);
+ }
+
+ public class ClubRepository : IClubRepository
+ {
+ private readonly Func _dbContextFactory; // Factory function to create FlightContext instances
+
+ public ClubRepository(Func dbContextFactory)
+ {
+ _dbContextFactory = dbContextFactory;
+ }
+
+ public bool ClubExists(string shortName)
+ {
+ using (var dbContext = _dbContextFactory()) // Create and dispose of DbContext within 'using'
+ {
+ return dbContext.Clubs.AsNoTracking().Any(c => c.ShortName == shortName);
+ }
+ }
+
+ public Club CloneClubByShortName(string shortName)
+ {
+ using (var dbContext = _dbContextFactory())
+ {
+ var originalClub = dbContext.Clubs.AsNoTracking().SingleOrDefault(d => d.ShortName == shortName);
+ if (originalClub == null) return null;
+
+ var clubCopy = new Club
+ {
+ ClubId = originalClub.ClubId,
+ Name = originalClub.Name,
+ ShortName = originalClub.ShortName,
+ LocationId = originalClub.LocationId,
+ Location = originalClub.Location,
+ ContactInformation = originalClub.ContactInformation,
+ Website = originalClub.Website
+ };
+
+ return clubCopy;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/FlightJournal.Web/Startup.cs b/FlightJournal.Web/Startup.cs
index 0fd29691..fac854bc 100644
--- a/FlightJournal.Web/Startup.cs
+++ b/FlightJournal.Web/Startup.cs
@@ -13,7 +13,7 @@ public void Configuration(IAppBuilder app)
// will look for SQL connection strings that contain Authentication=Active Directory Interactive. When found, they will use the AzureServiceTokenProvider to fetch an access token to authenticate with Azure SQL Database.
// https://www.pluralsight.com/guides/how-to-use-managed-identity-with-azure-sql-database
System.Data.SqlClient.SqlAuthenticationProvider.SetProvider(System.Data.SqlClient.SqlAuthenticationMethod.ActiveDirectoryInteractive, new SqlAppAuthenticationProvider());
-
+
ConfigureAuth(app);
//ConfigureOpenGliderNetworkFlightLogMonitor(app);
ConfigureAprsDataListener();
diff --git a/FlightJournal.Web/Validators/ClubValidator.cs b/FlightJournal.Web/Validators/ClubValidator.cs
index 2718d05d..bb95be66 100644
--- a/FlightJournal.Web/Validators/ClubValidator.cs
+++ b/FlightJournal.Web/Validators/ClubValidator.cs
@@ -1,6 +1,5 @@
-using System.Linq;
+using FlightJournal.Web.Repositories;
using System.Web;
-using FlightJournal.Web.Models;
namespace FlightJournal.Web.Validators
{
@@ -11,6 +10,12 @@ public interface IClubValidator
public class ClubValidator : IClubValidator
{
+ private readonly IClubRepository _clubRepository;
+ public ClubValidator(IClubRepository clubRepository)
+ {
+ _clubRepository = clubRepository;
+ }
+
public bool IsValid(string club)
{
if (System.Web.HttpContext.Current == null)
@@ -31,10 +36,7 @@ public bool IsValid(string club)
bool Any(string s)
{
- using (var shortDb = new FlightContext())
- {
- return (shortDb.Clubs.Any(d => d.ShortName == s));
- }
+ return _clubRepository.ClubExists(s);
}
}
}