Skip to content

Commit

Permalink
added files
Browse files Browse the repository at this point in the history
  • Loading branch information
cephalin committed Sep 4, 2017
1 parent 11913a2 commit 68d75fa
Show file tree
Hide file tree
Showing 71 changed files with 23,927 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "wwwroot/lib"
}
13 changes: 0 additions & 13 deletions CHANGELOG.md

This file was deleted.

35 changes: 35 additions & 0 deletions Controllers/HomeController.cs
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();
}
}
}
152 changes: 152 additions & 0 deletions Controllers/TodoesController.cs
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);
}
}
}
18 changes: 18 additions & 0 deletions Data/MyDatabaseContext.cs
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; }
}
}
28 changes: 28 additions & 0 deletions DotNetCoreSqlDb.csproj
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>
34 changes: 34 additions & 0 deletions Migrations/20170901142627_Initial.Designer.cs

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

32 changes: 32 additions & 0 deletions Migrations/20170901142627_Initial.cs
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");
}
}
}
33 changes: 33 additions & 0 deletions Migrations/MyDatabaseContextModelSnapshot.cs
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");
});
}
}
}
19 changes: 19 additions & 0 deletions Models/Todo.cs
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; }
}
}
Loading

0 comments on commit 68d75fa

Please sign in to comment.