@@ -22,161 +22,11 @@ public AdminController(ApplicationDbContext context)
2222 _context = context ;
2323 }
2424
25- // GET: Admin
25+
2626 public IActionResult Index ( )
2727 {
28-
29- return View ( ) ;
30- }
31- public async Task < IActionResult > BookList ( )
32- {
33- var applicationDbContext = _context . Books . Include ( b => b . Author ) . Include ( b => b . Category ) . Include ( b => b . Language ) ;
34- return View ( await applicationDbContext . ToListAsync ( ) ) ;
35- }
36-
37- // GET: Admin/Details/5
38- public async Task < IActionResult > BookDetails ( int ? id )
39- {
40- if ( id == null )
41- {
42- return NotFound ( ) ;
43- }
44-
45- var book = await _context . Books
46- . Include ( b => b . Author )
47- . Include ( b => b . Category )
48- . Include ( b => b . Language )
49- . FirstOrDefaultAsync ( m => m . Id == id ) ;
50- if ( book == null )
51- {
52- return NotFound ( ) ;
53- }
54-
55- return View ( book ) ;
56- }
57-
58- // GET: Admin/Create
59- public IActionResult BookCreate ( )
60- {
61- ViewData [ "AuthorId" ] = new SelectList ( _context . Authors , "Id" , "Name" ) ;
62- ViewData [ "CategoryId" ] = new SelectList ( _context . Categories , "Id" , "Name_TR" ) ;
63- ViewData [ "LanguageId" ] = new SelectList ( _context . Languages , "Id" , "Name_TR" ) ;
6428 return View ( ) ;
6529 }
66-
67- // POST: Admin/Create
68- // To protect from overposting attacks, enable the specific properties you want to bind to, for
69- // more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
70- [ HttpPost ]
71- [ ValidateAntiForgeryToken ]
72- public async Task < IActionResult > BookCreate ( [ Bind ( "Id,Name_TR,Name_EN,Description_TR,Description_EN,Price,Stock,PublishYear,CategoryId,LanguageId,AuthorId" ) ] Book book )
73- {
74- if ( ModelState . IsValid )
75- {
76- book . CreateDate = DateTime . Now ;
77- book . Active = true ;
78- _context . Add ( book ) ;
79- await _context . SaveChangesAsync ( ) ;
80- return RedirectToAction ( nameof ( Index ) ) ;
81- }
82- ViewData [ "AuthorId" ] = new SelectList ( _context . Authors , "Id" , "Name" , book . AuthorId ) ;
83- ViewData [ "CategoryId" ] = new SelectList ( _context . Categories , "Id" , "Name_TR" , book . CategoryId ) ;
84- ViewData [ "LanguageId" ] = new SelectList ( _context . Languages , "Id" , "Name_TR" , book . LanguageId ) ;
85- return View ( book ) ;
86- }
87-
88- // GET: Admin/Edit/5
89- public async Task < IActionResult > BookEdit ( int ? id )
90- {
91- if ( id == null )
92- {
93- return NotFound ( ) ;
94- }
95-
96- var book = await _context . Books . FindAsync ( id ) ;
97- if ( book == null )
98- {
99- return NotFound ( ) ;
100- }
101- ViewData [ "AuthorId" ] = new SelectList ( _context . Authors , "Id" , "Id" , book . AuthorId ) ;
102- ViewData [ "CategoryId" ] = new SelectList ( _context . Categories , "Id" , "Id" , book . CategoryId ) ;
103- ViewData [ "LanguageId" ] = new SelectList ( _context . Languages , "Id" , "Id" , book . LanguageId ) ;
104- return View ( book ) ;
105- }
106-
107- // POST: Admin/Edit/5
108- // To protect from overposting attacks, enable the specific properties you want to bind to, for
109- // more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
110- [ HttpPost ]
111- [ ValidateAntiForgeryToken ]
112- public async Task < IActionResult > BookEdit ( int id , [ Bind ( "Id,Name_TR,Name_EN,Description_TR,Description_EN,Price,Stock,PublishYear,CategoryId,LanguageId,AuthorId,CreateDate,Active" ) ] Book book )
113- {
114- if ( id != book . Id )
115- {
116- return NotFound ( ) ;
117- }
118-
119- if ( ModelState . IsValid )
120- {
121- try
122- {
123- _context . Update ( book ) ;
124- await _context . SaveChangesAsync ( ) ;
125- }
126- catch ( DbUpdateConcurrencyException )
127- {
128- if ( ! BookExists ( book . Id ) )
129- {
130- return NotFound ( ) ;
131- }
132- else
133- {
134- throw ;
135- }
136- }
137- return RedirectToAction ( nameof ( Index ) ) ;
138- }
139- ViewData [ "AuthorId" ] = new SelectList ( _context . Authors , "Id" , "Id" , book . AuthorId ) ;
140- ViewData [ "CategoryId" ] = new SelectList ( _context . Categories , "Id" , "Id" , book . CategoryId ) ;
141- ViewData [ "LanguageId" ] = new SelectList ( _context . Languages , "Id" , "Id" , book . LanguageId ) ;
142- return View ( book ) ;
143- }
144-
145- // GET: Admin/Delete/5
146- public async Task < IActionResult > BookDelete ( int ? id )
147- {
148- if ( id == null )
149- {
150- return NotFound ( ) ;
151- }
152-
153- var book = await _context . Books
154- . Include ( b => b . Author )
155- . Include ( b => b . Category )
156- . Include ( b => b . Language )
157- . FirstOrDefaultAsync ( m => m . Id == id ) ;
158- if ( book == null )
159- {
160- return NotFound ( ) ;
161- }
162-
163- return View ( book ) ;
164- }
165-
166-
167- [ HttpPost , ActionName ( "Delete" ) ]
168- [ ValidateAntiForgeryToken ]
169- public async Task < IActionResult > DeleteConfirmed ( int id )
170- {
171- var book = await _context . Books . FindAsync ( id ) ;
172- _context . Books . Remove ( book ) ;
173- await _context . SaveChangesAsync ( ) ;
174- return RedirectToAction ( nameof ( Index ) ) ;
175- }
176-
177- private bool BookExists ( int id )
178- {
179- return _context . Books . Any ( e => e . Id == id ) ;
180- }
30+
18131 }
18232}
0 commit comments