This commit is contained in:
王炜翔 2024-11-11 08:58:59 +08:00
parent e0d60f249e
commit ca580b86e8
2 changed files with 19 additions and 6 deletions

View File

@ -104,7 +104,6 @@ using(TestDbContext db=new TestDbContext()){
[Route("api/v1/admin/config/all")] [Route("api/v1/admin/config/all")]
[HttpGet] [HttpGet]
[Authorize]
public async Task<ActionResult<object>> config_get_all(string msg="null",short page=1, short limit = 10) public async Task<ActionResult<object>> config_get_all(string msg="null",short page=1, short limit = 10)
{ {

View File

@ -118,10 +118,17 @@ namespace asg_form.Controllers
bool a = await userManager.IsInRoleAsync(user, "admin"); bool a = await userManager.IsInRoleAsync(user, "admin");
if (a) if (a)
{ {
try
{
TestDbContext ctx = new TestDbContext(); 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}); 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()});
await ctx.SaveChangesAsync(); ctx.SaveChanges();
return "ok!"; return "ok!";
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
} }
else else
{ {
@ -150,6 +157,8 @@ namespace asg_form.Controllers
{ {
using (TestDbContext ctx = new TestDbContext()) using (TestDbContext ctx = new TestDbContext())
{ {
try
{
var qwq= await ctx.news.FindAsync(newsid); var qwq= await ctx.news.FindAsync(newsid);
if (qwq == null) if (qwq == null)
{ {
@ -159,8 +168,13 @@ namespace asg_form.Controllers
qwq.Title=req_News.Title; qwq.Title=req_News.Title;
qwq.FormName = user.UserName; qwq.FormName = user.UserName;
qwq.Type = req_News.Type; qwq.Type = req_News.Type;
await ctx.SaveChangesAsync(); ctx.SaveChanges();
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
} }
return "ok!"; return "ok!";
@ -184,7 +198,7 @@ public class T_news
public long Id { get; set; } public long Id { get; set; }
public string Title { get; set; } public string Title { get; set; }
public string FormName { get; set; } public string FormName { get; set; }
public DateTime? time { get; set; } public string? time { get; set; }
public string msg { get; set; } public string msg { get; set; }
public string Type { get; set; } public string Type { get; set; }