From 2363a001f41b09ada1e1d3f5900fbfb18cb42c46 Mon Sep 17 00:00:00 2001 From: syneffort Date: Fri, 25 Aug 2023 13:52:59 +0900 Subject: [PATCH] ranking app CR --- BlazorApp/BlazorApp.sln | 4 +- .../RankingApp/Data/ApplicationDbContext.cs | 3 + .../20230825025030_RankingService.Designer.cs | 308 ++++++++++++++++++ .../20230825025030_RankingService.cs | 35 ++ .../ApplicationDbContextModelSnapshot.cs | 109 ++++--- .../RankingApp/Data/Models/GameResult.cs | 11 + .../Data/Services/RankingService.cs | 37 +++ BlazorApp/RankingApp/Data/WeatherForecast.cs | 13 - .../RankingApp/Data/WeatherForecastService.cs | 20 -- BlazorApp/RankingApp/Pages/Counter.razor | 18 - BlazorApp/RankingApp/Pages/FetchData.razor | 48 --- BlazorApp/RankingApp/Pages/Ranking.razor | 112 +++++++ BlazorApp/RankingApp/Program.cs | 4 +- BlazorApp/RankingApp/Shared/NavMenu.razor | 9 +- BlazorApp/RankingApp/appsettings.json | 2 +- 15 files changed, 584 insertions(+), 149 deletions(-) create mode 100644 BlazorApp/RankingApp/Data/Migrations/20230825025030_RankingService.Designer.cs create mode 100644 BlazorApp/RankingApp/Data/Migrations/20230825025030_RankingService.cs create mode 100644 BlazorApp/RankingApp/Data/Models/GameResult.cs create mode 100644 BlazorApp/RankingApp/Data/Services/RankingService.cs delete mode 100644 BlazorApp/RankingApp/Data/WeatherForecast.cs delete mode 100644 BlazorApp/RankingApp/Data/WeatherForecastService.cs delete mode 100644 BlazorApp/RankingApp/Pages/Counter.razor delete mode 100644 BlazorApp/RankingApp/Pages/FetchData.razor create mode 100644 BlazorApp/RankingApp/Pages/Ranking.razor diff --git a/BlazorApp/BlazorApp.sln b/BlazorApp/BlazorApp.sln index 7cf9c45..acb22ab 100644 --- a/BlazorApp/BlazorApp.sln +++ b/BlazorApp/BlazorApp.sln @@ -7,9 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorApp", "BlazorApp\Blaz EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorServerApp", "BlazorServerApp\BlazorServerApp.csproj", "{DEA3AF90-CC70-4B35-AC07-C710ACF62455}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorStateApp", "BlazorStateApp\BlazorStateApp.csproj", "{504AB085-F56E-4B14-B6DC-6810D8690DBE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorStateApp", "BlazorStateApp\BlazorStateApp.csproj", "{504AB085-F56E-4B14-B6DC-6810D8690DBE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RankingApp", "RankingApp\RankingApp.csproj", "{6DCA770F-A98B-4A84-9139-A24F77C592D3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RankingApp", "RankingApp\RankingApp.csproj", "{6DCA770F-A98B-4A84-9139-A24F77C592D3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/BlazorApp/RankingApp/Data/ApplicationDbContext.cs b/BlazorApp/RankingApp/Data/ApplicationDbContext.cs index 2e58316..f8ef835 100644 --- a/BlazorApp/RankingApp/Data/ApplicationDbContext.cs +++ b/BlazorApp/RankingApp/Data/ApplicationDbContext.cs @@ -1,10 +1,13 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; +using RankingApp.Data.Models; namespace RankingApp.Data { public class ApplicationDbContext : IdentityDbContext { + public DbSet GameResults { get; set; } + public ApplicationDbContext(DbContextOptions options) : base(options) { diff --git a/BlazorApp/RankingApp/Data/Migrations/20230825025030_RankingService.Designer.cs b/BlazorApp/RankingApp/Data/Migrations/20230825025030_RankingService.Designer.cs new file mode 100644 index 0000000..25ebec3 --- /dev/null +++ b/BlazorApp/RankingApp/Data/Migrations/20230825025030_RankingService.Designer.cs @@ -0,0 +1,308 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using RankingApp.Data; + +#nullable disable + +namespace RankingApp.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20230825025030_RankingService")] + partial class RankingService + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.20") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("RankingApp.Data.Models.GameResult", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("GameResults"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlazorApp/RankingApp/Data/Migrations/20230825025030_RankingService.cs b/BlazorApp/RankingApp/Data/Migrations/20230825025030_RankingService.cs new file mode 100644 index 0000000..eb07c9a --- /dev/null +++ b/BlazorApp/RankingApp/Data/Migrations/20230825025030_RankingService.cs @@ -0,0 +1,35 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace RankingApp.Data.Migrations +{ + public partial class RankingService : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "GameResults", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "int", nullable: false), + UserName = table.Column(type: "nvarchar(max)", nullable: false), + Score = table.Column(type: "int", nullable: false), + Date = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_GameResults", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "GameResults"); + } + } +} diff --git a/BlazorApp/RankingApp/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/BlazorApp/RankingApp/Data/Migrations/ApplicationDbContextModelSnapshot.cs index 0e7f9ef..f8a0d1b 100644 --- a/BlazorApp/RankingApp/Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/BlazorApp/RankingApp/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,12 @@ -// +// +using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using RankingApp.Data; -using System; + +#nullable disable namespace RankingApp.Data.Migrations { @@ -15,9 +17,10 @@ namespace RankingApp.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("ProductVersion", "6.0.20") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { @@ -29,29 +32,30 @@ namespace RankingApp.Data.Migrations .HasColumnType("nvarchar(max)"); b.Property("Name") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); b.Property("NormalizedName") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); b.HasKey("Id"); b.HasIndex("NormalizedName") .IsUnique() - .HasName("RoleNameIndex") + .HasDatabaseName("RoleNameIndex") .HasFilter("[NormalizedName] IS NOT NULL"); - b.ToTable("AspNetRoles"); + b.ToTable("AspNetRoles", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); b.Property("ClaimType") .HasColumnType("nvarchar(max)"); @@ -67,7 +71,7 @@ namespace RankingApp.Data.Migrations b.HasIndex("RoleId"); - b.ToTable("AspNetRoleClaims"); + b.ToTable("AspNetRoleClaims", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => @@ -83,8 +87,8 @@ namespace RankingApp.Data.Migrations .HasColumnType("nvarchar(max)"); b.Property("Email") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); b.Property("EmailConfirmed") .HasColumnType("bit"); @@ -96,12 +100,12 @@ namespace RankingApp.Data.Migrations .HasColumnType("datetimeoffset"); b.Property("NormalizedEmail") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); b.Property("NormalizedUserName") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); b.Property("PasswordHash") .HasColumnType("nvarchar(max)"); @@ -119,28 +123,29 @@ namespace RankingApp.Data.Migrations .HasColumnType("bit"); b.Property("UserName") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); b.HasKey("Id"); b.HasIndex("NormalizedEmail") - .HasName("EmailIndex"); + .HasDatabaseName("EmailIndex"); b.HasIndex("NormalizedUserName") .IsUnique() - .HasName("UserNameIndex") + .HasDatabaseName("UserNameIndex") .HasFilter("[NormalizedUserName] IS NOT NULL"); - b.ToTable("AspNetUsers"); + b.ToTable("AspNetUsers", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); b.Property("ClaimType") .HasColumnType("nvarchar(max)"); @@ -156,18 +161,18 @@ namespace RankingApp.Data.Migrations b.HasIndex("UserId"); - b.ToTable("AspNetUserClaims"); + b.ToTable("AspNetUserClaims", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("nvarchar(128)") - .HasMaxLength(128); + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); b.Property("ProviderKey") - .HasColumnType("nvarchar(128)") - .HasMaxLength(128); + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); b.Property("ProviderDisplayName") .HasColumnType("nvarchar(max)"); @@ -180,7 +185,7 @@ namespace RankingApp.Data.Migrations b.HasIndex("UserId"); - b.ToTable("AspNetUserLogins"); + b.ToTable("AspNetUserLogins", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => @@ -195,7 +200,7 @@ namespace RankingApp.Data.Migrations b.HasIndex("RoleId"); - b.ToTable("AspNetUserRoles"); + b.ToTable("AspNetUserRoles", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => @@ -204,19 +209,45 @@ namespace RankingApp.Data.Migrations .HasColumnType("nvarchar(450)"); b.Property("LoginProvider") - .HasColumnType("nvarchar(128)") - .HasMaxLength(128); + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); b.Property("Name") - .HasColumnType("nvarchar(128)") - .HasMaxLength(128); + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); b.Property("Value") .HasColumnType("nvarchar(max)"); b.HasKey("UserId", "LoginProvider", "Name"); - b.ToTable("AspNetUserTokens"); + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("RankingApp.Data.Models.GameResult", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("GameResults"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => diff --git a/BlazorApp/RankingApp/Data/Models/GameResult.cs b/BlazorApp/RankingApp/Data/Models/GameResult.cs new file mode 100644 index 0000000..098a8d6 --- /dev/null +++ b/BlazorApp/RankingApp/Data/Models/GameResult.cs @@ -0,0 +1,11 @@ +namespace RankingApp.Data.Models +{ + public class GameResult + { + public int Id { get; set; } + public int UserId { get; set; } + public string UserName { get; set; } + public int Score { get; set; } + public DateTime Date { get; set; } + } +} diff --git a/BlazorApp/RankingApp/Data/Services/RankingService.cs b/BlazorApp/RankingApp/Data/Services/RankingService.cs new file mode 100644 index 0000000..09d06ac --- /dev/null +++ b/BlazorApp/RankingApp/Data/Services/RankingService.cs @@ -0,0 +1,37 @@ +using RankingApp.Data.Models; + +namespace RankingApp.Data.Services +{ + public class RankingService + { + private ApplicationDbContext _context; + + public RankingService(ApplicationDbContext context) + { + _context = context; + } + + // Create + public Task AddGameResult(GameResult gameResult) + { + _context.GameResults.Add(gameResult); + _context.SaveChanges(); + + return Task.FromResult(gameResult); + } + + // Read + public Task> GetGameResultsAsync() + { + List results = _context.GameResults + .OrderByDescending(item => item.Score) + .ToList(); + + return Task.FromResult(results); + } + + // Update + + // Delete + } +} diff --git a/BlazorApp/RankingApp/Data/WeatherForecast.cs b/BlazorApp/RankingApp/Data/WeatherForecast.cs deleted file mode 100644 index 88d2ac9..0000000 --- a/BlazorApp/RankingApp/Data/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace RankingApp.Data -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} \ No newline at end of file diff --git a/BlazorApp/RankingApp/Data/WeatherForecastService.cs b/BlazorApp/RankingApp/Data/WeatherForecastService.cs deleted file mode 100644 index ff1dc08..0000000 --- a/BlazorApp/RankingApp/Data/WeatherForecastService.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace RankingApp.Data -{ - public class WeatherForecastService - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - public Task GetForecastAsync(DateTime startDate) - { - return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = startDate.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }).ToArray()); - } - } -} \ No newline at end of file diff --git a/BlazorApp/RankingApp/Pages/Counter.razor b/BlazorApp/RankingApp/Pages/Counter.razor deleted file mode 100644 index ef23cb3..0000000 --- a/BlazorApp/RankingApp/Pages/Counter.razor +++ /dev/null @@ -1,18 +0,0 @@ -@page "/counter" - -Counter - -

Counter

- -

Current count: @currentCount

- - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} diff --git a/BlazorApp/RankingApp/Pages/FetchData.razor b/BlazorApp/RankingApp/Pages/FetchData.razor deleted file mode 100644 index 1aecd33..0000000 --- a/BlazorApp/RankingApp/Pages/FetchData.razor +++ /dev/null @@ -1,48 +0,0 @@ -@page "/fetchdata" - -Weather forecast - -@using RankingApp.Data -@inject WeatherForecastService ForecastService - -

Weather forecast

- -

This component demonstrates fetching data from a service.

- -@if (forecasts == null) -{ -

Loading...

-} -else -{ - - - - - - - - - - - @foreach (var forecast in forecasts) - { - - - - - - - } - -
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
-} - -@code { - private WeatherForecast[]? forecasts; - - protected override async Task OnInitializedAsync() - { - forecasts = await ForecastService.GetForecastAsync(DateTime.Now); - } -} diff --git a/BlazorApp/RankingApp/Pages/Ranking.razor b/BlazorApp/RankingApp/Pages/Ranking.razor new file mode 100644 index 0000000..41381f4 --- /dev/null +++ b/BlazorApp/RankingApp/Pages/Ranking.razor @@ -0,0 +1,112 @@ +@page "/ranking" +@using RankingApp.Data.Models; +@using RankingApp.Data.Services; + +@inject RankingService _rankingService; + +

Ranking

+ + + + @if (_gameResults == null) + { +

Loading...

+ } + else + { + + + + + + + + + + @foreach (var gameResult in _gameResults) + { + + + + + + } + +
User nameScoreDate
@gameResult.UserName@gameResult.Score@gameResult.Date.ToShortDateString()
+ +

+ +

+ + @if (_showPopup) + { + + } + } +
+ +

You have no authorization to access.

+
+
+ +@code { + + List _gameResults; + + bool _showPopup; + GameResult _gameResult; + + protected async override Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + + _gameResults = await _rankingService.GetGameResultsAsync(); + } + + void AddGameResult() + { + _showPopup = true; + _gameResult = new GameResult() { Id = 0 }; + } + + void ClosePopup() + { + _showPopup = false; + } + + async Task SaveGameResult() + { + if (_gameResult.Id == 0) + { + _gameResult.Date = DateTime.Now; + var result = _rankingService.AddGameResult(_gameResult); + } + else + { + + } + + _gameResults = await _rankingService.GetGameResultsAsync(); + ClosePopup(); + } +} diff --git a/BlazorApp/RankingApp/Program.cs b/BlazorApp/RankingApp/Program.cs index 91beee0..82d4f2e 100644 --- a/BlazorApp/RankingApp/Program.cs +++ b/BlazorApp/RankingApp/Program.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Identity.UI; using Microsoft.EntityFrameworkCore; using RankingApp.Areas.Identity; using RankingApp.Data; +using RankingApp.Data.Services; namespace RankingApp { @@ -25,7 +26,8 @@ namespace RankingApp builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddScoped>(); - builder.Services.AddSingleton(); + + builder.Services.AddScoped(); var app = builder.Build(); diff --git a/BlazorApp/RankingApp/Shared/NavMenu.razor b/BlazorApp/RankingApp/Shared/NavMenu.razor index 6b3673e..d9aad97 100644 --- a/BlazorApp/RankingApp/Shared/NavMenu.razor +++ b/BlazorApp/RankingApp/Shared/NavMenu.razor @@ -15,13 +15,8 @@ - diff --git a/BlazorApp/RankingApp/appsettings.json b/BlazorApp/RankingApp/appsettings.json index ea12025..8194fa1 100644 --- a/BlazorApp/RankingApp/appsettings.json +++ b/BlazorApp/RankingApp/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "Data Source=peacecloud.synology.me,21433;User ID=study;Password=********;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False" + "DefaultConnection": "Data Source=peacecloud.synology.me,21433;Initial Catalog=RankingDB;User ID=study;Password=Study1234;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False" }, "Logging": { "LogLevel": {