From 2290099f45dcf41362da25de13f3fc1c20b02134 Mon Sep 17 00:00:00 2001 From: Mia Winter Date: Wed, 19 Apr 2023 16:42:24 +0200 Subject: [PATCH] Implemented Inspect on Urls --- CHANGELOG.md | 1 + Pages/Urls.cshtml | 102 ++++++++++++++++++++++++++----------------- Pages/Urls.cshtml.cs | 16 ++++++- 3 files changed, 78 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5a202f..7341eca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Page Titles to Login, Logout and Urls Page - Added Inspect Page, which displays information about a URL and allows to delete it +- Added Inspect Form group to Urls that redirects to Inspect Page ## [1.1.0] - 2023-04-17 diff --git a/Pages/Urls.cshtml b/Pages/Urls.cshtml index d8c3f2c..cdd1f1f 100644 --- a/Pages/Urls.cshtml +++ b/Pages/Urls.cshtml @@ -15,49 +15,71 @@

Urls Administration

+ +
+
+

Inspect URL

- -

New URL

- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
-
- @Html.DropDownListFor(m => m.Model!.ExpirationDate, new List { - new("1 Day", DateTime.UtcNow.AddDays(1).ToBinary().ToString()), - new("1 Week", DateTime.UtcNow.AddDays(7).ToBinary().ToString()), - new("4 Weeks", DateTime.UtcNow.AddDays(4 * 7).ToBinary().ToString()), - new("1 Year", DateTime.UtcNow.AddYears(1).ToBinary().ToString()), - new("Never", DateTime.UtcNow.AddYears(1000).ToBinary().ToString()) - }, "Select Expiration") +
+
+ +
+
+ +
+
+
- -
- -
- -
-
- + +
+ @ModelState["Inspect_Id"]?.Errors.FirstOrDefault()?.ErrorMessage
-
- + + +
+

New URL

+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ @Html.DropDownListFor(m => m.Model!.ExpirationDate, new List { + new("1 Day", DateTime.UtcNow.AddDays(1).ToBinary().ToString()), + new("1 Week", DateTime.UtcNow.AddDays(7).ToBinary().ToString()), + new("4 Weeks", DateTime.UtcNow.AddDays(4 * 7).ToBinary().ToString()), + new("1 Year", DateTime.UtcNow.AddYears(1).ToBinary().ToString()), + new("Never", DateTime.UtcNow.AddYears(1000).ToBinary().ToString()) + }, "Select Expiration") +
+
+ +
+ +
+ +
+
+ +
+
+
+
diff --git a/Pages/Urls.cshtml.cs b/Pages/Urls.cshtml.cs index 0158e8d..54b317f 100644 --- a/Pages/Urls.cshtml.cs +++ b/Pages/Urls.cshtml.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using System.Text.RegularExpressions; using System.Web; +using Microsoft.AspNetCore.Components; using Microsoft.Extensions.Caching.Distributed; namespace JustShortIt.Pages; @@ -27,8 +28,21 @@ public class UrlsModel : PageModel { #endif Db = db; } - + public async Task OnPostInspectAsync() { + string? id = Request.Form["Inspect_Id"]; + if (id is null || string.IsNullOrEmpty(id)) { + ModelState.AddModelError("Inspect_Id", "ID is a required field"); + return Page(); + } + + if (await Db.GetAsync(id) is null) { + ModelState.AddModelError("Inspect_Id", "ID does not exist"); + return Page(); + } + + return RedirectToPage("Inspect", new { Id = id }); + } public async Task OnPostAsync() { if (!ModelState.IsValid) return Page();