1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Threading . Tasks ;
5+ using Microsoft . AspNetCore . Http ;
6+ using Microsoft . AspNetCore . Mvc ;
7+ using UnitTestingDemo . Models ;
8+ using UnitTestingDemo . Services . Interfaces ;
9+
10+ namespace UnitTestingDemo . Controllers
11+ {
12+ public class BookController : Controller
13+ {
14+ private readonly IBookService _bookService ;
15+
16+ public BookController ( IBookService bookService )
17+ {
18+ _bookService = bookService ;
19+ }
20+ // GET: Book
21+ public ActionResult Index ( )
22+ {
23+ var bookListViewModel = new BookListViewModel { Books = _bookService . GetAll ( ) } ;
24+ return View ( bookListViewModel ) ;
25+ }
26+
27+ // GET: Book/Details/5
28+ public ActionResult Details ( int id )
29+ {
30+ return View ( ) ;
31+ }
32+
33+ // GET: Book/Create
34+ public ActionResult Create ( )
35+ {
36+ return View ( ) ;
37+ }
38+
39+ // POST: Book/Create
40+ [ HttpPost ]
41+ [ ValidateAntiForgeryToken ]
42+ public ActionResult Create ( IFormCollection collection )
43+ {
44+ try
45+ {
46+ // TODO: Add insert logic here
47+
48+ return RedirectToAction ( nameof ( Index ) ) ;
49+ }
50+ catch
51+ {
52+ return View ( ) ;
53+ }
54+ }
55+
56+ // GET: Book/Edit/5
57+ public ActionResult Edit ( int id )
58+ {
59+ return View ( ) ;
60+ }
61+
62+ // POST: Book/Edit/5
63+ [ HttpPost ]
64+ [ ValidateAntiForgeryToken ]
65+ public ActionResult Edit ( int id , IFormCollection collection )
66+ {
67+ try
68+ {
69+ // TODO: Add update logic here
70+
71+ return RedirectToAction ( nameof ( Index ) ) ;
72+ }
73+ catch
74+ {
75+ return View ( ) ;
76+ }
77+ }
78+
79+ // GET: Book/Delete/5
80+ public ActionResult Delete ( int id )
81+ {
82+ return View ( ) ;
83+ }
84+
85+ // POST: Book/Delete/5
86+ [ HttpPost ]
87+ [ ValidateAntiForgeryToken ]
88+ public ActionResult Delete ( int id , IFormCollection collection )
89+ {
90+ try
91+ {
92+ // TODO: Add delete logic here
93+
94+ return RedirectToAction ( nameof ( Index ) ) ;
95+ }
96+ catch
97+ {
98+ return View ( ) ;
99+ }
100+ }
101+ }
102+ }
0 commit comments