forked from azure-appservice-samples/PhotoGalleryTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew.cshtml
49 lines (43 loc) · 1.62 KB
/
New.cshtml
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
@section Scripts {
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
}
@{
WebSecurity.RequireAuthenticatedUser();
Page.Title = "New Gallery";
Validation.RequireField("name", "You must specify a gallery name.");
if (IsPost && Validation.IsValid())
{
var galleryName = Request["Name"];
var db = Database.Open("PhotoGallery");
var nameExists = db.QueryValue("SELECT COUNT(*) FROM Galleries WHERE LOWER(Name) = LOWER(@0)", galleryName) > 0;
if (nameExists)
{
ModelState.AddError("Name", "A gallery with the supplied name already exists.");
}
else
{
//Create Gallery
db.Execute("INSERT INTO Galleries (Name) VALUES (@0)", galleryName);
// And redirect
Response.Redirect(Href("View", db.GetLastInsertId()));
}
}
}
<h1>New Gallery</h1>
<form method="post" action="">
<fieldset>
<legend>New Gallery</legend>
<ol>
<li>
<label for="name">Name</label>
<input type="text" id="name" name="name" title="Gallery name" placeholder="Gallery name" @Validation.For("name")/>
@Html.ValidationMessage("Name")
</li>
</ol>
<p class="form-actions" data-role="controlgroup" data-type="horizontal">
<input type="submit" data-role="button" value="Create" title="Create gallery" />
<a data-role="button" href="~/" title="Return to galleries">Cancel</a>
</p>
</fieldset>
</form>