Skip to content

Commit 279cf35

Browse files
committed
Kitap modeline yeni fotograf alanlari eklendi.Kategori,Kitap,Yazar ve Dil modelleri icin ayri controllerlar olusturuldu.Her biri icin crud fonksiyonlari olusturuldu.
1 parent c43d1c1 commit 279cf35

31 files changed

Lines changed: 1856 additions & 273 deletions

BookstoreProject/Controllers/AdminController.cs

Lines changed: 2 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Mvc.Rendering;
7+
using Microsoft.EntityFrameworkCore;
8+
using BookstoreProject.Data;
9+
using BookstoreProject.Models;
10+
using Microsoft.AspNetCore.Authorization;
11+
12+
namespace BookstoreProject.Controllers
13+
{
14+
[Authorize(Roles = "Admin")]
15+
public class AuthorsController : Controller
16+
{
17+
private readonly ApplicationDbContext _context;
18+
19+
public AuthorsController(ApplicationDbContext context)
20+
{
21+
_context = context;
22+
}
23+
24+
25+
public async Task<IActionResult> Index()
26+
{
27+
return View(await _context.Authors.ToListAsync());
28+
}
29+
30+
31+
public async Task<IActionResult> Details(int? id)
32+
{
33+
if (id == null)
34+
{
35+
return NotFound();
36+
}
37+
38+
var author = await _context.Authors
39+
.FirstOrDefaultAsync(m => m.Id == id);
40+
if (author == null)
41+
{
42+
return NotFound();
43+
}
44+
45+
return View(author);
46+
}
47+
48+
49+
public IActionResult Create()
50+
{
51+
return View();
52+
}
53+
54+
55+
[HttpPost]
56+
[ValidateAntiForgeryToken]
57+
public async Task<IActionResult> Create([Bind("Id,Name,Active")] Author author)
58+
{
59+
if (ModelState.IsValid)
60+
{
61+
author.Active = true;
62+
_context.Add(author);
63+
await _context.SaveChangesAsync();
64+
return RedirectToAction(nameof(Index));
65+
}
66+
return View(author);
67+
}
68+
69+
70+
public async Task<IActionResult> Edit(int? id)
71+
{
72+
if (id == null)
73+
{
74+
return NotFound();
75+
}
76+
77+
var author = await _context.Authors.FindAsync(id);
78+
if (author == null)
79+
{
80+
return NotFound();
81+
}
82+
return View(author);
83+
}
84+
85+
86+
[HttpPost]
87+
[ValidateAntiForgeryToken]
88+
public async Task<IActionResult> Edit(int id, [Bind("Id,Name,Active")] Author author)
89+
{
90+
if (id != author.Id)
91+
{
92+
return NotFound();
93+
}
94+
95+
if (ModelState.IsValid)
96+
{
97+
try
98+
{
99+
_context.Update(author);
100+
await _context.SaveChangesAsync();
101+
}
102+
catch (DbUpdateConcurrencyException)
103+
{
104+
if (!AuthorExists(author.Id))
105+
{
106+
return NotFound();
107+
}
108+
else
109+
{
110+
throw;
111+
}
112+
}
113+
return RedirectToAction(nameof(Index));
114+
}
115+
return View(author);
116+
}
117+
118+
119+
public async Task<IActionResult> Delete(int? id)
120+
{
121+
if (id == null)
122+
{
123+
return NotFound();
124+
}
125+
126+
var author = await _context.Authors
127+
.FirstOrDefaultAsync(m => m.Id == id);
128+
if (author == null)
129+
{
130+
return NotFound();
131+
}
132+
133+
return View(author);
134+
}
135+
136+
137+
[HttpPost, ActionName("Delete")]
138+
[ValidateAntiForgeryToken]
139+
public async Task<IActionResult> DeleteConfirmed(int id)
140+
{
141+
var author = await _context.Authors.FindAsync(id);
142+
_context.Authors.Remove(author);
143+
await _context.SaveChangesAsync();
144+
return RedirectToAction(nameof(Index));
145+
}
146+
147+
private bool AuthorExists(int id)
148+
{
149+
return _context.Authors.Any(e => e.Id == id);
150+
}
151+
}
152+
}

0 commit comments

Comments
 (0)