Skip to content

Commit

Permalink
update master branch to .NET Core 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jamcneil committed Jan 13, 2020
1 parent 435520f commit d499c79
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 34 deletions.
40 changes: 20 additions & 20 deletions Tailspin.SpaceGame.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,28 +33,28 @@ IDocumentDBRepository<Profile> profileRespository
)
{
// 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<string>()
{
"Solo",
"Duo",
"Trio"
},

},

GameRegions = new List<string>()
{
"Milky Way",
"Andromeda",
"Pinwheel",
"NGC 1300",
"Messier 82",
}
"Messier 82",
}
};

try
Expand All @@ -63,7 +63,7 @@ IDocumentDBRepository<Profile> profileRespository
// 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<Func<Score, bool>> queryPredicate = score =>
Expression<Func<Score, bool>> queryPredicate = score =>
(string.IsNullOrEmpty(mode) || score.GameMode == mode) &&
(string.IsNullOrEmpty(region) || score.GameRegion == region);

Expand All @@ -74,7 +74,7 @@ IDocumentDBRepository<Profile> profileRespository
IEnumerable<Score> 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
);

Expand All @@ -94,9 +94,9 @@ IDocumentDBRepository<Profile> profileRespository
// Fetch the user profile for each score.
// This creates a list that's parallel with the scores collection.
var profiles = new List<Task<Profile>>();
foreach (var score in scores)
{
profiles.Add(_profileRespository.GetItemAsync(score.ProfileId));
foreach (var score in scores)
{
profiles.Add(_profileRespository.GetItemAsync(score.ProfileId));
}
Task<Profile>.WaitAll(profiles.ToArray());

Expand All @@ -105,10 +105,10 @@ IDocumentDBRepository<Profile> profileRespository

return View(vm);
}
catch (Exception ex)
catch (Exception)
{
return View(vm);
}
}
}

[Route("/profile/{id}")]
Expand All @@ -119,7 +119,7 @@ public async Task<IActionResult> 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("/");
}
Expand Down
37 changes: 26 additions & 11 deletions Tailspin.SpaceGame.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,22 +26,28 @@ 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<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
//services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

// services.Configure<MvcOptions>(options =>
// {
// options.EnableEndpointRouting = false;
// });

// Add document stores. These are passed to the HomeController constructor.
services.AddSingleton<IDocumentDBRepository<Score>>(new LocalDocumentDBRepository<Score>(@"SampleData/scores.json"));
services.AddSingleton<IDocumentDBRepository<Profile>>(new LocalDocumentDBRepository<Profile>(@"SampleData/profiles.json"));
}

// 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())
{
Expand All @@ -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?}");
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ProjectGuid>{A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}</ProjectGuid>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<!-- <PackageReference Include="Microsoft.AspNetCore.App" /> -->
<!-- <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" /> -->
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>

Expand Down

0 comments on commit d499c79

Please sign in to comment.