Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CSharp 2020 Fall
Course Materials
Commits
0d6c2bef
Commit
0d6c2bef
authored
Oct 30, 2020
by
Andres Käver
Browse files
razor
parent
4d4b663f
Changes
328
Hide whitespace changes
Inline
Side-by-side
demos/RazorPagesDemo/WebApp/Pages/GpsLocations/Create.cshtml
0 → 100644
View file @
0d6c2bef
@page
@model WebApp.Pages.GpsLocations.CreateModel
@{
ViewData["Title"] = "Create";
}
<h1>
Create
</h1>
<h4>
GpsLocation
</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=
"GpsLocation.Lat"
class=
"control-label"
></label>
<input
asp-for=
"GpsLocation.Lat"
class=
"form-control"
/>
<span
asp-validation-for=
"GpsLocation.Lat"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<label
asp-for=
"GpsLocation.Lon"
class=
"control-label"
></label>
<input
asp-for=
"GpsLocation.Lon"
class=
"form-control"
/>
<span
asp-validation-for=
"GpsLocation.Lon"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<label
asp-for=
"GpsLocation.CreatedAt"
class=
"control-label"
></label>
<input
asp-for=
"GpsLocation.CreatedAt"
class=
"form-control"
/>
<span
asp-validation-for=
"GpsLocation.CreatedAt"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<label
asp-for=
"GpsLocation.GpsSessionId"
class=
"control-label"
></label>
<select
asp-for=
"GpsLocation.GpsSessionId"
class =
"form-control"
asp-items=
"ViewBag.GpsSessionId"
></select>
</div>
<div
class=
"form-group"
>
<input
type=
"submit"
value=
"Create"
class=
"btn btn-primary"
/>
</div>
</form>
</div>
</div>
<div>
<a
asp-page=
"Index"
>
Back to List
</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
demos/RazorPagesDemo/WebApp/Pages/GpsLocations/Create.cshtml.cs
0 → 100644
View file @
0d6c2bef
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
DAL
;
using
Domain
;
namespace
WebApp.Pages.GpsLocations
{
public
class
CreateModel
:
PageModel
{
private
readonly
DAL
.
ApplicationDbContext
_context
;
public
CreateModel
(
DAL
.
ApplicationDbContext
context
)
{
_context
=
context
;
}
public
IActionResult
OnGet
()
{
ViewData
[
"GpsSessionId"
]
=
new
SelectList
(
_context
.
GpsSessions
,
"GpsSessionId"
,
"GpsSessionId"
);
return
Page
();
}
[
BindProperty
]
public
GpsLocation
GpsLocation
{
get
;
set
;
}
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://aka.ms/RazorPagesCRUD.
public
async
Task
<
IActionResult
>
OnPostAsync
()
{
if
(!
ModelState
.
IsValid
)
{
return
Page
();
}
_context
.
GpsLocations
.
Add
(
GpsLocation
);
await
_context
.
SaveChangesAsync
();
return
RedirectToPage
(
"./Index"
);
}
}
}
demos/RazorPagesDemo/WebApp/Pages/GpsLocations/Delete.cshtml
0 → 100644
View file @
0d6c2bef
@page
@model WebApp.Pages.GpsLocations.DeleteModel
@{
ViewData["Title"] = "Delete";
}
<h1>
Delete
</h1>
<h3>
Are you sure you want to delete this?
</h3>
<div>
<h4>
GpsLocation
</h4>
<hr
/>
<dl
class=
"row"
>
<dt
class=
"col-sm-2"
>
@Html.DisplayNameFor(model => model.GpsLocation.Lat)
</dt>
<dd
class=
"col-sm-10"
>
@Html.DisplayFor(model => model.GpsLocation.Lat)
</dd>
<dt
class=
"col-sm-2"
>
@Html.DisplayNameFor(model => model.GpsLocation.Lon)
</dt>
<dd
class=
"col-sm-10"
>
@Html.DisplayFor(model => model.GpsLocation.Lon)
</dd>
<dt
class=
"col-sm-2"
>
@Html.DisplayNameFor(model => model.GpsLocation.CreatedAt)
</dt>
<dd
class=
"col-sm-10"
>
@Html.DisplayFor(model => model.GpsLocation.CreatedAt)
</dd>
<dt
class=
"col-sm-2"
>
@Html.DisplayNameFor(model => model.GpsLocation.GpsSession)
</dt>
<dd
class=
"col-sm-10"
>
@Html.DisplayFor(model => model.GpsLocation.GpsSession.GpsSessionId)
</dd>
</dl>
<form
method=
"post"
>
<input
type=
"hidden"
asp-for=
"GpsLocation.GpsLocationId"
/>
<input
type=
"submit"
value=
"Delete"
class=
"btn btn-danger"
/>
|
<a
asp-page=
"./Index"
>
Back to List
</a>
</form>
</div>
demos/RazorPagesDemo/WebApp/Pages/GpsLocations/Delete.cshtml.cs
0 → 100644
View file @
0d6c2bef
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
DAL
;
using
Domain
;
namespace
WebApp.Pages.GpsLocations
{
public
class
DeleteModel
:
PageModel
{
private
readonly
DAL
.
ApplicationDbContext
_context
;
public
DeleteModel
(
DAL
.
ApplicationDbContext
context
)
{
_context
=
context
;
}
[
BindProperty
]
public
GpsLocation
GpsLocation
{
get
;
set
;
}
public
async
Task
<
IActionResult
>
OnGetAsync
(
int
?
id
)
{
if
(
id
==
null
)
{
return
NotFound
();
}
GpsLocation
=
await
_context
.
GpsLocations
.
Include
(
g
=>
g
.
GpsSession
).
FirstOrDefaultAsync
(
m
=>
m
.
GpsLocationId
==
id
);
if
(
GpsLocation
==
null
)
{
return
NotFound
();
}
return
Page
();
}
public
async
Task
<
IActionResult
>
OnPostAsync
(
int
?
id
)
{
if
(
id
==
null
)
{
return
NotFound
();
}
GpsLocation
=
await
_context
.
GpsLocations
.
FindAsync
(
id
);
if
(
GpsLocation
!=
null
)
{
_context
.
GpsLocations
.
Remove
(
GpsLocation
);
await
_context
.
SaveChangesAsync
();
}
return
RedirectToPage
(
"./Index"
);
}
}
}
demos/RazorPagesDemo/WebApp/Pages/GpsLocations/Details.cshtml
0 → 100644
View file @
0d6c2bef
@page
@model WebApp.Pages.GpsLocations.DetailsModel
@{
ViewData["Title"] = "Details";
}
<h1>
Details
</h1>
<div>
<h4>
GpsLocation
</h4>
<hr
/>
<dl
class=
"row"
>
<dt
class=
"col-sm-2"
>
@Html.DisplayNameFor(model => model.GpsLocation.Lat)
</dt>
<dd
class=
"col-sm-10"
>
@Html.DisplayFor(model => model.GpsLocation.Lat)
</dd>
<dt
class=
"col-sm-2"
>
@Html.DisplayNameFor(model => model.GpsLocation.Lon)
</dt>
<dd
class=
"col-sm-10"
>
@Html.DisplayFor(model => model.GpsLocation.Lon)
</dd>
<dt
class=
"col-sm-2"
>
@Html.DisplayNameFor(model => model.GpsLocation.CreatedAt)
</dt>
<dd
class=
"col-sm-10"
>
@Html.DisplayFor(model => model.GpsLocation.CreatedAt)
</dd>
<dt
class=
"col-sm-2"
>
@Html.DisplayNameFor(model => model.GpsLocation.GpsSession)
</dt>
<dd
class=
"col-sm-10"
>
@Html.DisplayFor(model => model.GpsLocation.GpsSession.GpsSessionId)
</dd>
</dl>
</div>
<div>
<a
asp-page=
"./Edit"
asp-route-id=
"@Model.GpsLocation.GpsLocationId"
>
Edit
</a>
|
<a
asp-page=
"./Index"
>
Back to List
</a>
</div>
demos/RazorPagesDemo/WebApp/Pages/GpsLocations/Details.cshtml.cs
0 → 100644
View file @
0d6c2bef
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
DAL
;
using
Domain
;
namespace
WebApp.Pages.GpsLocations
{
public
class
DetailsModel
:
PageModel
{
private
readonly
DAL
.
ApplicationDbContext
_context
;
public
DetailsModel
(
DAL
.
ApplicationDbContext
context
)
{
_context
=
context
;
}
public
GpsLocation
GpsLocation
{
get
;
set
;
}
public
async
Task
<
IActionResult
>
OnGetAsync
(
int
?
id
)
{
if
(
id
==
null
)
{
return
NotFound
();
}
GpsLocation
=
await
_context
.
GpsLocations
.
Include
(
g
=>
g
.
GpsSession
).
FirstOrDefaultAsync
(
m
=>
m
.
GpsLocationId
==
id
);
if
(
GpsLocation
==
null
)
{
return
NotFound
();
}
return
Page
();
}
}
}
demos/RazorPagesDemo/WebApp/Pages/GpsLocations/Edit.cshtml
0 → 100644
View file @
0d6c2bef
@page
@model WebApp.Pages.GpsLocations.EditModel
@{
ViewData["Title"] = "Edit";
}
<h1>
Edit
</h1>
<h4>
GpsLocation
</h4>
<hr
/>
<div
class=
"row"
>
<div
class=
"col-md-4"
>
<form
method=
"post"
>
<div
asp-validation-summary=
"ModelOnly"
class=
"text-danger"
></div>
<input
type=
"hidden"
asp-for=
"GpsLocation.GpsLocationId"
/>
<div
class=
"form-group"
>
<label
asp-for=
"GpsLocation.Lat"
class=
"control-label"
></label>
<input
asp-for=
"GpsLocation.Lat"
class=
"form-control"
/>
<span
asp-validation-for=
"GpsLocation.Lat"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<label
asp-for=
"GpsLocation.Lon"
class=
"control-label"
></label>
<input
asp-for=
"GpsLocation.Lon"
class=
"form-control"
/>
<span
asp-validation-for=
"GpsLocation.Lon"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<label
asp-for=
"GpsLocation.CreatedAt"
class=
"control-label"
></label>
<input
asp-for=
"GpsLocation.CreatedAt"
class=
"form-control"
/>
<span
asp-validation-for=
"GpsLocation.CreatedAt"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<label
asp-for=
"GpsLocation.GpsSessionId"
class=
"control-label"
></label>
<select
asp-for=
"GpsLocation.GpsSessionId"
class=
"form-control"
asp-items=
"ViewBag.GpsSessionId"
></select>
<span
asp-validation-for=
"GpsLocation.GpsSessionId"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<input
type=
"submit"
value=
"Save"
class=
"btn btn-primary"
/>
</div>
</form>
</div>
</div>
<div>
<a
asp-page=
"./Index"
>
Back to List
</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
demos/RazorPagesDemo/WebApp/Pages/GpsLocations/Edit.cshtml.cs
0 → 100644
View file @
0d6c2bef
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
Microsoft.EntityFrameworkCore
;
using
DAL
;
using
Domain
;
namespace
WebApp.Pages.GpsLocations
{
public
class
EditModel
:
PageModel
{
private
readonly
DAL
.
ApplicationDbContext
_context
;
public
EditModel
(
DAL
.
ApplicationDbContext
context
)
{
_context
=
context
;
}
[
BindProperty
]
public
GpsLocation
GpsLocation
{
get
;
set
;
}
public
async
Task
<
IActionResult
>
OnGetAsync
(
int
?
id
)
{
if
(
id
==
null
)
{
return
NotFound
();
}
GpsLocation
=
await
_context
.
GpsLocations
.
Include
(
g
=>
g
.
GpsSession
).
FirstOrDefaultAsync
(
m
=>
m
.
GpsLocationId
==
id
);
if
(
GpsLocation
==
null
)
{
return
NotFound
();
}
ViewData
[
"GpsSessionId"
]
=
new
SelectList
(
_context
.
GpsSessions
,
"GpsSessionId"
,
"GpsSessionId"
);
return
Page
();
}
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://aka.ms/RazorPagesCRUD.
public
async
Task
<
IActionResult
>
OnPostAsync
()
{
if
(!
ModelState
.
IsValid
)
{
return
Page
();
}
_context
.
Attach
(
GpsLocation
).
State
=
EntityState
.
Modified
;
try
{
await
_context
.
SaveChangesAsync
();
}
catch
(
DbUpdateConcurrencyException
)
{
if
(!
GpsLocationExists
(
GpsLocation
.
GpsLocationId
))
{
return
NotFound
();
}
else
{
throw
;
}
}
return
RedirectToPage
(
"./Index"
);
}
private
bool
GpsLocationExists
(
int
id
)
{
return
_context
.
GpsLocations
.
Any
(
e
=>
e
.
GpsLocationId
==
id
);
}
}
}
demos/RazorPagesDemo/WebApp/Pages/GpsLocations/Index.cshtml
0 → 100644
View file @
0d6c2bef
@page
@model WebApp.Pages.GpsLocations.IndexModel
@{
ViewData["Title"] = "Index";
}
<h1>
Index
</h1>
<p>
<a
asp-page=
"Create"
>
Create New
</a>
</p>
<table
class=
"table"
>
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.GpsLocation[0].Lat)
</th>
<th>
@Html.DisplayNameFor(model => model.GpsLocation[0].Lon)
</th>
<th>
@Html.DisplayNameFor(model => model.GpsLocation[0].CreatedAt)
</th>
<th>
@Html.DisplayNameFor(model => model.GpsLocation[0].GpsSession)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.GpsLocation) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Lat)
</td>
<td>
@Html.DisplayFor(modelItem => item.Lon)
</td>
<td>
@Html.DisplayFor(modelItem => item.CreatedAt)
</td>
<td>
@Html.DisplayFor(modelItem => item.GpsSession.GpsSessionId)
</td>
<td>
<a
asp-page=
"./Edit"
asp-route-id=
"@item.GpsLocationId"
>
Edit
</a>
|
<a
asp-page=
"./Details"
asp-route-id=
"@item.GpsLocationId"
>
Details
</a>
|
<a
asp-page=
"./Delete"
asp-route-id=
"@item.GpsLocationId"
>
Delete
</a>
</td>
</tr>
}
</tbody>
</table>
demos/RazorPagesDemo/WebApp/Pages/GpsLocations/Index.cshtml.cs
0 → 100644
View file @
0d6c2bef
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
DAL
;
using
Domain
;
namespace
WebApp.Pages.GpsLocations
{
public
class
IndexModel
:
PageModel
{
private
readonly
DAL
.
ApplicationDbContext
_context
;
public
IndexModel
(
DAL
.
ApplicationDbContext
context
)
{
_context
=
context
;
}
public
IList
<
GpsLocation
>
GpsLocation
{
get
;
set
;
}
public
async
Task
OnGetAsync
()
{
GpsLocation
=
await
_context
.
GpsLocations
.
Include
(
g
=>
g
.
GpsSession
).
ToListAsync
();
}
}
}
demos/RazorPagesDemo/WebApp/Pages/GpsSessions/Create.cshtml
0 → 100644
View file @
0d6c2bef
@page
@model WebApp.Pages.GpsSessions.CreateModel
@{
ViewData["Title"] = "Create";
}
<h1>
Create
</h1>
<h4>
GpsSession
</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=
"GpsSession.Name"
class=
"control-label"
></label>
<input
asp-for=
"GpsSession.Name"
class=
"form-control"
/>
<span
asp-validation-for=
"GpsSession.Name"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<label
asp-for=
"GpsSession.CreatedAt"
class=
"control-label"
></label>
<input
asp-for=
"GpsSession.CreatedAt"
class=
"form-control"
/>
<span
asp-validation-for=
"GpsSession.CreatedAt"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<label
asp-for=
"GpsSession.SessionLength"
class=
"control-label"
></label>
<input
asp-for=
"GpsSession.SessionLength"
class=
"form-control"
/>
<span
asp-validation-for=
"GpsSession.SessionLength"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<label
asp-for=
"GpsSession.Duration"
class=
"control-label"
></label>
<input
asp-for=
"GpsSession.Duration"
class=
"form-control"
/>
<span
asp-validation-for=
"GpsSession.Duration"
class=
"text-danger"
></span>
</div>
<div
class=
"form-group"
>
<input
type=
"submit"
value=
"Create"
class=
"btn btn-primary"
/>
</div>
</form>
</div>
</div>
<div>
<a
asp-page=
"Index"
>
Back to List
</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
demos/RazorPagesDemo/WebApp/Pages/GpsSessions/Create.cshtml.cs
0 → 100644
View file @
0d6c2bef
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
DAL
;
using
Domain
;
namespace
WebApp.Pages.GpsSessions
{
public
class
CreateModel
:
PageModel
{
private
readonly
DAL
.
ApplicationDbContext
_context
;
public
CreateModel
(
DAL
.
ApplicationDbContext
context
)
{
_context
=
context
;
}
public
IActionResult
OnGet
()
{
return
Page
();
}
[
BindProperty
]
public
GpsSession
GpsSession
{
get
;
set
;
}
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://aka.ms/RazorPagesCRUD.