server/aspnetapp/Controllers/WebApi/CancelOrderController.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using aspnetapp.Models;
using aspnetapp.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
namespace aspnetapp.Controllers.WebApi
{
[Route("api/[controller]")]
[ApiController]
public class CancelOrderController : ControllerBase
{
private readonly CounterContext _context;
private IMemoryCache _memoryCache;
private readonly IProductService _IProductService;
public CancelOrderController(CounterContext context, IMemoryCache cache, IProductService iProductService)
{
_context = context;
_IProductService = iProductService;
this._memoryCache = cache ?? throw new ArgumentNullException(nameof(cache));
}
// GET: api/<CancelOrderController>
[HttpGet]
public async Task<ActionResult> Get(int id)
{
OrderEntity? thisOrder = await _context.Orders.FindAsync(id);
if (thisOrder == null)
{
return NotFound("未找到该订单");
}
thisOrder.OrderStatus = (int)EnumCode.OrderStatus.已取消;
thisOrder.CancelTime = DateTime.Now;
if (_context.Goods.Any(s => s.Id == thisOrder.FoodsId && s.IsSpecial.GetValueOrDefault() == (int)EnumCode.yesno.是))
{
_IProductService.AddStock(thisOrder.FoodsId);
}
try
{
_context.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
return BadRequest("失败");
}
return Ok("success");
}
// POST api/<CancelOrderController>
[HttpPost]
public async Task<ActionResult> Post(int id)
{
OrderEntity? thisOrder = await _context.Orders.FindAsync(id);
if (thisOrder == null)
{
return NotFound("未找到该订单");
}
后面还有 21 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。