MvcBookStore/Controllers/StoreManageController.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcBookStore.Controllers
{
[Authorize(Roles ="Admin")]
public class StoreManageController : Controller
{
Models.ICategoryRepository _categoryRepository;
Models.IBookRepository _bookRepository;
public StoreManageController()
{
_categoryRepository = new Models.CategoryRepository();
_bookRepository = new Models.BookRepository();
}
// GET: /StoreManage/
public ActionResult Index()
{
return View(_bookRepository.GetAllBooks().ToList());
}
public ActionResult Details(int id)
{
return View(_categoryRepository.GetBookById(id));
}
public ActionResult Create()
{
ViewBag.CategoryId = new SelectList(_categoryRepository.GetAllCategoties(), "CategoryId", "Name");
return View();
}
[HttpPost]
public ActionResult Create(Models.Books book)
{
if(ModelState.IsValid )
{
_bookRepository.AddToBooks(book);
return RedirectToAction("Index");
}
else
{
ViewBag.CategoryId = new SelectList(_categoryRepository.GetAllCategoties(), "CategoryId", "Name");
return View(book);
}
}
public ActionResult Edit(int id)
{
Models.Books book = _bookRepository.GetBooksById(id);
if (book == null)
{
return HttpNotFound();
}
else
{
ViewBag.CategoryId = new SelectList(_categoryRepository.GetAllCategoties(), "CategoryId", "Name");
后面还有 37 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。