forked from Azure-Samples/dotnetcore-sqldb-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
23,927 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"directory": "wwwroot/lib" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace DotNetCoreSqlDb.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
public IActionResult About() | ||
{ | ||
ViewData["Message"] = "Your application description page."; | ||
|
||
return View(); | ||
} | ||
|
||
public IActionResult Contact() | ||
{ | ||
ViewData["Message"] = "Your contact page."; | ||
|
||
return View(); | ||
} | ||
|
||
public IActionResult Error() | ||
{ | ||
return View(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
using Microsoft.EntityFrameworkCore; | ||
using DotNetCoreSqlDb.Models; | ||
|
||
namespace DotNetCoreSqlDb.Controllers | ||
{ | ||
public class TodosController : Controller | ||
{ | ||
private readonly MyDatabaseContext _context; | ||
|
||
public TodosController(MyDatabaseContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
// GET: Todos | ||
public async Task<IActionResult> Index() | ||
{ | ||
return View(await _context.Todo.ToListAsync()); | ||
} | ||
|
||
// GET: Todos/Details/5 | ||
public async Task<IActionResult> Details(int? id) | ||
{ | ||
if (id == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var todo = await _context.Todo | ||
.SingleOrDefaultAsync(m => m.ID == id); | ||
if (todo == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return View(todo); | ||
} | ||
|
||
// GET: Todos/Create | ||
public IActionResult Create() | ||
{ | ||
return View(); | ||
} | ||
|
||
// POST: Todos/Create | ||
// To protect from overposting attacks, please enable the specific properties you want to bind to, for | ||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598. | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> Create([Bind("ID,Description,CreatedDate")] Todo todo) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
_context.Add(todo); | ||
await _context.SaveChangesAsync(); | ||
return RedirectToAction("Index"); | ||
} | ||
return View(todo); | ||
} | ||
|
||
// GET: Todos/Edit/5 | ||
public async Task<IActionResult> Edit(int? id) | ||
{ | ||
if (id == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var todo = await _context.Todo.SingleOrDefaultAsync(m => m.ID == id); | ||
if (todo == null) | ||
{ | ||
return NotFound(); | ||
} | ||
return View(todo); | ||
} | ||
|
||
// POST: Todos/Edit/5 | ||
// To protect from overposting attacks, please enable the specific properties you want to bind to, for | ||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598. | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> Edit(int id, [Bind("ID,Description,CreatedDate")] Todo todo) | ||
{ | ||
if (id != todo.ID) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
if (ModelState.IsValid) | ||
{ | ||
try | ||
{ | ||
_context.Update(todo); | ||
await _context.SaveChangesAsync(); | ||
} | ||
catch (DbUpdateConcurrencyException) | ||
{ | ||
if (!TodoExists(todo.ID)) | ||
{ | ||
return NotFound(); | ||
} | ||
else | ||
{ | ||
throw; | ||
} | ||
} | ||
return RedirectToAction("Index"); | ||
} | ||
return View(todo); | ||
} | ||
|
||
// GET: Todos/Delete/5 | ||
public async Task<IActionResult> Delete(int? id) | ||
{ | ||
if (id == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var todo = await _context.Todo | ||
.SingleOrDefaultAsync(m => m.ID == id); | ||
if (todo == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return View(todo); | ||
} | ||
|
||
// POST: Todos/Delete/5 | ||
[HttpPost, ActionName("Delete")] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> DeleteConfirmed(int id) | ||
{ | ||
var todo = await _context.Todo.SingleOrDefaultAsync(m => m.ID == id); | ||
_context.Todo.Remove(todo); | ||
await _context.SaveChangesAsync(); | ||
return RedirectToAction("Index"); | ||
} | ||
|
||
private bool TodoExists(int id) | ||
{ | ||
return _context.Todo.Any(e => e.ID == id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace DotNetCoreSqlDb.Models | ||
{ | ||
public class MyDatabaseContext : DbContext | ||
{ | ||
public MyDatabaseContext (DbContextOptions<MyDatabaseContext> options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<DotNetCoreSqlDb.Models.Todo> Todo { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp1.1</TargetFramework> | ||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" /> | ||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" /> | ||
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
namespace DotNetCoreSqlDb.Migrations | ||
{ | ||
public partial class Initial : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "Todo", | ||
columns: table => new | ||
{ | ||
ID = table.Column<int>(nullable: false) | ||
.Annotation("Sqlite:Autoincrement", true), | ||
CreatedDate = table.Column<DateTime>(nullable: false), | ||
Description = table.Column<string>(nullable: true) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Todo", x => x.ID); | ||
}); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Todo"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using DotNetCoreSqlDb.Models; | ||
|
||
namespace DotNetCoreSqlDb.Migrations | ||
{ | ||
[DbContext(typeof(MyDatabaseContext))] | ||
partial class MyDatabaseContextModelSnapshot : ModelSnapshot | ||
{ | ||
protected override void BuildModel(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder | ||
.HasAnnotation("ProductVersion", "1.1.2"); | ||
|
||
modelBuilder.Entity("DotNetCoreSqlDb.Models.Todo", b => | ||
{ | ||
b.Property<int>("ID") | ||
.ValueGeneratedOnAdd(); | ||
|
||
b.Property<DateTime>("CreatedDate"); | ||
|
||
b.Property<string>("Description"); | ||
|
||
b.HasKey("ID"); | ||
|
||
b.ToTable("Todo"); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace DotNetCoreSqlDb.Models | ||
{ | ||
public class Todo | ||
{ | ||
public int ID { get; set; } | ||
public string Description { get; set; } | ||
|
||
[Display(Name = "Created Date")] | ||
[DataType(DataType.Date)] | ||
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] | ||
public DateTime CreatedDate { get; set; } | ||
} | ||
} |
Oops, something went wrong.