forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsertItem.cshtml.cs
63 lines (52 loc) · 1.12 KB
/
InsertItem.cshtml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using NHibernate.Example.Web.Models;
namespace NHibernate.Example.Web.Pages
{
public class InsertItemModel : PageModel
{
[BindProperty]
public InsertItemEvent NewItem { get; set; }
private readonly ISession _session;
public InsertItemModel(ISession session)
{
_session = session;
}
public void OnGet()
{
}
public IActionResult OnPost()
{
if (!ModelState.IsValid)
{
return Page();
}
using (var tx = _session.BeginTransaction())
{
var item = new Item
{
Price = NewItem.Price,
Description = NewItem.Description,
};
_session.Save(item);
tx.Commit();
}
return RedirectToPage("/ViewData");
}
public IActionResult OnPostCancel()
{
return RedirectToPage("/ViewData");
}
public class InsertItemEvent
{
[Required, Range(0.0, double.MaxValue)]
public decimal Price { get; set; }
public string Description { get; set; }
}
}
}