From 2b6e2e1c4dbb0d8aa8f4a5b1ba14663ceed61b05 Mon Sep 17 00:00:00 2001 From: Mathias Date: Mon, 18 Nov 2024 19:18:11 +0100 Subject: [PATCH 01/19] Add admin pages for managing reviews, user libraries, and user favorites **Create Review** * Add a form to create a new review with fields for `GameId`, `UserId`, `Rating`, and `Content` * Add a submit button to save the review **Edit Review** * Add a form to edit an existing review with fields for `GameId`, `UserId`, `Rating`, and `Content` * Add a submit button to save the changes **Delete Review** * Add a confirmation page to delete a review * Display the review details and a delete button **List Reviews** * Add a table to list all reviews with columns for `GameId`, `UserId`, `Rating`, and `Content` * Add links to edit and delete each review **Create User Library Entry** * Add a form to create a new user library entry with fields for `UserId`, `GameId`, `Status`, and `IsUpcoming` * Add a submit button to save the entry **Edit User Library Entry** * Add a form to edit an existing user library entry with fields for `UserId`, `GameId`, `Status`, and `IsUpcoming` * Add a submit button to save the changes **Delete User Library Entry** * Add a confirmation page to delete a user library entry * Display the entry details and a delete button **List User Library Entries** * Add a table to list all user library entries with columns for `UserId`, `GameId`, `Status`, and `IsUpcoming` * Add links to edit and delete each entry **Create User Favorite Entry** * Add a form to create a new user favorite entry with fields for `UserId` and `GameId` * Add a submit button to save the entry --- GameLibrary/Pages/Admin/Dashboard.cshtml | 108 ++++++++++++++++++ GameLibrary/Pages/Admin/Dashboard.cshtml.cs | 44 +++++++ GameLibrary/Pages/Admin/Index.cshtml | 18 +++ GameLibrary/Pages/Admin/Index.cshtml.cs | 34 ++++++ GameLibrary/Pages/Admin/Reviews/Create.cshtml | 55 +++++++++ .../Pages/Admin/Reviews/Create.cshtml.cs | 42 +++++++ GameLibrary/Pages/Admin/Reviews/Delete.cshtml | 53 +++++++++ .../Pages/Admin/Reviews/Delete.cshtml.cs | 54 +++++++++ GameLibrary/Pages/Admin/Reviews/Edit.cshtml | 56 +++++++++ .../Pages/Admin/Reviews/Edit.cshtml.cs | 71 ++++++++++++ GameLibrary/Pages/Admin/Reviews/Index.cshtml | 46 ++++++++ .../Pages/Admin/Reviews/Index.cshtml.cs | 26 +++++ GameLibrary/Pages/Admin/Roles/Create.cshtml | 20 ++++ .../Pages/Admin/Roles/Create.cshtml.cs | 37 ++++++ GameLibrary/Pages/Admin/Roles/Delete.cshtml | 29 +++++ .../Pages/Admin/Roles/Delete.cshtml.cs | 54 +++++++++ GameLibrary/Pages/Admin/Roles/Edit.cshtml | 20 ++++ GameLibrary/Pages/Admin/Roles/Edit.cshtml.cs | 68 +++++++++++ GameLibrary/Pages/Admin/Roles/Index.cshtml | 33 ++++++ GameLibrary/Pages/Admin/Roles/Index.cshtml.cs | 23 ++++ .../Pages/Admin/UserFavorites/Create.cshtml | 43 +++++++ .../Admin/UserFavorites/Create.cshtml.cs | 42 +++++++ .../Pages/Admin/UserFavorites/Delete.cshtml | 42 +++++++ .../Admin/UserFavorites/Delete.cshtml.cs | 57 +++++++++ .../Pages/Admin/UserFavorites/Edit.cshtml | 44 +++++++ .../Pages/Admin/UserFavorites/Edit.cshtml.cs | 80 +++++++++++++ .../Pages/Admin/UserFavorites/Index.cshtml | 42 +++++++ .../Pages/Admin/UserFavorites/Index.cshtml.cs | 26 +++++ .../Pages/Admin/UserLibraries/Create.cshtml | 55 +++++++++ .../Admin/UserLibraries/Create.cshtml.cs | 42 +++++++ .../Pages/Admin/UserLibraries/Delete.cshtml | 52 +++++++++ .../Admin/UserLibraries/Delete.cshtml.cs | 57 +++++++++ .../Pages/Admin/UserLibraries/Edit.cshtml | 56 +++++++++ .../Pages/Admin/UserLibraries/Edit.cshtml.cs | 80 +++++++++++++ .../Pages/Admin/UserLibraries/Index.cshtml | 46 ++++++++ .../Pages/Admin/UserLibraries/Index.cshtml.cs | 26 +++++ GameLibrary/Pages/Admin/Users/Create.cshtml | 45 ++++++++ .../Pages/Admin/Users/Create.cshtml.cs | 65 +++++++++++ GameLibrary/Pages/Admin/Users/Delete.cshtml | 42 +++++++ .../Pages/Admin/Users/Delete.cshtml.cs | 67 +++++++++++ GameLibrary/Pages/Admin/Users/Edit.cshtml | 45 ++++++++ GameLibrary/Pages/Admin/Users/Edit.cshtml.cs | 89 +++++++++++++++ GameLibrary/Pages/Admin/Users/Index.cshtml | 40 +++++++ GameLibrary/Pages/Admin/Users/Index.cshtml.cs | 23 ++++ 44 files changed, 2097 insertions(+) create mode 100644 GameLibrary/Pages/Admin/Dashboard.cshtml create mode 100644 GameLibrary/Pages/Admin/Dashboard.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Index.cshtml create mode 100644 GameLibrary/Pages/Admin/Index.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Reviews/Create.cshtml create mode 100644 GameLibrary/Pages/Admin/Reviews/Create.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Reviews/Delete.cshtml create mode 100644 GameLibrary/Pages/Admin/Reviews/Delete.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Reviews/Edit.cshtml create mode 100644 GameLibrary/Pages/Admin/Reviews/Edit.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Reviews/Index.cshtml create mode 100644 GameLibrary/Pages/Admin/Reviews/Index.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Roles/Create.cshtml create mode 100644 GameLibrary/Pages/Admin/Roles/Create.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Roles/Delete.cshtml create mode 100644 GameLibrary/Pages/Admin/Roles/Delete.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Roles/Edit.cshtml create mode 100644 GameLibrary/Pages/Admin/Roles/Edit.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Roles/Index.cshtml create mode 100644 GameLibrary/Pages/Admin/Roles/Index.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/UserFavorites/Create.cshtml create mode 100644 GameLibrary/Pages/Admin/UserFavorites/Create.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/UserFavorites/Delete.cshtml create mode 100644 GameLibrary/Pages/Admin/UserFavorites/Delete.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/UserFavorites/Edit.cshtml create mode 100644 GameLibrary/Pages/Admin/UserFavorites/Edit.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/UserFavorites/Index.cshtml create mode 100644 GameLibrary/Pages/Admin/UserFavorites/Index.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/UserLibraries/Create.cshtml create mode 100644 GameLibrary/Pages/Admin/UserLibraries/Create.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/UserLibraries/Delete.cshtml create mode 100644 GameLibrary/Pages/Admin/UserLibraries/Delete.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/UserLibraries/Edit.cshtml create mode 100644 GameLibrary/Pages/Admin/UserLibraries/Edit.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/UserLibraries/Index.cshtml create mode 100644 GameLibrary/Pages/Admin/UserLibraries/Index.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Users/Create.cshtml create mode 100644 GameLibrary/Pages/Admin/Users/Create.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Users/Delete.cshtml create mode 100644 GameLibrary/Pages/Admin/Users/Delete.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Users/Edit.cshtml create mode 100644 GameLibrary/Pages/Admin/Users/Edit.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/Users/Index.cshtml create mode 100644 GameLibrary/Pages/Admin/Users/Index.cshtml.cs diff --git a/GameLibrary/Pages/Admin/Dashboard.cshtml b/GameLibrary/Pages/Admin/Dashboard.cshtml new file mode 100644 index 0000000..e85799a --- /dev/null +++ b/GameLibrary/Pages/Admin/Dashboard.cshtml @@ -0,0 +1,108 @@ +@page +@model GameLibrary.Pages.Admin.DashboardModel + +@{ + ViewData["Title"] = "Dashboard"; +} + +

Admin Dashboard

+ +
+
+
+
Total Games
+
+
@Model.TotalGames
+
+
+
+
+
+
Total Reviews
+
+
@Model.TotalReviews
+
+
+
+
+
+
Total Users
+
+
@Model.TotalUsers
+
+
+
+
+
+
Total Favorites
+
+
@Model.TotalFavorites
+
+
+
+
+ +
+
+

Game Genres

+ +
+
+

User Activity

+ +
+
+ +
+
+

Review Ratings

+ +
+
+ +@section Scripts { + + +} diff --git a/GameLibrary/Pages/Admin/Dashboard.cshtml.cs b/GameLibrary/Pages/Admin/Dashboard.cshtml.cs new file mode 100644 index 0000000..7b4ea33 --- /dev/null +++ b/GameLibrary/Pages/Admin/Dashboard.cshtml.cs @@ -0,0 +1,44 @@ +using GameLibrary.Data; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin; + +public class DashboardModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public DashboardModel(ApplicationDbContext context) + { + _context = context; + } + + public int TotalGames { get; set; } + public int TotalReviews { get; set; } + public int TotalUsers { get; set; } + public int TotalFavorites { get; set; } + + public Dictionary GameGenres { get; set; } = new(); + public Dictionary UserActivity { get; set; } = new(); + public Dictionary ReviewRatings { get; set; } = new(); + + public async Task OnGetAsync() + { + TotalGames = await _context.Games.CountAsync(); + TotalReviews = await _context.Reviews.CountAsync(); + TotalUsers = await _context.Users.CountAsync(); + TotalFavorites = await _context.UserFavorites.CountAsync(); + + GameGenres = await _context.Games + .GroupBy(g => g.Genre) + .ToDictionaryAsync(g => g.Key, g => g.Count()); + + UserActivity = await _context.Users + .GroupBy(u => u.CreatedAt.Date) + .ToDictionaryAsync(u => u.Key.ToString("yyyy-MM-dd"), u => u.Count()); + + ReviewRatings = await _context.Reviews + .GroupBy(r => r.Rating) + .ToDictionaryAsync(r => r.Key, r => r.Count()); + } +} diff --git a/GameLibrary/Pages/Admin/Index.cshtml b/GameLibrary/Pages/Admin/Index.cshtml new file mode 100644 index 0000000..05fd7c2 --- /dev/null +++ b/GameLibrary/Pages/Admin/Index.cshtml @@ -0,0 +1,18 @@ +@page +@model GameLibrary.Pages.Admin.IndexModel + +@{ + ViewData["Title"] = "Admin Index"; +} + +

Admin Index

+ + diff --git a/GameLibrary/Pages/Admin/Index.cshtml.cs b/GameLibrary/Pages/Admin/Index.cshtml.cs new file mode 100644 index 0000000..2aaf07b --- /dev/null +++ b/GameLibrary/Pages/Admin/Index.cshtml.cs @@ -0,0 +1,34 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace GameLibrary.Pages.Admin; + +public class IndexModel : PageModel +{ + public List NavigationLinks { get; set; } = new(); + + public void OnGet() + { + NavigationLinks.Add("Dashboard"); + NavigationLinks.Add("Games"); + NavigationLinks.Add("Reviews"); + NavigationLinks.Add("User Libraries"); + NavigationLinks.Add("User Favorites"); + NavigationLinks.Add("Users"); + NavigationLinks.Add("Roles"); + } + + public IActionResult OnPostNavigate(string link) + { + return link switch + { + "Dashboard" => RedirectToPage("Dashboard"), + "Games" => RedirectToPage("Games/Index"), + "Reviews" => RedirectToPage("Reviews/Index"), + "User Libraries" => RedirectToPage("UserLibraries/Index"), + "User Favorites" => RedirectToPage("UserFavorites/Index"), + "Users" => RedirectToPage("Users/Index"), + "Roles" => RedirectToPage("Roles/Index"), + _ => Page() + }; + } +} diff --git a/GameLibrary/Pages/Admin/Reviews/Create.cshtml b/GameLibrary/Pages/Admin/Reviews/Create.cshtml new file mode 100644 index 0000000..bec443d --- /dev/null +++ b/GameLibrary/Pages/Admin/Reviews/Create.cshtml @@ -0,0 +1,55 @@ +@page +@model GameLibrary.Pages.Admin.Reviews.CreateModel + +@{ + ViewData["Title"] = "Create Review"; +} + + + +
+

Create Review

+
+ +
+
+
+
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + Back to List +
+
+
+
+ + diff --git a/GameLibrary/Pages/Admin/Reviews/Create.cshtml.cs b/GameLibrary/Pages/Admin/Reviews/Create.cshtml.cs new file mode 100644 index 0000000..bbaae3d --- /dev/null +++ b/GameLibrary/Pages/Admin/Reviews/Create.cshtml.cs @@ -0,0 +1,42 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.Reviews; + +public class CreateModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public CreateModel(ApplicationDbContext context) + { + _context = context; + } + + public IActionResult OnGet() + { + ViewData["Games"] = new SelectList(_context.Games, "Id", "Title"); + ViewData["Users"] = new SelectList(_context.Users, "Id", "UserName"); + return Page(); + } + + [BindProperty] + public Review? Review { get; set; } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + Review!.CreatedAt = DateTime.UtcNow; + _context.Reviews.Add(Review); + await _context.SaveChangesAsync(); + + return RedirectToPage("./Index"); + } +} diff --git a/GameLibrary/Pages/Admin/Reviews/Delete.cshtml b/GameLibrary/Pages/Admin/Reviews/Delete.cshtml new file mode 100644 index 0000000..d3f4e18 --- /dev/null +++ b/GameLibrary/Pages/Admin/Reviews/Delete.cshtml @@ -0,0 +1,53 @@ +@page +@model GameLibrary.Pages.Admin.Reviews.DeleteModel + +@{ + ViewData["Title"] = "Delete Review"; +} + + + +
+

Delete Review

+

Are you sure you want to delete this review?

+
+ +
+
+
+
+ @Html.DisplayNameFor(model => model.Review!.GameId) +
+
+ @Html.DisplayFor(model => model.Review!.GameId) +
+
+ @Html.DisplayNameFor(model => model.Review!.UserId) +
+
+ @Html.DisplayFor(model => model.Review!.UserId) +
+
+ @Html.DisplayNameFor(model => model.Review!.Rating) +
+
+ @Html.DisplayFor(model => model.Review!.Rating) +
+
+ @Html.DisplayNameFor(model => model.Review!.Content) +
+
+ @Html.DisplayFor(model => model.Review!.Content) +
+
+
+
+ +
+
+ + + Back to List +
+
+ diff --git a/GameLibrary/Pages/Admin/Reviews/Delete.cshtml.cs b/GameLibrary/Pages/Admin/Reviews/Delete.cshtml.cs new file mode 100644 index 0000000..2db232f --- /dev/null +++ b/GameLibrary/Pages/Admin/Reviews/Delete.cshtml.cs @@ -0,0 +1,54 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.Reviews; + +public class DeleteModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public DeleteModel(ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public Review? Review { get; set; } + + public async Task OnGetAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + Review = await _context.Reviews.FirstOrDefaultAsync(m => m.Id == id); + + if (Review == null) + { + return NotFound(); + } + return Page(); + } + + public async Task OnPostAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + Review = await _context.Reviews.FindAsync(id); + + if (Review != null) + { + _context.Reviews.Remove(Review); + await _context.SaveChangesAsync(); + } + + return RedirectToPage("./Index"); + } +} diff --git a/GameLibrary/Pages/Admin/Reviews/Edit.cshtml b/GameLibrary/Pages/Admin/Reviews/Edit.cshtml new file mode 100644 index 0000000..972a36e --- /dev/null +++ b/GameLibrary/Pages/Admin/Reviews/Edit.cshtml @@ -0,0 +1,56 @@ +@page +@model GameLibrary.Pages.Admin.Reviews.EditModel + +@{ + ViewData["Title"] = "Edit Review"; +} + + + +
+

Edit Review

+
+ +
+
+
+
+ + +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + Back to List +
+
+
+
+ + diff --git a/GameLibrary/Pages/Admin/Reviews/Edit.cshtml.cs b/GameLibrary/Pages/Admin/Reviews/Edit.cshtml.cs new file mode 100644 index 0000000..85953d5 --- /dev/null +++ b/GameLibrary/Pages/Admin/Reviews/Edit.cshtml.cs @@ -0,0 +1,71 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.Reviews; + +public class EditModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public EditModel(ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public Review? Review { get; set; } + + public SelectList Games { get; set; } = null!; + public SelectList Users { get; set; } = null!; + + public async Task OnGetAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + Review = await _context.Reviews.FirstOrDefaultAsync(m => m.Id == id); + + if (Review == null) + { + return NotFound(); + } + + Games = new SelectList(await _context.Games.ToListAsync(), "Id", "Title"); + Users = new SelectList(await _context.Users.ToListAsync(), "Id", "UserName"); + + return Page(); + } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + var reviewToUpdate = await _context.Reviews.FindAsync(Review!.Id); + + if (reviewToUpdate == null) + { + return NotFound(); + } + + if (await TryUpdateModelAsync( + reviewToUpdate, + "review", + r => r.GameId, r => r.UserId, r => r.Rating, r => r.Content)) + { + reviewToUpdate.UpdatedAt = DateTime.UtcNow; + await _context.SaveChangesAsync(); + return RedirectToPage("./Index"); + } + + return Page(); + } +} diff --git a/GameLibrary/Pages/Admin/Reviews/Index.cshtml b/GameLibrary/Pages/Admin/Reviews/Index.cshtml new file mode 100644 index 0000000..528c1cb --- /dev/null +++ b/GameLibrary/Pages/Admin/Reviews/Index.cshtml @@ -0,0 +1,46 @@ +@page +@model GameLibrary.Pages.Admin.Reviews.IndexModel + +@{ + ViewData["Title"] = "Reviews"; +} + + + +
+

Reviews

+

+ Create New +

+
+ +
+ + + + + + + + + + + + @foreach (var item in Model.Reviews!) + { + + + + + + + + } + +
GameUserRatingContentActions
@Html.DisplayFor(modelItem => item.GameId)@Html.DisplayFor(modelItem => item.UserId)@Html.DisplayFor(modelItem => item.Rating)@Html.DisplayFor(modelItem => item.Content) + Edit

+ Delete +
+
+ + diff --git a/GameLibrary/Pages/Admin/Reviews/Index.cshtml.cs b/GameLibrary/Pages/Admin/Reviews/Index.cshtml.cs new file mode 100644 index 0000000..9f6d00d --- /dev/null +++ b/GameLibrary/Pages/Admin/Reviews/Index.cshtml.cs @@ -0,0 +1,26 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.Reviews; + +public class IndexModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public IndexModel(ApplicationDbContext context) + { + _context = context; + } + + public IList? Reviews { get; set; } + + public async Task OnGetAsync() + { + Reviews = await _context.Reviews + .Include(r => r.Game) + .Include(r => r.User) + .ToListAsync(); + } +} diff --git a/GameLibrary/Pages/Admin/Roles/Create.cshtml b/GameLibrary/Pages/Admin/Roles/Create.cshtml new file mode 100644 index 0000000..86e303c --- /dev/null +++ b/GameLibrary/Pages/Admin/Roles/Create.cshtml @@ -0,0 +1,20 @@ +@page +@model GameLibrary.Pages.Admin.Roles.CreateModel + +@{ + ViewData["Title"] = "Create Role"; +} + +

Create Role

+ +
+
+ + + +
+
+ + Back to List +
+
diff --git a/GameLibrary/Pages/Admin/Roles/Create.cshtml.cs b/GameLibrary/Pages/Admin/Roles/Create.cshtml.cs new file mode 100644 index 0000000..9b347e5 --- /dev/null +++ b/GameLibrary/Pages/Admin/Roles/Create.cshtml.cs @@ -0,0 +1,37 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace GameLibrary.Pages.Admin.Roles; + +public class CreateModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public CreateModel(ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public Role Role { get; set; } = new Role(); + + public IActionResult OnGet() + { + return Page(); + } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + _context.Roles.Add(Role); + await _context.SaveChangesAsync(); + + return RedirectToPage("./Index"); + } +} diff --git a/GameLibrary/Pages/Admin/Roles/Delete.cshtml b/GameLibrary/Pages/Admin/Roles/Delete.cshtml new file mode 100644 index 0000000..1f19f10 --- /dev/null +++ b/GameLibrary/Pages/Admin/Roles/Delete.cshtml @@ -0,0 +1,29 @@ +@page +@model GameLibrary.Pages.Admin.Roles.DeleteModel + +@{ + ViewData["Title"] = "Delete Role"; +} + +

Delete Role

+ +

Are you sure you want to delete this role?

+ +
+

Role

+
+
+
+ @Html.DisplayNameFor(model => model.Role.Name) +
+
+ @Html.DisplayFor(model => model.Role.Name) +
+
+ +
+ + + Back to List +
+
diff --git a/GameLibrary/Pages/Admin/Roles/Delete.cshtml.cs b/GameLibrary/Pages/Admin/Roles/Delete.cshtml.cs new file mode 100644 index 0000000..bad4e37 --- /dev/null +++ b/GameLibrary/Pages/Admin/Roles/Delete.cshtml.cs @@ -0,0 +1,54 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.Roles; + +public class DeleteModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public DeleteModel(ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public Role? Role { get; set; } + + public async Task OnGetAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + Role = await _context.Roles.FirstOrDefaultAsync(m => m.Id == id); + + if (Role == null) + { + return NotFound(); + } + return Page(); + } + + public async Task OnPostAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + Role = await _context.Roles.FindAsync(id); + + if (Role != null) + { + _context.Roles.Remove(Role); + await _context.SaveChangesAsync(); + } + + return RedirectToPage("./Index"); + } +} diff --git a/GameLibrary/Pages/Admin/Roles/Edit.cshtml b/GameLibrary/Pages/Admin/Roles/Edit.cshtml new file mode 100644 index 0000000..4579660 --- /dev/null +++ b/GameLibrary/Pages/Admin/Roles/Edit.cshtml @@ -0,0 +1,20 @@ +@page +@model GameLibrary.Pages.Admin.Roles.EditModel + +@{ + ViewData["Title"] = "Edit Role"; +} + +

Edit Role

+ +
+
+ + + +
+
+ + Back to List +
+
diff --git a/GameLibrary/Pages/Admin/Roles/Edit.cshtml.cs b/GameLibrary/Pages/Admin/Roles/Edit.cshtml.cs new file mode 100644 index 0000000..5c29b67 --- /dev/null +++ b/GameLibrary/Pages/Admin/Roles/Edit.cshtml.cs @@ -0,0 +1,68 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace GameLibrary.Pages.Admin.Roles; + +public class EditModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public EditModel(ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public Role Role { get; set; } = new Role(); + + public async Task OnGetAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + Role = await _context.Roles.FindAsync(id); + + if (Role == null) + { + return NotFound(); + } + return Page(); + } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + _context.Attach(Role).State = Microsoft.EntityFrameworkCore.EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!RoleExists(Role.Id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return RedirectToPage("./Index"); + } + + private bool RoleExists(Guid id) + { + return _context.Roles.Any(e => e.Id == id); + } +} diff --git a/GameLibrary/Pages/Admin/Roles/Index.cshtml b/GameLibrary/Pages/Admin/Roles/Index.cshtml new file mode 100644 index 0000000..6170098 --- /dev/null +++ b/GameLibrary/Pages/Admin/Roles/Index.cshtml @@ -0,0 +1,33 @@ +@page +@model GameLibrary.Pages.Admin.Roles.IndexModel + +@{ + ViewData["Title"] = "Roles"; +} + +

Roles

+ +

+ Create New Role +

+ + + + + + + + + + @foreach (var role in Model.Roles) + { + + + + + } + +
NameActions
@role.Name + Edit + Delete +
diff --git a/GameLibrary/Pages/Admin/Roles/Index.cshtml.cs b/GameLibrary/Pages/Admin/Roles/Index.cshtml.cs new file mode 100644 index 0000000..13168c6 --- /dev/null +++ b/GameLibrary/Pages/Admin/Roles/Index.cshtml.cs @@ -0,0 +1,23 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.Roles; + +public class IndexModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public IndexModel(ApplicationDbContext context) + { + _context = context; + } + + public IList? Roles { get; set; } + + public async Task OnGetAsync() + { + Roles = await _context.Roles.ToListAsync(); + } +} diff --git a/GameLibrary/Pages/Admin/UserFavorites/Create.cshtml b/GameLibrary/Pages/Admin/UserFavorites/Create.cshtml new file mode 100644 index 0000000..86222b9 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserFavorites/Create.cshtml @@ -0,0 +1,43 @@ +@page +@model GameLibrary.Pages.Admin.UserFavorites.CreateModel + +@{ + ViewData["Title"] = "Create User Favorite Entry"; +} + + + +
+

Create User Favorite Entry

+
+ +
+
+
+
+ +
+ + + +
+ +
+ + + +
+ +
+ + Back to List +
+
+
+
+ + diff --git a/GameLibrary/Pages/Admin/UserFavorites/Create.cshtml.cs b/GameLibrary/Pages/Admin/UserFavorites/Create.cshtml.cs new file mode 100644 index 0000000..e731e8c --- /dev/null +++ b/GameLibrary/Pages/Admin/UserFavorites/Create.cshtml.cs @@ -0,0 +1,42 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.UserFavorites; + +public class CreateModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public CreateModel(ApplicationDbContext context) + { + _context = context; + } + + public IActionResult OnGet() + { + ViewData["Games"] = new SelectList(_context.Games, "Id", "Title"); + ViewData["Users"] = new SelectList(_context.Users, "Id", "UserName"); + return Page(); + } + + [BindProperty] + public UserFavorite? UserFavorite { get; set; } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + UserFavorite!.AddedAt = DateTime.UtcNow; + _context.UserFavorites.Add(UserFavorite); + await _context.SaveChangesAsync(); + + return RedirectToPage("./Index"); + } +} diff --git a/GameLibrary/Pages/Admin/UserFavorites/Delete.cshtml b/GameLibrary/Pages/Admin/UserFavorites/Delete.cshtml new file mode 100644 index 0000000..544c9a0 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserFavorites/Delete.cshtml @@ -0,0 +1,42 @@ +@page +@model GameLibrary.Pages.Admin.UserFavorites.DeleteModel + +@{ + ViewData["Title"] = "Delete User Favorite Entry"; +} + + + +
+

Delete User Favorite Entry

+

Are you sure you want to delete this user favorite entry?

+
+ +
+
+
+
+ @Html.DisplayNameFor(model => model.UserFavorite!.UserId) +
+
+ @Html.DisplayFor(model => model.UserFavorite!.UserId) +
+
+ @Html.DisplayNameFor(model => model.UserFavorite!.GameId) +
+
+ @Html.DisplayFor(model => model.UserFavorite!.GameId) +
+
+
+
+ +
+
+ + + Back to List +
+
+ + diff --git a/GameLibrary/Pages/Admin/UserFavorites/Delete.cshtml.cs b/GameLibrary/Pages/Admin/UserFavorites/Delete.cshtml.cs new file mode 100644 index 0000000..9aeceb8 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserFavorites/Delete.cshtml.cs @@ -0,0 +1,57 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.UserFavorites; + +public class DeleteModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public DeleteModel(ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public UserFavorite? UserFavorite { get; set; } + + public async Task OnGetAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + UserFavorite = await _context.UserFavorites + .Include(uf => uf.Game) + .Include(uf => uf.User) + .FirstOrDefaultAsync(m => m.Id == id); + + if (UserFavorite == null) + { + return NotFound(); + } + return Page(); + } + + public async Task OnPostAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + UserFavorite = await _context.UserFavorites.FindAsync(id); + + if (UserFavorite != null) + { + _context.UserFavorites.Remove(UserFavorite); + await _context.SaveChangesAsync(); + } + + return RedirectToPage("./Index"); + } +} diff --git a/GameLibrary/Pages/Admin/UserFavorites/Edit.cshtml b/GameLibrary/Pages/Admin/UserFavorites/Edit.cshtml new file mode 100644 index 0000000..a388085 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserFavorites/Edit.cshtml @@ -0,0 +1,44 @@ +@page +@model GameLibrary.Pages.Admin.UserFavorites.EditModel + +@{ + ViewData["Title"] = "Edit User Favorite Entry"; +} + + + +
+

Edit User Favorite Entry

+
+ +
+
+
+
+ + +
+ + + +
+ +
+ + + +
+ +
+ + Back to List +
+
+
+
+ + diff --git a/GameLibrary/Pages/Admin/UserFavorites/Edit.cshtml.cs b/GameLibrary/Pages/Admin/UserFavorites/Edit.cshtml.cs new file mode 100644 index 0000000..2dd62ca --- /dev/null +++ b/GameLibrary/Pages/Admin/UserFavorites/Edit.cshtml.cs @@ -0,0 +1,80 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.UserFavorites; + +public class EditModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public EditModel(ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public UserFavorite? UserFavorite { get; set; } + + public SelectList? Games { get; set; } + public SelectList? Users { get; set; } + + public async Task OnGetAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + UserFavorite = await _context.UserFavorites + .Include(uf => uf.Game) + .Include(uf => uf.User) + .FirstOrDefaultAsync(m => m.Id == id); + + if (UserFavorite == null) + { + return NotFound(); + } + + Games = new SelectList(_context.Games, "Id", "Title"); + Users = new SelectList(_context.Users, "Id", "UserName"); + + return Page(); + } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + _context.Attach(UserFavorite!).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!UserFavoriteExists(UserFavorite!.Id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return RedirectToPage("./Index"); + } + + private bool UserFavoriteExists(Guid id) + { + return _context.UserFavorites.Any(e => e.Id == id); + } +} diff --git a/GameLibrary/Pages/Admin/UserFavorites/Index.cshtml b/GameLibrary/Pages/Admin/UserFavorites/Index.cshtml new file mode 100644 index 0000000..a9d6522 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserFavorites/Index.cshtml @@ -0,0 +1,42 @@ +@page +@model GameLibrary.Pages.Admin.UserFavorites.IndexModel + +@{ + ViewData["Title"] = "User Favorite Entries"; +} + + + +
+

User Favorite Entries

+

+ Create New +

+
+ +
+ + + + + + + + + + @foreach (var item in Model.UserFavorites!) + { + + + + + + } + +
UserGameActions
@Html.DisplayFor(modelItem => item.User.UserName)@Html.DisplayFor(modelItem => item.Game.Title) + Edit + Delete +
+
+ + diff --git a/GameLibrary/Pages/Admin/UserFavorites/Index.cshtml.cs b/GameLibrary/Pages/Admin/UserFavorites/Index.cshtml.cs new file mode 100644 index 0000000..b368acc --- /dev/null +++ b/GameLibrary/Pages/Admin/UserFavorites/Index.cshtml.cs @@ -0,0 +1,26 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.UserFavorites; + +public class IndexModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public IndexModel(ApplicationDbContext context) + { + _context = context; + } + + public IList? UserFavorites { get; set; } + + public async Task OnGetAsync() + { + UserFavorites = await _context.UserFavorites + .Include(uf => uf.Game) + .Include(uf => uf.User) + .ToListAsync(); + } +} diff --git a/GameLibrary/Pages/Admin/UserLibraries/Create.cshtml b/GameLibrary/Pages/Admin/UserLibraries/Create.cshtml new file mode 100644 index 0000000..602b1c0 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserLibraries/Create.cshtml @@ -0,0 +1,55 @@ +@page +@model GameLibrary.Pages.Admin.UserLibraries.CreateModel + +@{ + ViewData["Title"] = "Create User Library Entry"; +} + + + +
+

Create User Library Entry

+
+ +
+
+
+
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + Back to List +
+
+
+
+ + diff --git a/GameLibrary/Pages/Admin/UserLibraries/Create.cshtml.cs b/GameLibrary/Pages/Admin/UserLibraries/Create.cshtml.cs new file mode 100644 index 0000000..14dd0ab --- /dev/null +++ b/GameLibrary/Pages/Admin/UserLibraries/Create.cshtml.cs @@ -0,0 +1,42 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.UserLibraries; + +public class CreateModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public CreateModel(ApplicationDbContext context) + { + _context = context; + } + + public IActionResult OnGet() + { + ViewData["Games"] = new SelectList(_context.Games, "Id", "Title"); + ViewData["Users"] = new SelectList(_context.Users, "Id", "UserName"); + return Page(); + } + + [BindProperty] + public UserLibrary? UserLibrary { get; set; } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + UserLibrary!.AddedDate = DateTime.UtcNow; + _context.UserLibraries.Add(UserLibrary); + await _context.SaveChangesAsync(); + + return RedirectToPage("./Index"); + } +} diff --git a/GameLibrary/Pages/Admin/UserLibraries/Delete.cshtml b/GameLibrary/Pages/Admin/UserLibraries/Delete.cshtml new file mode 100644 index 0000000..fef5724 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserLibraries/Delete.cshtml @@ -0,0 +1,52 @@ +@page +@model GameLibrary.Pages.Admin.UserLibraries.DeleteModel + +@{ + ViewData["Title"] = "Delete User Library Entry"; +} + + +
+

Delete User Library Entry

+

Are you sure you want to delete this entry?

+
+ +
+
+
+
+ @Html.DisplayNameFor(model => model.UserLibrary!.UserId) +
+
+ @Html.DisplayFor(model => model.UserLibrary!.UserId) +
+
+ @Html.DisplayNameFor(model => model.UserLibrary!.GameId) +
+
+ @Html.DisplayFor(model => model.UserLibrary!.GameId) +
+
+ @Html.DisplayNameFor(model => model.UserLibrary!.Status) +
+
+ @Html.DisplayFor(model => model.UserLibrary!.Status) +
+
+ @Html.DisplayNameFor(model => model.UserLibrary!.IsUpcoming) +
+
+ @Html.DisplayFor(model => model.UserLibrary!.IsUpcoming) +
+
+
+
+ +
+
+ + + Back to List +
+
+ diff --git a/GameLibrary/Pages/Admin/UserLibraries/Delete.cshtml.cs b/GameLibrary/Pages/Admin/UserLibraries/Delete.cshtml.cs new file mode 100644 index 0000000..05116e9 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserLibraries/Delete.cshtml.cs @@ -0,0 +1,57 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.UserLibraries; + +public class DeleteModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public DeleteModel(ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public UserLibrary? UserLibrary { get; set; } + + public async Task OnGetAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + UserLibrary = await _context.UserLibraries + .Include(ul => ul.Game) + .Include(ul => ul.User) + .FirstOrDefaultAsync(m => m.Id == id); + + if (UserLibrary == null) + { + return NotFound(); + } + return Page(); + } + + public async Task OnPostAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + UserLibrary = await _context.UserLibraries.FindAsync(id); + + if (UserLibrary != null) + { + _context.UserLibraries.Remove(UserLibrary); + await _context.SaveChangesAsync(); + } + + return RedirectToPage("./Index"); + } +} diff --git a/GameLibrary/Pages/Admin/UserLibraries/Edit.cshtml b/GameLibrary/Pages/Admin/UserLibraries/Edit.cshtml new file mode 100644 index 0000000..f6fad91 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserLibraries/Edit.cshtml @@ -0,0 +1,56 @@ +@page +@model GameLibrary.Pages.Admin.UserLibraries.EditModel + +@{ + ViewData["Title"] = "Edit User Library Entry"; +} + + + +
+

Edit User Library Entry

+
+ +
+
+
+
+ + +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + Back to List +
+
+
+
+ + diff --git a/GameLibrary/Pages/Admin/UserLibraries/Edit.cshtml.cs b/GameLibrary/Pages/Admin/UserLibraries/Edit.cshtml.cs new file mode 100644 index 0000000..918cadb --- /dev/null +++ b/GameLibrary/Pages/Admin/UserLibraries/Edit.cshtml.cs @@ -0,0 +1,80 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.UserLibraries; + +public class EditModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public EditModel(ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public UserLibrary? UserLibrary { get; set; } + + public SelectList? Games { get; set; } + public SelectList? Users { get; set; } + + public async Task OnGetAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + UserLibrary = await _context.UserLibraries + .Include(ul => ul.Game) + .Include(ul => ul.User) + .FirstOrDefaultAsync(m => m.Id == id); + + if (UserLibrary == null) + { + return NotFound(); + } + + Games = new SelectList(_context.Games, "Id", "Title"); + Users = new SelectList(_context.Users, "Id", "UserName"); + + return Page(); + } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + _context.Attach(UserLibrary!).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!UserLibraryExists(UserLibrary!.Id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return RedirectToPage("./Index"); + } + + private bool UserLibraryExists(Guid id) + { + return _context.UserLibraries.Any(e => e.Id == id); + } +} diff --git a/GameLibrary/Pages/Admin/UserLibraries/Index.cshtml b/GameLibrary/Pages/Admin/UserLibraries/Index.cshtml new file mode 100644 index 0000000..39321a2 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserLibraries/Index.cshtml @@ -0,0 +1,46 @@ +@page +@model GameLibrary.Pages.Admin.UserLibraries.IndexModel + +@{ + ViewData["Title"] = "User Libraries"; +} + + +
+
+

User Libraries


+ +

+ Create New +

+
+ +
+ + + + + + + + + @foreach (var item in Model.UserLibraries!) + { + + + + + } + +
User Library DetailsActions
+ User: @Html.DisplayFor(modelItem => item.UserId)
+ Game: @Html.DisplayFor(modelItem => item.GameId)
+ Status: @Html.DisplayFor(modelItem => item.Status)
+ Is Upcoming: @Html.DisplayFor(modelItem => item.IsUpcoming) +
+ Edit

+ Delete +
+
+
+ diff --git a/GameLibrary/Pages/Admin/UserLibraries/Index.cshtml.cs b/GameLibrary/Pages/Admin/UserLibraries/Index.cshtml.cs new file mode 100644 index 0000000..27612e8 --- /dev/null +++ b/GameLibrary/Pages/Admin/UserLibraries/Index.cshtml.cs @@ -0,0 +1,26 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.UserLibraries; + +public class IndexModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public IndexModel(ApplicationDbContext context) + { + _context = context; + } + + public IList? UserLibraries { get; set; } + + public async Task OnGetAsync() + { + UserLibraries = await _context.UserLibraries + .Include(ul => ul.Game) + .Include(ul => ul.User) + .ToListAsync(); + } +} diff --git a/GameLibrary/Pages/Admin/Users/Create.cshtml b/GameLibrary/Pages/Admin/Users/Create.cshtml new file mode 100644 index 0000000..781c0f1 --- /dev/null +++ b/GameLibrary/Pages/Admin/Users/Create.cshtml @@ -0,0 +1,45 @@ +@page +@model GameLibrary.Pages.Admin.Users.CreateModel + +@{ + ViewData["Title"] = "Create User"; +} + + + +
+

Create User

+
+ +
+
+
+
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + Back to List +
+
+
+
+ + diff --git a/GameLibrary/Pages/Admin/Users/Create.cshtml.cs b/GameLibrary/Pages/Admin/Users/Create.cshtml.cs new file mode 100644 index 0000000..f3f3971 --- /dev/null +++ b/GameLibrary/Pages/Admin/Users/Create.cshtml.cs @@ -0,0 +1,65 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Identity; + +namespace GameLibrary.Pages.Admin.Users; + +public class CreateModel : PageModel +{ + private readonly ApplicationDbContext _context; + private readonly UserManager _userManager; + + public CreateModel(ApplicationDbContext context, UserManager userManager) + { + _context = context; + _userManager = userManager; + } + + public IActionResult OnGet() + { + User = new User + { + UserName = "", + Email = "", + CreatedAt = DateTime.UtcNow + }; + return Page(); + } + + [BindProperty] + public User? User { get; set; } + + [BindProperty] + public string? Password { get; set; } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + var user = new User + { + UserName = User!.UserName, + Email = User.Email, + CreatedAt = DateTime.UtcNow + }; + + var result = await _userManager.CreateAsync(user, Password!); + + if (result.Succeeded) + { + return RedirectToPage("./Index"); + } + + foreach (var error in result.Errors) + { + ModelState.AddModelError(string.Empty, error.Description); + } + + return Page(); + } +} diff --git a/GameLibrary/Pages/Admin/Users/Delete.cshtml b/GameLibrary/Pages/Admin/Users/Delete.cshtml new file mode 100644 index 0000000..44e7c20 --- /dev/null +++ b/GameLibrary/Pages/Admin/Users/Delete.cshtml @@ -0,0 +1,42 @@ +@page +@model GameLibrary.Pages.Admin.Users.DeleteModel + +@{ + ViewData["Title"] = "Delete User"; +} + + + +
+

Delete User

+

Are you sure you want to delete this user?

+
+ +
+
+
+
+ @Html.DisplayNameFor(model => model.User!.UserName) +
+
+ @Html.DisplayFor(model => model.User!.UserName) +
+
+ @Html.DisplayNameFor(model => model.User!.Email) +
+
+ @Html.DisplayFor(model => model.User!.Email) +
+
+
+
+ +
+
+ + + Back to List +
+
+ + diff --git a/GameLibrary/Pages/Admin/Users/Delete.cshtml.cs b/GameLibrary/Pages/Admin/Users/Delete.cshtml.cs new file mode 100644 index 0000000..fb3e454 --- /dev/null +++ b/GameLibrary/Pages/Admin/Users/Delete.cshtml.cs @@ -0,0 +1,67 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.Users; + +public class DeleteModel : PageModel +{ + private readonly ApplicationDbContext _context; + private readonly UserManager _userManager; + + public DeleteModel(ApplicationDbContext context, UserManager userManager) + { + _context = context; + _userManager = userManager; + } + + [BindProperty] + public User? User { get; set; } + + public async Task OnGetAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + User = await _userManager.Users.FirstOrDefaultAsync(u => u.Id == id); + + if (User == null) + { + return NotFound(); + } + + return Page(); + } + + public async Task OnPostAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + User = await _userManager.Users.FindAsync(id); + + if (User != null) + { + var result = await _userManager.DeleteAsync(User); + + if (result.Succeeded) + { + return RedirectToPage("./Index"); + } + + foreach (var error in result.Errors) + { + ModelState.AddModelError(string.Empty, error.Description); + } + } + + return Page(); + } +} diff --git a/GameLibrary/Pages/Admin/Users/Edit.cshtml b/GameLibrary/Pages/Admin/Users/Edit.cshtml new file mode 100644 index 0000000..f7c13b1 --- /dev/null +++ b/GameLibrary/Pages/Admin/Users/Edit.cshtml @@ -0,0 +1,45 @@ +@page +@model GameLibrary.Pages.Admin.Users.EditModel + +@{ + ViewData["Title"] = "Edit User"; +} + + + +
+

Edit User

+
+ +
+
+
+
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + Back to List +
+
+
+
+ + diff --git a/GameLibrary/Pages/Admin/Users/Edit.cshtml.cs b/GameLibrary/Pages/Admin/Users/Edit.cshtml.cs new file mode 100644 index 0000000..e8eb56f --- /dev/null +++ b/GameLibrary/Pages/Admin/Users/Edit.cshtml.cs @@ -0,0 +1,89 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.Users; + +public class EditModel : PageModel +{ + private readonly ApplicationDbContext _context; + private readonly UserManager _userManager; + + public EditModel(ApplicationDbContext context, UserManager userManager) + { + _context = context; + _userManager = userManager; + } + + [BindProperty] + public User? User { get; set; } + + [BindProperty] + public string? Password { get; set; } + + public async Task OnGetAsync(Guid? id) + { + if (id == null) + { + return NotFound(); + } + + User = await _userManager.Users.FirstOrDefaultAsync(u => u.Id == id); + + if (User == null) + { + return NotFound(); + } + + return Page(); + } + + public async Task OnPostAsync(Guid? id) + { + if (!ModelState.IsValid) + { + return Page(); + } + + if (id == null) + { + return NotFound(); + } + + var userToUpdate = await _userManager.Users.FirstOrDefaultAsync(u => u.Id == id); + + if (userToUpdate == null) + { + return NotFound(); + } + + if (await TryUpdateModelAsync( + userToUpdate, + "user", + u => u.UserName, u => u.Email)) + { + if (!string.IsNullOrEmpty(Password)) + { + var token = await _userManager.GeneratePasswordResetTokenAsync(userToUpdate); + var result = await _userManager.ResetPasswordAsync(userToUpdate, token, Password); + + if (!result.Succeeded) + { + foreach (var error in result.Errors) + { + ModelState.AddModelError(string.Empty, error.Description); + } + return Page(); + } + } + + await _context.SaveChangesAsync(); + return RedirectToPage("./Index"); + } + + return Page(); + } +} diff --git a/GameLibrary/Pages/Admin/Users/Index.cshtml b/GameLibrary/Pages/Admin/Users/Index.cshtml new file mode 100644 index 0000000..a8940a6 --- /dev/null +++ b/GameLibrary/Pages/Admin/Users/Index.cshtml @@ -0,0 +1,40 @@ +@page +@model GameLibrary.Pages.Admin.Users.IndexModel + +@{ + ViewData["Title"] = "Users"; +} + + +
+

Users

+

+ Create New +

+
+ +
+ + + + + + + + + + @foreach (var item in Model.Users!) + { + + + + + + } + +
User NameEmailActions
@Html.DisplayFor(modelItem => item.UserName)@Html.DisplayFor(modelItem => item.Email) + Edit + Delete +
+
+ diff --git a/GameLibrary/Pages/Admin/Users/Index.cshtml.cs b/GameLibrary/Pages/Admin/Users/Index.cshtml.cs new file mode 100644 index 0000000..3fb17c6 --- /dev/null +++ b/GameLibrary/Pages/Admin/Users/Index.cshtml.cs @@ -0,0 +1,23 @@ +using GameLibrary.Data; +using GameLibrary.Models; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace GameLibrary.Pages.Admin.Users; + +public class IndexModel : PageModel +{ + private readonly ApplicationDbContext _context; + + public IndexModel(ApplicationDbContext context) + { + _context = context; + } + + public IList? Users { get; set; } + + public async Task OnGetAsync() + { + Users = await _context.Users.ToListAsync(); + } +} From 2f41406bb79455f4ede54b44e9c3c805a3b4dd31 Mon Sep 17 00:00:00 2001 From: Mathias Date: Mon, 18 Nov 2024 20:44:16 +0100 Subject: [PATCH 02/19] Admin Panel Nav in admin panel --- GameLibrary/Migrations/20241123065457_Init.cs | 15 ++- .../Pages/Account/Manage/_ManageNav.cshtml | 2 +- GameLibrary/Pages/Admin/Dashboard.cshtml | 108 ----------------- GameLibrary/Pages/Admin/Dashboard.cshtml.cs | 44 ------- GameLibrary/Pages/Admin/Games/Index.cshtml | 1 + GameLibrary/Pages/Admin/Index.cshtml | 109 ++++++++++++++++-- GameLibrary/Pages/Admin/Index.cshtml.cs | 66 +++++++---- GameLibrary/Pages/Admin/ManageNavPages.cs | 55 +++++++++ .../Pages/Admin/Reviews/Create.cshtml.cs | 22 +++- .../Pages/Admin/Reviews/Delete.cshtml.cs | 14 +++ .../Pages/Admin/Reviews/Edit.cshtml.cs | 14 +++ GameLibrary/Pages/Admin/Reviews/Index.cshtml | 1 + .../Pages/Admin/Reviews/Index.cshtml.cs | 14 +++ .../Pages/Admin/Roles/Create.cshtml.cs | 14 +++ .../Pages/Admin/Roles/Delete.cshtml.cs | 14 +++ GameLibrary/Pages/Admin/Roles/Edit.cshtml.cs | 15 +++ GameLibrary/Pages/Admin/Roles/Index.cshtml | 1 + GameLibrary/Pages/Admin/Roles/Index.cshtml.cs | 14 +++ .../Admin/UserFavorites/Create.cshtml.cs | 22 +++- .../Admin/UserFavorites/Delete.cshtml.cs | 14 +++ .../Pages/Admin/UserFavorites/Edit.cshtml.cs | 14 +++ .../Pages/Admin/UserFavorites/Index.cshtml | 1 + .../Pages/Admin/UserFavorites/Index.cshtml.cs | 14 +++ .../Admin/UserLibraries/Create.cshtml.cs | 22 +++- .../Admin/UserLibraries/Delete.cshtml.cs | 14 +++ .../Pages/Admin/UserLibraries/Edit.cshtml.cs | 14 +++ .../Pages/Admin/UserLibraries/Index.cshtml | 1 + .../Pages/Admin/UserLibraries/Index.cshtml.cs | 14 +++ .../Pages/Admin/Users/Create.cshtml.cs | 16 ++- .../Pages/Admin/Users/Delete.cshtml.cs | 18 ++- GameLibrary/Pages/Admin/Users/Edit.cshtml.cs | 16 ++- GameLibrary/Pages/Admin/Users/Index.cshtml | 1 + GameLibrary/Pages/Admin/Users/Index.cshtml.cs | 14 +++ GameLibrary/Pages/Admin/_Layout.cshtml | 25 ++++ GameLibrary/Pages/Admin/_ManageNav.cshtml | 9 ++ 35 files changed, 555 insertions(+), 197 deletions(-) delete mode 100644 GameLibrary/Pages/Admin/Dashboard.cshtml delete mode 100644 GameLibrary/Pages/Admin/Dashboard.cshtml.cs create mode 100644 GameLibrary/Pages/Admin/ManageNavPages.cs create mode 100644 GameLibrary/Pages/Admin/_Layout.cshtml create mode 100644 GameLibrary/Pages/Admin/_ManageNav.cshtml diff --git a/GameLibrary/Migrations/20241123065457_Init.cs b/GameLibrary/Migrations/20241123065457_Init.cs index 41df414..6a02e4f 100644 --- a/GameLibrary/Migrations/20241123065457_Init.cs +++ b/GameLibrary/Migrations/20241123065457_Init.cs @@ -1,4 +1,17 @@ -using System; +// Copyright 2024 Web.Tech. Group17 +// +// Licensed under the Apache License, Version 2.0 (the "License"): +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/GameLibrary/Pages/Account/Manage/_ManageNav.cshtml b/GameLibrary/Pages/Account/Manage/_ManageNav.cshtml index 6d2863c..6d8f6ec 100644 --- a/GameLibrary/Pages/Account/Manage/_ManageNav.cshtml +++ b/GameLibrary/Pages/Account/Manage/_ManageNav.cshtml @@ -2,7 +2,7 @@ @{ var hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any(); } -