src/ZKEACMS.Shop/Controllers/BasketController.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/* http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
using Easy.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using ZKEACMS.Shop.Filter;
using ZKEACMS.Shop.Models;
using ZKEACMS.Shop.Service;
using ZKEACMS.Shop.ViewModel;
using Easy.Extend;
namespace ZKEACMS.Shop.Controllers
{
[CustomLoginCheck]
public class BasketController : Controller
{
private readonly IBasketService _basketService;
public BasketController(IBasketService basketService)
{
_basketService = basketService;
}
[HttpPost, ValidateAntiForgeryToken]
public IActionResult Index()
{
return View(new BasketData(_basketService.Get()));
}
[HttpPost, ValidateAntiForgeryToken]
public IActionResult Add(int productId, int? quantity, string tags)
{
if (quantity.HasValue && quantity.Value < 1) return BadRequest();
var basket = new Basket { ProductId = productId, Quantity = quantity ?? 1, Description = tags };
_basketService.Add(basket);
return Json(new AjaxResult { Status = AjaxStatus.Normal, Data = new BasketData(_basketService.Get()) });
}
[HttpPost, ValidateAntiForgeryToken]
public IActionResult Update(int basketId, int quantity)
{
if (quantity < 1) return BadRequest();
var basket = _basketService.Get(basketId);
if (basket != null)
{
basket.Quantity = quantity;
_basketService.Update(basket);
}
return Json(new AjaxResult { Status = AjaxStatus.Normal, Data = new BasketData(_basketService.Get()) });
}
[HttpPost, ValidateAntiForgeryToken]
public IActionResult Remove(int basketId)
{
_basketService.Remove(basketId);
return Json(new AjaxResult { Status = AjaxStatus.Normal, Data = new BasketData(_basketService.Get()) });
}
[HttpPost, ValidateAntiForgeryToken]
public IActionResult GetBaskets()
{
后面还有 24 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。