Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

1 using System;

2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.Linq;
5 using System.Web;
6 using System.Web.Mvc;
7 using System.Web.Routing;
8
9 //DO NOT MODIFY ANYTHING HERE
10 namespace RestaurantManagementSystem.CustomFilters
11 {
12 public class CustomExceptionFilterAttribute : FilterAttribute, IExceptionFilter
13
14 {
15 public void OnException(ExceptionContext filterContext)
16 {
17 ConsoleLog(filterContext.Exception.Message);
18 }
19
20 static string scriptTag = "<script type=\"\" language=\"\">{0}</script>";
21
22 public static void ConsoleLog(string message)
23 {
24 string function = "console.log('{0}');";
25 string log = string.Format(GenerateCodeFromFunction(function), message);
26 HttpContext.Current.Response.Write(log);
27 }
28
29 static string GenerateCodeFromFunction(string function)
30 {
31 return string.Format(scriptTag, function);
32 }
33
34
35 }
36 }
37
38 @*Details view code goes here*@
39 @model RestaurantManagementSystem.Models.Restaurant
40
41 @{
42 ViewBag.Title = "Details";
43 Layout = "~/Views/Shared/_Layout.cshtml";
44 }
45
46 <h4>Restaurant Added Successfully!</h4>
47 <hr />
48 <div>
49 @*<h4>Restaurant</h4>
50 <hr />*@
51 <dl class="dl-horizontal">
52 <dt>
53 @Html.DisplayNameFor(model => model.Name)
54 </dt>
55
56 <dd>
57 @Html.DisplayFor(model => model.Name)
58 </dd>
59
60 <dt>
61 @Html.DisplayNameFor(model => model.Cuisine)
62 </dt>
63
64 <dd>
65 @Html.DisplayFor(model => model.Cuisine)
66 </dd>
67 <dt>
68 @Html.DisplayNameFor(model => model.LaunchDate)
69 </dt>
70
71 <dd>
72 @Html.DisplayFor(model => model.LaunchDate)
73 </dd>
74 <dt>
75 @Html.DisplayNameFor(model => model.OnlineOrders)
76 </dt>
77
78 <dd>
79 @Html.DisplayFor(model => model.OnlineOrders)
80 </dd>
81
82 </dl>
83 </div>
84 <p>
85 @*@Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |*@
86 @Html.ActionLink("Back to List", "Index")
87 </p>
88 @*Index view code goes here*@
89 @model IEnumerable<RestaurantManagementSystem.Models.Restaurant>
90
91 @{
92 ViewBag.Title = "Index";
93 Layout = "~/Views/Shared/_Layout.cshtml";
94 }
95
96 <h2>Index</h2>
97
98 <p>
99 @Html.ActionLink("Create New","AddRestaurant")
100 </p>
101 <table class="table">
102 <tr>
103 <th>
104 @Html.DisplayNameFor(model => model.Name)
105 </th>
106 <th>
107 @Html.DisplayNameFor(model => model.Cuisine)
108 </th>
109 <th>
110 @Html.DisplayNameFor(model => model.LaunchDate)
111 </th>
112 <th>
113 @Html.DisplayNameFor(model => model.OnlineOrders)
114 </th>
115 <th></th>
116 </tr>
117
118 @foreach (var item in Model) {
119 <tr>
120 <td>
121 @Html.DisplayFor(modelItem => item.Name)
122 </td>
123 <td>
124 @Html.DisplayFor(modelItem => item.Cuisine)
125 </td>
126 <td>
127 @Html.DisplayFor(modelItem => item.LaunchDate)
128 </td>
129 <td>
130 @Html.DisplayFor(modelItem => item.OnlineOrders)
131 </td>
132 @*<td>
133 @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
134 @Html.ActionLink("Details", "Details", new { id=item.Id }) |
135 @Html.ActionLink("Delete", "Delete", new { id=item.Id })
136 </td>*@
137 </tr>
138 }
139
140 </table>
141
142
143 using System;
144 using System.ComponentModel.DataAnnotations;
145 using System.ComponentModel;
146 //DO NOT MODIFY ANYTHING HERE
147 namespace RestaurantManagementSystem.Models
148 {
149 public class Restaurant
150 {
151 [Key]
152 public int Id { get; set; }
153
154 [Required(ErrorMessage = "Please Provide Restaurant Name")]
155 [MaxLength(255)]
156 public string Name { get; set; }
157
158 //[Required(ErrorMessage = "Please Select Cuisine Type")]
159 [Display(Name = "Type of food")]
160 [DefaultValue("None")]
161 public CuisineType? Cuisine { get; set; }
162
163 [Required(ErrorMessage = "Please Provide Online Orders")]
164 [Display(Name = "Open for Online Orders?")]
165 public bool OnlineOrders { get; set; }
166
167 [Required(ErrorMessage = "Please Provide Valid Date")]
168 [DataType(DataType.Date)]
169 [DisplayFormat(DataFormatString = "{0:dd-MM-yy}", ApplyFormatInEditMode =
true)]
170 public DateTime? LaunchDate { get; set; }
171
172
173 }
174 }
175
176 using System;
177 using System.Linq;
178 using System.Web.Mvc;
179 using RestaurantManagementSystem.Models;
180
181
182 //DO NOT MODIFY THE NAMESPACE AND CONTROLLER NAME
183 namespace RestaurantManagementSystem.Controllers
184 {
185
186 public class RestaurantController : Controller
187 {
188 RestaurantManagementDbContext context = new RestaurantManagementDbContext();
189 [HttpGet]
190 // GET: Restaurant
191 public ActionResult Index()
192 {
193
194 var context = new RestaurantManagementDbContext();
195 var restaurant=context.Restaurants.ToList();
196 return View(restaurant);
197
198 }
199 [HttpGet]
200 public ActionResult AddRestaurant()
201 {
202 var viewModel = new Restaurant();
203 return View(viewModel);
204
205 }
206 [HttpPost]
207 //[CustomExceptionFilterAttribute]
208 public ActionResult AddRestaurant(Restaurant restaurant) //DO NOT change
the action name
209 {
210 if (ModelState.IsValid)
211 {
212 var context = new RestaurantManagementDbContext();
213 context.Restaurants.Add(restaurant);
214 context.SaveChanges();
215 //return View("Details", restaurant);
216 //return RedirectToAction("Details", restaurant);
217 return RedirectToAction("Details",new { id = restaurant.Id });
218
219 }
220 return View(restaurant);
221 }
222 public ActionResult Details(int? id)
223 {
224 var context = new RestaurantManagementDbContext();
225 Restaurant res = null;
226 if (id != null)
227 {
228 res = context.Restaurants.Where(model => model.Id ==
id).FirstOrDefault();
229 return View(res);
230 }
231 return View();
232 }
233 }
234 }
235
236
237 using RestaurantManagementSystem.Models;
238 using System;
239 using System.Collections.Generic;
240 using System.Data.Entity;
241 using System.Linq;
242 using System.Text;
243 using System.Threading.Tasks;
244
245 //DO NOT MODIFY THE NAMESPACE
246 namespace RestaurantManagementSystem.Models
247 {
248 public class RestaurantManagementDbContext : DbContext
249 {
250 //code goes here
251 public virtual DbSet<Restaurant> Restaurants {get;set;}
252
253 /// <summary>
254 /// Constructor to initialize RestaurantManagementDbContext object
255 /// </summary>
256 public RestaurantManagementDbContext() : base("RMS_DB")
257 {
258 //no code here
259 }
260
261
262 }
263 }
264
265 <!DOCTYPE html>
266 <html>
267 <head>
268 <meta charset="utf-8" />
269 <meta name="viewport" content="width=device-width, initial-scale=1.0">
270 <title>@ViewBag.Title - Restaurant Management Application</title>
271 @Styles.Render("~/Content/css")
272 @Scripts.Render("~/bundles/modernizr")
273 </head>
274 <body>
275
276
277 @*Nav bar with home page link and restaurant list link code goes here*@
278 <div class="navbar navbar-inverse navbar-fixed-top">
279 <div class="container">
280 <div class="navbar-header">
281 <button type="button" class="navbar-toggle" data-toggle="collapse"
data-target=".navbar-collapse">
282 <span class="icon-bar"></span>
283 <span class="icon-bar"></span>
284 <span class="icon-bar"></span>
285 </button>
286 @Html.ActionLink("Restaurant Management System", "Index",
"Restaurant", new { area = "" }, new { @class = "navbar-brand" })
287 </div>
288 <div class="navbar-collapse collapse">
289 <ul class="nav navbar-nav">
290 <li>@Html.ActionLink("RestaurantList",
"Index", "Restaurant")</li>
291 </ul>
292 </div>
293 </div>
294 </div>
295 <div class="container body-content">
296 @RenderBody()
297 <hr />
298 <footer>
299 <p>&copy; @DateTime.Now.Year - Restaurant Management Application</p>
300 </footer>
301 </div>
302
303 @Scripts.Render("~/bundles/jquery")
304 @Scripts.Render("~/bundles/bootstrap")
305 @RenderSection("scripts", required: false)
306 </body>
307 </html>
308
309 @*AddRestaurant view code goes here*@
310 @model RestaurantManagementSystem.Models.Restaurant
311
312 @{
313 ViewBag.Title = "AddRestaurant";
314 Layout = "~/Views/Shared/_Layout.cshtml";
315 }
316
317 @*<h2>AddRestaurant</h2>*@
318
319
320 @using (Html.BeginForm("AddRestaurant", "Restaurant", FormMethod.Post))
321 {
322 @Html.AntiForgeryToken()
323 <h2>Create</h2>
324 <div class="form-horizontal">
325 <h4>Restaurant</h4>
326 <hr />
327 @Html.ValidationSummary(true, "", new { @class = "text-danger" })
328 <div class="form-group">
329 @Html.LabelFor(model => model.Name, htmlAttributes: new { @class =
"control-label col-md-2" })
330 <div class="col-md-10">
331 @Html.EditorFor(model => model.Name, new { htmlAttributes = new {
@class = "form-control", @id = "Name" } })
332 @Html.ValidationMessageFor(model => model.Name, "", new { @class =
"text-danger" })
333 </div>
334 </div>
335
336 @*<div class="form-group">
337 @Html.LabelFor(model => model.Cuisine, htmlAttributes: new { @class =
"control-label col-md-2" })
338 <div class="col-md-10">
339 @Html.EnumDropDownListFor(model => model.Cuisine, "None", new {
htmlAttributes = new { @class = "form-control", @id = "Type of Food"
} })
340 @Html.ValidationMessageFor(model => model.Cuisine, "", new { @class
= "text-danger" })
341 </div>
342 </div>*@
343 <div class="form-group">
344 @Html.LabelFor(model => model.Cuisine, htmlAttributes: new { @class =
"control-label col-md-2" })
345 <div class="col-md-10">
346 @Html.EnumDropDownListFor(model => model.Cuisine, "None",
htmlAttributes: new { @class = "form-control", @id = "Type of Food" })
347 @Html.ValidationMessageFor(model => model.Cuisine, "", new { @class
= "text-danger" })
348 </div>
349 </div>
350
351
352
353 <div class="form-group">
354 @Html.LabelFor(model => model.LaunchDate, htmlAttributes: new { @class =
"control-label col-md-2" })
355 <div class="col-md-10">
356 @Html.EditorFor(model => model.LaunchDate, "dd/mm/yyyy", new {
htmlAttributes = new { @class = "form-control", @id = "LaunchDate" }
})
357 @Html.ValidationMessageFor(model => model.LaunchDate, "", new {
@class = "text-danger" })
358 </div>
359 </div>
360 <div class="form-group">
361 @Html.LabelFor(model => model.OnlineOrders, htmlAttributes: new { @class
= "control-label col-md-2" })
362 <div class="col-md-10">
363 <div class="checkbox">
364 @Html.EditorFor(model => model.OnlineOrders)
365 @Html.ValidationMessageFor(model => model.OnlineOrders, "", new
{ @class = "text-danger" })
366 </div>
367 </div>
368 </div>
369
370 <div class="form-group">
371 <div class="col-md-offset-2 col-md-10">
372 <input type="submit" value="Add Restaurant" id="Submit" class="btn
btn-default" />
373 </div>
374 </div>
375 </div>
376 }
377
378 <div>
379 @Html.ActionLink("Back to List", "Index")
380 </div>
381
382 @section Scripts {
383 @Scripts.Render("~/bundles/jqueryval")
384 }
385
386
387 using System;
388 using System.Collections.Generic;
389 using System.Linq;
390 using System.Web;
391
392 //DO NOT MODIFY ANYTHING HERE
393 namespace RestaurantManagementSystem.Models
394 {
395 public enum CuisineType
396 {
397 Italian,
398 Indian,
399 French,
400 Mexican,
401 Chineese,
402 Japaneese,
403 Iranian,
404 Spanish,
405 Greece,
406 American,
407 Arabian
408 }
409 }
410
411
412 @{
413 Layout = "~/Views/Shared/_Layout.cshtml";
414 }
415
416
417
418
419
420
421

You might also like