2024-08-03 20:40:34 +08:00
|
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
|
|
|
|
|
namespace asg_form.Controllers
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class booking : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly RoleManager<Role> roleManager;
|
|
|
|
|
private readonly UserManager<User> userManager;
|
|
|
|
|
public booking(
|
|
|
|
|
RoleManager<Role> roleManager, UserManager<User> userManager)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
this.roleManager = roleManager;
|
|
|
|
|
this.userManager = userManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Route("api/newbooking")]
|
|
|
|
|
[HttpPost]
|
2024-08-25 01:02:37 +08:00
|
|
|
|
|
2024-08-03 20:40:34 +08:00
|
|
|
|
public async Task<ActionResult<string>> newbooking()
|
|
|
|
|
{
|
|
|
|
|
string username = this.User.FindFirst(ClaimTypes.Name)!.Value;
|
|
|
|
|
User user = await userManager.FindByNameAsync(username);
|
|
|
|
|
if (user.isbooking==null)
|
|
|
|
|
{
|
|
|
|
|
user.isbooking = true;
|
|
|
|
|
await userManager.UpdateAsync(user);
|
|
|
|
|
return "OK";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return BadRequest(new error_mb { code = 400, message = "已经预约过了" }); ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|