-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActorsController.cs
More file actions
95 lines (83 loc) · 2.69 KB
/
Copy pathActorsController.cs
File metadata and controls
95 lines (83 loc) · 2.69 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
using eTickets.Data;
using eTickets.Data.Services;
using eTickets.Data.Static;
using eTickets.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace eTickets.Controllers
{
[Authorize(Roles = UserRoles.Admin)]
public class ActorsController : Controller
{
private readonly IActorsService _service;
public ActorsController(IActorsService service)
{
_service = service;
}
[AllowAnonymous]
public async Task<IActionResult> Index()
{
var data = await _service.GetAllAsync();
return View(data);
}
//Get: Actors/Create
public IActionResult Create()
{
return View();
}
[HttpPost]
public async Task<IActionResult> Create([Bind("FullName,ProfilePictureURL,Bio")]Actor actor)
{
if (!ModelState.IsValid)
{
return View(actor);
}
await _service.AddAsync(actor);
return RedirectToAction(nameof(Index));
}
//Get: Actors/Details/1
[AllowAnonymous]
public async Task<IActionResult> Details(int id)
{
var actorDetails = await _service.GetByIdAsync(id);
if (actorDetails == null) return View("NotFound");
return View(actorDetails);
}
//Get: Actors/Edit/1
public async Task<IActionResult> Edit(int id)
{
var actorDetails = await _service.GetByIdAsync(id);
if (actorDetails == null) return View("NotFound");
return View(actorDetails);
}
[HttpPost]
public async Task<IActionResult> Edit(int id, [Bind("Id,FullName,ProfilePictureURL,Bio")] Actor actor)
{
if (!ModelState.IsValid)
{
return View(actor);
}
await _service.UpdateAsync(id, actor);
return RedirectToAction(nameof(Index));
}
//Get: Actors/Delete/1
public async Task<IActionResult> Delete(int id)
{
var actorDetails = await _service.GetByIdAsync(id);
if (actorDetails == null) return View("NotFound");
return View(actorDetails);
}
[HttpPost, ActionName("Delete")]
public async Task<IActionResult> DeleteConfirmed(int id)
{
var actorDetails = await _service.GetByIdAsync(id);
if (actorDetails == null) return View("NotFound");
await _service.DeleteAsync(id);
return RedirectToAction(nameof(Index));
}
}
}