From ca580b86e851d8716c118db043e959a121bfd033 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, 11 Nov 2024 08:58:59 +0800 Subject: [PATCH] 1 --- asg_form/Controllers/config.cs | 1 - asg_form/Controllers/news.cs | 24 +++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/asg_form/Controllers/config.cs b/asg_form/Controllers/config.cs index ad497c8..3173ee7 100644 --- a/asg_form/Controllers/config.cs +++ b/asg_form/Controllers/config.cs @@ -104,7 +104,6 @@ using(TestDbContext db=new TestDbContext()){ [Route("api/v1/admin/config/all")] [HttpGet] - [Authorize] public async Task> config_get_all(string msg="null",short page=1, short limit = 10) { diff --git a/asg_form/Controllers/news.cs b/asg_form/Controllers/news.cs index 02d5309..648a64d 100644 --- a/asg_form/Controllers/news.cs +++ b/asg_form/Controllers/news.cs @@ -118,10 +118,17 @@ namespace asg_form.Controllers bool a = await userManager.IsInRoleAsync(user, "admin"); if (a) { + try + { TestDbContext ctx = new TestDbContext(); - await ctx.news.AddAsync(new T_news { Title = req_News.Title, msg = req_News.msg,Type=req_News.Type, FormName = user.UserName ,time=DateTime.Now}); - await ctx.SaveChangesAsync(); + ctx.news.Add(new T_news { Title = req_News.Title, msg = req_News.msg,Type=req_News.Type, FormName = user.UserName ,time=DateTime.Now.ToString()}); + ctx.SaveChanges(); return "ok!"; + } + catch (Exception ex) + { + return Ok(new { code = 500, message = "服务器错误", ex }); + } } else { @@ -150,6 +157,8 @@ namespace asg_form.Controllers { using (TestDbContext ctx = new TestDbContext()) { + try + { var qwq= await ctx.news.FindAsync(newsid); if (qwq == null) { @@ -159,8 +168,13 @@ namespace asg_form.Controllers qwq.Title=req_News.Title; qwq.FormName = user.UserName; qwq.Type = req_News.Type; - await ctx.SaveChangesAsync(); - + ctx.SaveChanges(); + } + catch (Exception ex) + { + return Ok(new { code = 500, message = "服务器错误", ex }); + } + } return "ok!"; @@ -184,7 +198,7 @@ public class T_news public long Id { get; set; } public string Title { get; set; } public string FormName { get; set; } - public DateTime? time { get; set; } + public string? time { get; set; } public string msg { get; set; } public string Type { get; set; }