Skip to content

Commit

Permalink
Games Page added
Browse files Browse the repository at this point in the history
  • Loading branch information
GiGwebs committed Nov 14, 2024
1 parent 72a1b5a commit 19c1d68
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 37 deletions.
Binary file modified GameLibrary/Database.db
Binary file not shown.
Binary file modified GameLibrary/Database.db-shm
Binary file not shown.
Binary file modified GameLibrary/Database.db-wal
Binary file not shown.
28 changes: 28 additions & 0 deletions GameLibrary/Pages/Games/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@page
@model GameLibrary.Pages.Games.IndexModel
@{
ViewData["Title"] = "Welcome to GAMELIB";
}

<h1 style="color: #FFD43B;">Welcome to GAMELIB</h1>

<div>
<h2>Game List</h2>
<div class="row">
@foreach (var game in Model.Games)
{
<div class="col-md-4">
<div class="card" style="margin-bottom: 20px;">
<img src="@game.ImageUrl" class="card-img-top" alt="@game.Title"
style="height: 200px; object-fit: cover;" />
<div class="card-body">
<h5 class="card-title">@game.Title</h5>
<p class="card-text">@game.Description.Substring(0, Math.Min(100, @game.Description.Length)) + "..."
</p>
<a href="/Games/[email protected]" class="btn btn-primary">View Details</a>
</div>
</div>
</div>
}
</div>
</div>
41 changes: 41 additions & 0 deletions GameLibrary/Pages/Games/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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 GameLibrary.Data;
using GameLibrary.Models;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;

namespace GameLibrary.Pages.Games;

public class IndexModel : PageModel
{
private readonly ApplicationDbContext _context;

public IndexModel(ApplicationDbContext context)
{
_context = context;
}

public IList<Game> Games { get; set; } = new List<Game>();

public async Task OnGetAsync()
{
Games = await _context.Games
.OrderByDescending(g => g.Rating)
.ThenByDescending(g => g.ReleaseDate)
.ToListAsync();
}
}
28 changes: 5 additions & 23 deletions GameLibrary/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
@page
@model GameLibrary.Pages.IndexModel
@model IndexModel
@{
ViewData["Title"] = "Welcome to GAMELIB";
ViewData["Title"] = "Home page";
}

<h1 style="color: #FFD43B;">Welcome to GAMELIB</h1>

<div>
<h2>Game List</h2>
<div class="row">
@foreach (var game in Model.Games)
{
<div class="col-md-4">
<div class="card" style="margin-bottom: 20px;">
<img src="@game.ImageUrl" class="card-img-top" alt="@game.Title"
style="height: 200px; object-fit: cover;" />
<div class="card-body">
<h5 class="card-title">@game.Title</h5>
<p class="card-text">@game.Description.Substring(0, Math.Min(100, @game.Description.Length)) + "..."
</p>
<a href="/Games/[email protected]" class="btn btn-primary">View Details</a>
</div>
</div>
</div>
}
</div>
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
19 changes: 5 additions & 14 deletions GameLibrary/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.


using GameLibrary.Data;
using GameLibrary.Models;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;

namespace GameLibrary.Pages;

public class IndexModel : PageModel
{
private readonly ApplicationDbContext _context;
private readonly ILogger<IndexModel> _logger;

public IndexModel(ApplicationDbContext context)
public IndexModel(ILogger<IndexModel> logger)
{
_context = context;
_logger = logger;
}

public IList<Game> Games { get; set; } = new List<Game>();

public async Task OnGetAsync()
public void OnGet()
{
Games = await _context.Games
.OrderByDescending(g => g.Rating)
.ThenByDescending(g => g.ReleaseDate)
.ToListAsync();

}
}
2 changes: 2 additions & 0 deletions GameLibrary/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto">
<li class="nav-item"><a class="nav-link" asp-area="" asp-page="/Index">Home</a></li>
<li class="nav-item"><a class="nav-link" asp-area="" asp-page="/Games/Index">Games</a></li>
<li class="nav-item"><a class="nav-link" asp-area="" asp-page="/Privacy">Privacy</a></li>

</ul>
<partial name="_LoginPartial" />
</div>
Expand Down

0 comments on commit 19c1d68

Please sign in to comment.