50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
|
|
using FateMaster.API.Data;
|
||
|
|
using FateMaster.API.Models;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
|
||
|
|
namespace FateMaster.API.Controllers.Admin;
|
||
|
|
|
||
|
|
[ApiController]
|
||
|
|
[Route("api/admin/[controller]")]
|
||
|
|
public class PricesController : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly ApplicationDbContext _context;
|
||
|
|
|
||
|
|
public PricesController(ApplicationDbContext context)
|
||
|
|
{
|
||
|
|
_context = context;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 获取所有价格配置
|
||
|
|
/// </summary>
|
||
|
|
[HttpGet]
|
||
|
|
public async Task<ActionResult<List<PriceConfig>>> GetAll()
|
||
|
|
{
|
||
|
|
return await _context.PriceConfigs.ToListAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 更新价格配置
|
||
|
|
/// </summary>
|
||
|
|
[HttpPut("{id}")]
|
||
|
|
public async Task<ActionResult> Update(int id, [FromBody] UpdatePriceRequest request)
|
||
|
|
{
|
||
|
|
var price = await _context.PriceConfigs.FindAsync(id);
|
||
|
|
if (price == null)
|
||
|
|
{
|
||
|
|
return NotFound();
|
||
|
|
}
|
||
|
|
|
||
|
|
price.Price = request.Price;
|
||
|
|
price.IsEnabled = request.IsEnabled;
|
||
|
|
price.UpdatedAt = DateTime.UtcNow;
|
||
|
|
|
||
|
|
await _context.SaveChangesAsync();
|
||
|
|
return Ok(price);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public record UpdatePriceRequest(decimal Price, bool IsEnabled);
|