From d499c7984224511b180fa491f7a6c4e1b3ab6d6e Mon Sep 17 00:00:00 2001 From: jamcneil Date: Mon, 13 Jan 2020 13:03:55 -0700 Subject: [PATCH] update master branch to .NET Core 3.1 --- .../Controllers/HomeController.cs | 40 +++++++++---------- Tailspin.SpaceGame.Web/Startup.cs | 37 ++++++++++++----- .../Tailspin.SpaceGame.Web.csproj | 6 +-- 3 files changed, 49 insertions(+), 34 deletions(-) diff --git a/Tailspin.SpaceGame.Web/Controllers/HomeController.cs b/Tailspin.SpaceGame.Web/Controllers/HomeController.cs index ed71be596cf..f6c6ae96931 100644 --- a/Tailspin.SpaceGame.Web/Controllers/HomeController.cs +++ b/Tailspin.SpaceGame.Web/Controllers/HomeController.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Linq.Expressions; +using System.Linq.Expressions; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using TailSpin.SpaceGame.Web.Models; @@ -33,28 +33,28 @@ public async Task Index( ) { // Create the view model with initial values we already know. - var vm = new LeaderboardViewModel - { - Page = page, - PageSize = pageSize, - SelectedMode = mode, - SelectedRegion = region, - + var vm = new LeaderboardViewModel + { + Page = page, + PageSize = pageSize, + SelectedMode = mode, + SelectedRegion = region, + GameModes = new List() { "Solo", "Duo", "Trio" - }, - + }, + GameRegions = new List() { "Milky Way", "Andromeda", "Pinwheel", "NGC 1300", - "Messier 82", - } + "Messier 82", + } }; try @@ -63,7 +63,7 @@ public async Task Index( // This expression selects all scores that match the provided game // mode and region (map). // Select the score if the game mode or region is empty. - Expression> queryPredicate = score => + Expression> queryPredicate = score => (string.IsNullOrEmpty(mode) || score.GameMode == mode) && (string.IsNullOrEmpty(region) || score.GameRegion == region); @@ -74,7 +74,7 @@ public async Task Index( IEnumerable scores = await _scoreRepository.GetItemsAsync( queryPredicate, // the predicate defined above score => score.HighScore, // sort descending by high score - page - 1, // subtract 1 to make the query 0-based + page - 1, // subtract 1 to make the query 0-based pageSize ); @@ -94,9 +94,9 @@ public async Task Index( // Fetch the user profile for each score. // This creates a list that's parallel with the scores collection. var profiles = new List>(); - foreach (var score in scores) - { - profiles.Add(_profileRespository.GetItemAsync(score.ProfileId)); + foreach (var score in scores) + { + profiles.Add(_profileRespository.GetItemAsync(score.ProfileId)); } Task.WaitAll(profiles.ToArray()); @@ -105,10 +105,10 @@ public async Task Index( return View(vm); } - catch (Exception ex) + catch (Exception) { return View(vm); - } + } } [Route("/profile/{id}")] @@ -119,7 +119,7 @@ public async Task Profile(string id, string rank="") // Fetch the user profile with the given identifier. return View(new ProfileViewModel { Profile = await _profileRespository.GetItemAsync(id), Rank = rank }); } - catch (Exception ex) + catch (Exception) { return RedirectToAction("/"); } diff --git a/Tailspin.SpaceGame.Web/Startup.cs b/Tailspin.SpaceGame.Web/Startup.cs index 34a97db490c..b3babdf8d75 100644 --- a/Tailspin.SpaceGame.Web/Startup.cs +++ b/Tailspin.SpaceGame.Web/Startup.cs @@ -1,11 +1,17 @@ -using Microsoft.AspNetCore.Builder; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using TailSpin.SpaceGame.Web.Models; - +using Microsoft.Extensions.Hosting; +using TailSpin.SpaceGame.Web.Models; +using Microsoft.AspNetCore.Http; + + namespace TailSpin.SpaceGame.Web { public class Startup @@ -20,6 +26,7 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.AddControllersWithViews(); services.Configure(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. @@ -27,7 +34,12 @@ public void ConfigureServices(IServiceCollection services) options.MinimumSameSitePolicy = SameSiteMode.None; }); - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + + // services.Configure(options => + // { + // options.EnableEndpointRouting = false; + // }); // Add document stores. These are passed to the HomeController constructor. services.AddSingleton>(new LocalDocumentDBRepository(@"SampleData/scores.json")); @@ -35,7 +47,7 @@ public void ConfigureServices(IServiceCollection services) } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { @@ -49,13 +61,16 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseHttpsRedirection(); app.UseStaticFiles(); - app.UseCookiePolicy(); - app.UseMvc(routes => + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => { - routes.MapRoute( + endpoints.MapControllerRoute( name: "default", - template: "{controller=Home}/{action=Index}/{id?}"); + pattern: "{controller=Home}/{action=Index}/{id?}"); }); } } diff --git a/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj b/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj index 47ee6ec166d..f529ba045a4 100644 --- a/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj +++ b/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj @@ -1,13 +1,13 @@ - netcoreapp2.1 + netcoreapp3.1 {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46} - - + +