From 798668d94f6868f474d82fddebd4f996d297a589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=82=9C=E7=BF=94?= <2307953404@qq.com> Date: Thu, 24 Oct 2024 09:30:56 +0800 Subject: [PATCH] schedule --- asg_form/Controllers/schedule.cs | 43 ++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/asg_form/Controllers/schedule.cs b/asg_form/Controllers/schedule.cs index 20f2c87..019ca86 100644 --- a/asg_form/Controllers/schedule.cs +++ b/asg_form/Controllers/schedule.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore; using NPOI.OpenXmlFormats.Spreadsheet; using Castle.Components.DictionaryAdapter; using Flandre.Core.Messaging; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal; namespace asg_form.Controllers { @@ -25,7 +26,7 @@ namespace asg_form.Controllers [Authorize] [Route("api/v1/admin/game")] [HttpPut] - public async Task> gameput(long gameid,[FromBody] req_team_game req) + public async Task> gameput(long gameid,[FromBody] req_team_game req) { string id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value; @@ -85,7 +86,7 @@ namespace asg_form.Controllers [Authorize] [Route("api/v1/admin/game")] [HttpPost] - public async Task> gamepost([FromBody] req_team_game req) + public async Task> gamepost([FromBody] req_team_game req) { string id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value; @@ -117,10 +118,10 @@ namespace asg_form.Controllers }; wp = 1; - testDb.team_Games.Add(ins); - await testDb.SaveChangesAsync(); - return Ok(new { code = 200, message = "加入成功" }); + await testDb.team_Games.AddAsync(ins); + await testDb.SaveChangesAsync(); } + return Ok(new { code = 200, message = "加入成功" }); } catch (Exception ex) @@ -327,8 +328,29 @@ namespace asg_form.Controllers } - - + [Authorize] + [Route("api/v1/game/final")] + [HttpPost] + public async Task> finSc(long gameid,FinalScore msg) + { + using(var db = new TestDbContext()) + { + try + { + var query = db.team_Games.FirstOrDefault(n => n.id == gameid); + if (query == null) return Ok(new { code = 404, message = "未找到比赛" }); + query.final_score = msg.finalScore; + await db.SaveChangesAsync(); + return Ok(new { code = 200, message = "结果已存入" }); + } + catch (Exception ex) + { + var innerException = ex.InnerException ?? ex; // 如果没有 InnerException,使用 ex 本身 + // 记录错误信息 + return Ok(new { code = 500, message = "服务器错误", details = innerException.Message}); + } + } + } public class schedule_log @@ -370,6 +392,7 @@ namespace asg_form.Controllers public string? judge { get; set; } public int com_limit { get; set; } = 2; public string? person_type { get; set; } + public string? final_score { get; set; } } @@ -397,11 +420,15 @@ namespace asg_form.Controllers public string? personType { get; set; } } + public class FinalScore + { + public string finalScore { get; set; } + } } - } +}