任务编辑功能
This commit is contained in:
parent
47af2cbfd0
commit
7ca06fdfd9
@ -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<ActionResult<object>> 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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user