-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHotelController.cs
More file actions
102 lines (93 loc) · 2.64 KB
/
HotelController.cs
File metadata and controls
102 lines (93 loc) · 2.64 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AsyncInn.Web.Models;
using AsyncInn.Web.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace AsyncInn.Web.Controllers
{
public class HotelController : Controller
{
IHotelService hotelService;
public HotelController(IHotelService hotelService)
{
this.hotelService = hotelService;
}
// GET: HotelController
public async Task<ActionResult> Index()
{
var hotels = await hotelService.GetHotels();
return View(hotels.OrderBy(hotels => hotels.HotelName));
}
// GET: HotelController/Details/5
public async Task<ActionResult> Details(long id)
{
var hotel = await hotelService.GetHotelById(id);
return View(hotel);
}
//GET: Hotel/Create
// GET: HotelController/Delete/5
public ActionResult Create()
{
return View();
}
// POST: Hotel/Create
[HttpPost]
public async Task <ActionResult> Create(Hotel hotel)
{
try
{
await hotelService.Create(hotel);
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// Get: HotelController/Edit/5
public async Task<ActionResult> Edit(long id)
{
var hotel = await hotelService.GetHotelById(id);
return View(hotel);
}
// POST: HotelController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Edit(long id, Hotel hotel)
{
try
{
await hotelService.Edit(id, hotel);
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: HotelController/Delete/5
public async Task <ActionResult> Delete(long id)
{
var hotel = await hotelService.GetHotelById(id);
return View(hotel);
}
// POST: HotelController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task <ActionResult> Delete(long id, IFormCollection collection)
{
try
{
await hotelService.Delete(id);
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
}
}