forked from dotnet-presentations/aspnetcore-for-beginners
-
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
NORTHAMERICA\mnaggaga
committed
Apr 2, 2018
1 parent
b3f68d5
commit 6c20406
Showing
170 changed files
with
49,007 additions
and
8 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
43 changes: 43 additions & 0 deletions
43
Tutorial/2-Add a model/RazorPagesMovie/Migrations/20180402133827_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
Tutorial/2-Add a model/RazorPagesMovie/Migrations/20180402133827_InitialCreate.cs
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,34 @@ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace RazorPagesMovie.Migrations | ||
{ | ||
public partial class InitialCreate : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "Movie", | ||
columns: table => new | ||
{ | ||
ID = table.Column<int>(nullable: false) | ||
.Annotation("Sqlite:Autoincrement", true), | ||
Genre = table.Column<string>(nullable: true), | ||
Price = table.Column<decimal>(nullable: false), | ||
ReleaseDate = table.Column<DateTime>(nullable: false), | ||
Title = table.Column<string>(nullable: true) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Movie", x => x.ID); | ||
}); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Movie"); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
Tutorial/2-Add a model/RazorPagesMovie/Migrations/MovieContextModelSnapshot.cs
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,42 @@ | ||
// <auto-generated /> | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using Microsoft.EntityFrameworkCore.Storage.Internal; | ||
using RazorPagesMovie.Models; | ||
using System; | ||
|
||
namespace RazorPagesMovie.Migrations | ||
{ | ||
[DbContext(typeof(MovieContext))] | ||
partial class MovieContextModelSnapshot : ModelSnapshot | ||
{ | ||
protected override void BuildModel(ModelBuilder modelBuilder) | ||
{ | ||
#pragma warning disable 612, 618 | ||
modelBuilder | ||
.HasAnnotation("ProductVersion", "2.0.1-rtm-125"); | ||
|
||
modelBuilder.Entity("RazorPagesMovie.Models.Movie", b => | ||
{ | ||
b.Property<int>("ID") | ||
.ValueGeneratedOnAdd(); | ||
|
||
b.Property<string>("Genre"); | ||
|
||
b.Property<decimal>("Price"); | ||
|
||
b.Property<DateTime>("ReleaseDate"); | ||
|
||
b.Property<string>("Title"); | ||
|
||
b.HasKey("ID"); | ||
|
||
b.ToTable("Movie"); | ||
}); | ||
#pragma warning restore 612, 618 | ||
} | ||
} | ||
} |
Binary file not shown.
49 changes: 49 additions & 0 deletions
49
Tutorial/2-Add a model/RazorPagesMovie/Pages/Movies/Create.cshtml
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,49 @@ | ||
@page | ||
@model RazorPagesMovie.Pages.Movies.CreateModel | ||
|
||
@{ | ||
ViewData["Title"] = "Create"; | ||
} | ||
|
||
<h2>Create</h2> | ||
|
||
<h4>Movie</h4> | ||
<hr /> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
<form method="post"> | ||
<div asp-validation-summary="ModelOnly" class="text-danger"></div> | ||
<div class="form-group"> | ||
<label asp-for="Movie.Title" class="control-label"></label> | ||
<input asp-for="Movie.Title" class="form-control" /> | ||
<span asp-validation-for="Movie.Title" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Movie.ReleaseDate" class="control-label"></label> | ||
<input asp-for="Movie.ReleaseDate" class="form-control" /> | ||
<span asp-validation-for="Movie.ReleaseDate" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Movie.Genre" class="control-label"></label> | ||
<input asp-for="Movie.Genre" class="form-control" /> | ||
<span asp-validation-for="Movie.Genre" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Movie.Price" class="control-label"></label> | ||
<input asp-for="Movie.Price" class="form-control" /> | ||
<span asp-validation-for="Movie.Price" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<input type="submit" value="Create" class="btn btn-default" /> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<a asp-page="Index">Back to List</a> | ||
</div> | ||
|
||
@section Scripts { | ||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");} | ||
} |
42 changes: 42 additions & 0 deletions
42
Tutorial/2-Add a model/RazorPagesMovie/Pages/Movies/Create.cshtml.cs
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,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
using RazorPagesMovie.Models; | ||
|
||
namespace RazorPagesMovie.Pages.Movies | ||
{ | ||
public class CreateModel : PageModel | ||
{ | ||
private readonly RazorPagesMovie.Models.MovieContext _context; | ||
|
||
public CreateModel(RazorPagesMovie.Models.MovieContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public IActionResult OnGet() | ||
{ | ||
return Page(); | ||
} | ||
|
||
[BindProperty] | ||
public Movie Movie { get; set; } | ||
|
||
public async Task<IActionResult> OnPostAsync() | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return Page(); | ||
} | ||
|
||
_context.Movie.Add(Movie); | ||
await _context.SaveChangesAsync(); | ||
|
||
return RedirectToPage("./Index"); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Tutorial/2-Add a model/RazorPagesMovie/Pages/Movies/Delete.cshtml
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,46 @@ | ||
@page | ||
@model RazorPagesMovie.Pages.Movies.DeleteModel | ||
|
||
@{ | ||
ViewData["Title"] = "Delete"; | ||
} | ||
|
||
<h2>Delete</h2> | ||
|
||
<h3>Are you sure you want to delete this?</h3> | ||
<div> | ||
<h4>Movie</h4> | ||
<hr /> | ||
<dl class="dl-horizontal"> | ||
<dt> | ||
@Html.DisplayNameFor(model => model.Movie.Title) | ||
</dt> | ||
<dd> | ||
@Html.DisplayFor(model => model.Movie.Title) | ||
</dd> | ||
<dt> | ||
@Html.DisplayNameFor(model => model.Movie.ReleaseDate) | ||
</dt> | ||
<dd> | ||
@Html.DisplayFor(model => model.Movie.ReleaseDate) | ||
</dd> | ||
<dt> | ||
@Html.DisplayNameFor(model => model.Movie.Genre) | ||
</dt> | ||
<dd> | ||
@Html.DisplayFor(model => model.Movie.Genre) | ||
</dd> | ||
<dt> | ||
@Html.DisplayNameFor(model => model.Movie.Price) | ||
</dt> | ||
<dd> | ||
@Html.DisplayFor(model => model.Movie.Price) | ||
</dd> | ||
</dl> | ||
|
||
<form method="post"> | ||
<input type="hidden" asp-for="Movie.ID" /> | ||
<input type="submit" value="Delete" class="btn btn-default" /> | | ||
<a asp-page="./Index">Back to List</a> | ||
</form> | ||
</div> |
58 changes: 58 additions & 0 deletions
58
Tutorial/2-Add a model/RazorPagesMovie/Pages/Movies/Delete.cshtml.cs
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,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.EntityFrameworkCore; | ||
using RazorPagesMovie.Models; | ||
|
||
namespace RazorPagesMovie.Pages.Movies | ||
{ | ||
public class DeleteModel : PageModel | ||
{ | ||
private readonly RazorPagesMovie.Models.MovieContext _context; | ||
|
||
public DeleteModel(RazorPagesMovie.Models.MovieContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[BindProperty] | ||
public Movie Movie { get; set; } | ||
|
||
public async Task<IActionResult> OnGetAsync(int? id) | ||
{ | ||
if (id == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
Movie = await _context.Movie.SingleOrDefaultAsync(m => m.ID == id); | ||
|
||
if (Movie == null) | ||
{ | ||
return NotFound(); | ||
} | ||
return Page(); | ||
} | ||
|
||
public async Task<IActionResult> OnPostAsync(int? id) | ||
{ | ||
if (id == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
Movie = await _context.Movie.FindAsync(id); | ||
|
||
if (Movie != null) | ||
{ | ||
_context.Movie.Remove(Movie); | ||
await _context.SaveChangesAsync(); | ||
} | ||
|
||
return RedirectToPage("./Index"); | ||
} | ||
} | ||
} |
Oops, something went wrong.