From 7ca06fdfd901ed2daf82abc02fd2f157575ef188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=82=9C=E7=BF=94?= <2307953404@qq.com> Date: Mon, 28 Oct 2024 22:59:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=BC=96=E8=BE=91=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- asg_form/Controllers/AssignmentController.cs | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/asg_form/Controllers/AssignmentController.cs b/asg_form/Controllers/AssignmentController.cs index 3b615aa..0a8fbd7 100644 --- a/asg_form/Controllers/AssignmentController.cs +++ b/asg_form/Controllers/AssignmentController.cs @@ -325,5 +325,40 @@ namespace asg_form.Controllers } } + public class taskChange + { + public long taskId { get; set; } + public string taskName { get; set; } + public string taskDescription { get; set; } + public long money { get; set; } + } + [Route("api/v1/admin/UpdateTasks")] + [HttpPut] + [Authorize] + public async Task> UpdateTask([FromBody] taskChange msg) + { + try + { + if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "nbadmin")) + { + return Ok(new error_mb { code = 401, message = "无权访问" }); + } + if(msg == null) return Ok(new error_mb { code = 400, message = "信息不完整" }); + using (var db = new TestDbContext()) + { + var task = db.T_Task.Find(msg.taskId); + if (task == null) return Ok(new { code = 404, message = "任务未找到" }); + task.taskDescription = msg.taskDescription; + task.money = msg.money; + task.taskName = msg.taskName; + await db.SaveChangesAsync(); + return Ok(new { code = 200, message = "已修改" }); + } + } + catch (Exception ex) + { + return Ok(new { code = 500, message = "服务器错误", ex }); + } + } } }