diff --git a/MyWebsite/MyWebsite/Controllers/HomeController.cs b/MyWebsite/MyWebsite/Controllers/HomeController.cs index 5dfcbeb..3499852 100644 --- a/MyWebsite/MyWebsite/Controllers/HomeController.cs +++ b/MyWebsite/MyWebsite/Controllers/HomeController.cs @@ -48,7 +48,18 @@ namespace MyWebsite.Controllers )), new CookieOptions { Expires = DateTimeOffset.UtcNow.AddYears(1) }); - return Redirect(Request.Headers["Referer"]); + return Redirect(Extensions.CheckNullOrWhitespace(Request.Headers["Referer"], "/")); + } + + [Route("ComicSans")] + public IActionResult ComicSans() + { + if (Request.Cookies.ContainsKey("useComicSans")) + Response.Cookies.Delete("useComicSans"); + else + Response.Cookies.Append("useComicSans", "true"); + + return Redirect(Extensions.CheckNullOrWhitespace(Request.Headers["Referer"], "/")); } } } \ No newline at end of file diff --git a/MyWebsite/MyWebsite/Helpers/Extensions.cs b/MyWebsite/MyWebsite/Helpers/Extensions.cs index 852d78e..c8f15ed 100644 --- a/MyWebsite/MyWebsite/Helpers/Extensions.cs +++ b/MyWebsite/MyWebsite/Helpers/Extensions.cs @@ -7,5 +7,8 @@ namespace MyWebsite { public static bool Belongs(this T item, params T[] array) => array?.Contains(item) ?? false; + + public static string CheckNullOrWhitespace(string str, string defaultValue) => + string.IsNullOrWhiteSpace(str) ? defaultValue : str; } } \ No newline at end of file diff --git a/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml b/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml index c0a0691..25e2035 100644 --- a/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml +++ b/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml @@ -9,6 +9,16 @@ + @if (Context.Request.Cookies.ContainsKey("useComicSans")) + { + + } +