From 6fb8f536d73ba076e3d4ad6d0b33c816670621b6 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, 7 Oct 2024 11:05:03 +0800 Subject: [PATCH] 1234 --- .../Controllers/Budget/BgCountController.cs | 34 ++++++++++++++++--- asg_form/Controllers/config.cs | 22 +++++++----- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/asg_form/Controllers/Budget/BgCountController.cs b/asg_form/Controllers/Budget/BgCountController.cs index e7613d7..aef7871 100644 --- a/asg_form/Controllers/Budget/BgCountController.cs +++ b/asg_form/Controllers/Budget/BgCountController.cs @@ -79,12 +79,12 @@ namespace asg_form.Controllers.Budget budget_used = msg.budgetUsed, source_event_name = msg.sourceEventName, source_event_id = msg.sourceEventId, - change_time = dateString, + used_event_name = msg.usedEventName, used_event_id = msg.usedEventId, use_status = "0", update_person = msg.updatePerson, - update_time = null, + update_time = dateString, }; sub.budgetDetails.Add(budget); await sub.SaveChangesAsync(); @@ -123,7 +123,7 @@ namespace asg_form.Controllers.Budget budget.used_event_name = msg.usedEventName; budget.used_event_id = msg.usedEventId; budget.update_person = msg.updatePerson; - budget.update_time = currentTime.ToString(); + budget.change_time = currentTime.ToString(); await sub.SaveChangesAsync(); return Ok(new error_mb { code = 200, message = "更新预算成功" }); } @@ -178,7 +178,7 @@ namespace asg_form.Controllers.Budget budget.use_status = "1"; budget.use_person = request.UsePerson; budget.use_person_id = request.UsePersonId; - budget.update_time = DateTime.Now.ToString(); + budget.change_time = DateTime.Now.ToString(); await db.SaveChangesAsync(); return Ok(new { code = 200, message = "更新使用情况成功" }); } @@ -238,5 +238,31 @@ namespace asg_form.Controllers.Budget } } + [Route("api/v1/admin/DelBg")] + [HttpDelete] + [Authorize] + public async Task> DelBg([FromQuery] int id) + { + if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) + { + return Ok(new error_mb { code = 401, message = "无权访问" }); + } + try + { + using (TestDbContext sub = new TestDbContext()) + { + var f = sub.budgetDetails.FindAsync(id); + if (f == null ) return Ok(new error_mb { code = 404, message = "没有目标元素" }); + sub.budgetDetails.Remove(sub.budgetDetails.Find(id)); + await sub.SaveChangesAsync(); + return Ok(new error_mb { code = 200, message = "成功删除" }); + } + }catch (Exception ex) + { + return Ok(new { code = 500, message="服务器错误", error = ex.Message }); + } + + } + } } diff --git a/asg_form/Controllers/config.cs b/asg_form/Controllers/config.cs index 3dee4fc..f28e319 100644 --- a/asg_form/Controllers/config.cs +++ b/asg_form/Controllers/config.cs @@ -1,6 +1,8 @@ using System.Security.Claims; +using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; namespace asg_form.Controllers; @@ -103,7 +105,7 @@ using(TestDbContext db=new TestDbContext()){ [Route("api/v1/admin/config/all")] [HttpGet] [Authorize] - public async Task> config_get_all(short page, short page_long = 10) + public async Task> config_get_all(short page, short limit = 10) { if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) @@ -112,14 +114,18 @@ using(TestDbContext db=new TestDbContext()){ } using (TestDbContext db = new TestDbContext()) { - int a = db.T_config.Count(); - int b = page_long * page; - if (page_long * page > a) + var query = db.T_config.AsQueryable(); + var TotalRecords = await query.CountAsync(); + var config =await query + .Skip((page - 1) * limit) + .Take(limit) + .ToListAsync(); + var result = new { - b = a; - } - object config = db.T_config.Skip(page_long * page - page_long).Take(page_long).ToList(); - return Ok(config); + rows = config, + total = TotalRecords, + }; + return Ok(result); } }