Skip to content

Commit

Permalink
Merge pull request #3 from cephalin/master
Browse files Browse the repository at this point in the history
Upgrade to Core 2.2
  • Loading branch information
cephalin authored Aug 6, 2019
2 parents bddc83b + 897f182 commit 685139b
Show file tree
Hide file tree
Showing 82 changed files with 27,403 additions and 11,213 deletions.
3 changes: 0 additions & 3 deletions .bowerrc

This file was deleted.

16 changes: 5 additions & 11 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using DotNetCoreSqlDb.Models;

namespace DotNetCoreSqlDb.Controllers
{
Expand All @@ -13,23 +15,15 @@ public IActionResult Index()
return View();
}

public IActionResult About()
public IActionResult Privacy()
{
ViewData["Message"] = "Your application description page.";

return View();
}

public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";

return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View();
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -15,7 +15,7 @@ public class TodosController : Controller

public TodosController(MyDatabaseContext context)
{
_context = context;
_context = context;
}

// GET: Todos
Expand All @@ -33,7 +33,7 @@ public async Task<IActionResult> Details(int? id)
}

var todo = await _context.Todo
.SingleOrDefaultAsync(m => m.ID == id);
.FirstOrDefaultAsync(m => m.ID == id);
if (todo == null)
{
return NotFound();
Expand All @@ -59,7 +59,7 @@ public async Task<IActionResult> Create([Bind("ID,Description,CreatedDate")] Tod
{
_context.Add(todo);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
return RedirectToAction(nameof(Index));
}
return View(todo);
}
Expand All @@ -72,7 +72,7 @@ public async Task<IActionResult> Edit(int? id)
return NotFound();
}

var todo = await _context.Todo.SingleOrDefaultAsync(m => m.ID == id);
var todo = await _context.Todo.FindAsync(id);
if (todo == null)
{
return NotFound();
Expand Down Expand Up @@ -110,7 +110,7 @@ public async Task<IActionResult> Edit(int id, [Bind("ID,Description,CreatedDate"
throw;
}
}
return RedirectToAction("Index");
return RedirectToAction(nameof(Index));
}
return View(todo);
}
Expand All @@ -124,7 +124,7 @@ public async Task<IActionResult> Delete(int? id)
}

var todo = await _context.Todo
.SingleOrDefaultAsync(m => m.ID == id);
.FirstOrDefaultAsync(m => m.ID == id);
if (todo == null)
{
return NotFound();
Expand All @@ -138,10 +138,10 @@ public async Task<IActionResult> Delete(int? id)
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
var todo = await _context.Todo.SingleOrDefaultAsync(m => m.ID == id);
var todo = await _context.Todo.FindAsync(id);
_context.Todo.Remove(todo);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
return RedirectToAction(nameof(Index));
}

private bool TodoExists(int id)
Expand Down
24 changes: 8 additions & 16 deletions DotNetCoreSqlDb.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.7" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="2.2.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace DotNetCoreSqlDb.Migrations
{
public partial class Initial : Migration
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
Expand All @@ -16,8 +15,8 @@ protected override void Up(MigrationBuilder migrationBuilder)
ID = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
CreatedDate = table.Column<DateTime>(nullable: false),
Description = table.Column<string>(nullable: true)
Description = table.Column<string>(nullable: true),
CreatedDate = table.Column<DateTime>(nullable: false)
},
constraints: table =>
{
Expand Down
12 changes: 7 additions & 5 deletions Migrations/MyDatabaseContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
// <auto-generated />
using System;
using DotNetCoreSqlDb.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using DotNetCoreSqlDb.Models;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace DotNetCoreSqlDb.Migrations
{
Expand All @@ -12,8 +12,9 @@ partial class MyDatabaseContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "1.1.2");
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079");

modelBuilder.Entity("DotNetCoreSqlDb.Models.Todo", b =>
{
Expand All @@ -28,6 +29,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.ToTable("Todo");
});
#pragma warning restore 612, 618
}
}
}
11 changes: 11 additions & 0 deletions Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace DotNetCoreSqlDb.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
1 change: 1 addition & 0 deletions Models/Todo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ public class Todo
public DateTime CreatedDate { get; set; }
}
}

11 changes: 8 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace DotNetCoreSqlDb
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHost BuildWebHost(string[] args) =>
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddAzureWebAppDiagnostics();
});
}
}
26 changes: 17 additions & 9 deletions Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using DotNetCoreSqlDb.Models;

Expand All @@ -24,31 +26,37 @@ 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)
{
// Add framework services.
services.AddMvc();
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_2);

services.AddDbContext<MyDatabaseContext>(options =>
options.UseSqlite("Data Source=localdatabase.db"));
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
loggerFactory.AddAzureWebAppDiagnostics();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();

app.UseMvc(routes =>
{
Expand Down
7 changes: 0 additions & 7 deletions Views/Home/About.cshtml

This file was deleted.

17 changes: 0 additions & 17 deletions Views/Home/Contact.cshtml

This file was deleted.

Loading

0 comments on commit 685139b

Please sign in to comment.