Skip to content

Commit

Permalink
Adding a form to create restaurants
Browse files Browse the repository at this point in the history
  • Loading branch information
gorohoroh committed Jul 5, 2018
1 parent ddc5a0e commit 317f2e8
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions OdeToFoodRider/OdeToFoodRider/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ public IActionResult Details(int id)

return View(model);
}

public IActionResult Create()
{
return View();
}
}
}
10 changes: 10 additions & 0 deletions OdeToFoodRider/OdeToFoodRider/Models/CuisineType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace OdeToFoodRider.Models
{
public enum CuisineType
{
None,
Italian,
French,
German
}
}
1 change: 1 addition & 0 deletions OdeToFoodRider/OdeToFoodRider/Models/Restaurant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public class Restaurant
{
public int Id { get; set; }
public string Name { get; set; }
public CuisineType Cuisine { get; set; }
}
}
23 changes: 23 additions & 0 deletions OdeToFoodRider/OdeToFoodRider/Views/Home/Create.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@using OdeToFoodRider.Models
@model OdeToFoodRider.Models.Restaurant

<!DOCTYPE html>

<html>
<head>
<title>Add a Restaurant</title>
</head>
<body>
<h1>Create</h1>

<input asp-for="Name"/>

@*VSRD: Rider's code analysis bug in the asp-items expression below: RSRP-469518 *@
<select asp-for="Cuisine" asp-items="@Html.GetEnumSelectList<CuisineType>()"></select>

<input type="submit" name="save" value="Save"/>
<div>

</div>
</body>
</html>
2 changes: 2 additions & 0 deletions OdeToFoodRider/OdeToFoodRider/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
}
</table>

<a asp-action="Create">Add Restaurant</a>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ public IActionResult Details(int id)
// VSRD: Visual Studio doesn't see that the view isn't resolved and doesn't suggest to create one.
return View(model);
}

public IActionResult Create()
{
return View();
}
}
}
15 changes: 15 additions & 0 deletions OdeToFoodVisualStudio/OdeToFoodVisualStudio/Models/CuisineType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace OdeToFoodVisualStudio.Models
{
public enum CuisineType
{
None,
Italian,
French,
German
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public class Restaurant
{
public int Id { get; set; }
public string Name { get; set; }
public CuisineType Cuisine { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@using OdeToFoodVisualStudio.Models
@model OdeToFoodVisualStudio.Models.Restaurant
@* VSRD: Visual Studio gives no import suggestions for model declaration - have to type in FQN (for which there is completion) *@

<h1>Create</h1>

<form method="post">

<input asp-for="Name"/>

@* VSRD: No import action for unreferenced CuisineType, have to manually add a @using *@
<select asp-for="Cuisine" asp-items="@Html.GetEnumSelectList<CuisineType>()"></select>
@* The above won't work if the select tag is empty (auto-closed: <select/>) *@

<input type="submit" name="save" value="Save" />
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
</tr>
}
</table>
<a asp-action="Create">Add Restaurant</a>
</body>
</html>

0 comments on commit 317f2e8

Please sign in to comment.