From 5a314ca997d8dc1b881afc4b7505649099075d1d Mon Sep 17 00:00:00 2001 From: Zhangyuyan <3136627705@qq.com> Date: Sun, 5 Jan 2025 15:02:12 +0800 Subject: [PATCH] 20241230 --- .../Controllers/CoursesController.cs" | 1 + .../Controllers/ScoresController.cs" | 24 +++++++++++++++---- .../Controllers/StudentsController.cs" | 1 + .../ScoreManager/Views/Courses/Index.cshtml" | 2 +- .../ScoreManager/Views/Scores/Edit.cshtml" | 6 ++--- .../ScoreManager/Views/Scores/Index.cshtml" | 2 +- .../ScoreManager/Views/Students/Index.cshtml" | 2 +- .../20241225.md" | 13 +++++++++- .../20241230.md" | 6 +++++ 9 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 "\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241230.md" diff --git "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/CoursesController.cs" "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/CoursesController.cs" index 30129c4..ecd4852 100644 --- "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/CoursesController.cs" +++ "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/CoursesController.cs" @@ -23,6 +23,7 @@ public class CoursesController : Controller { return View(res); } + ViewBag.keyword=keyword; var list = res.Where(x => x.CourseName.Contains(keyword)).ToList(); return View(list); } diff --git "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/ScoresController.cs" "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/ScoresController.cs" index d2cc9f6..c41a088 100644 --- "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/ScoresController.cs" +++ "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/ScoresController.cs" @@ -13,7 +13,7 @@ public class ScoresController : Controller } public IActionResult Index(string keyword) { - var list = _db.Scores.ToList(); + var list = _db.Scores.Where(x=>!x.IsDeleted).ToList(); var stus = _db.Students.Where(x=>!x.IsDeleted).ToList(); var cours = _db.Courses.Where(x=>!x.IsDeleted).ToList(); var res = list.Select(x => { @@ -24,11 +24,16 @@ public class ScoresController : Controller x.StudentId, StudentName = tmpStu == null ? "" : tmpStu.StudentName, x.CourseId, - CourseName = tmpCourse == null ? "默认课程" : tmpCourse.CourseName, + CourseName = tmpCourse == null ? "" : tmpCourse.CourseName, x.Score }; }); - return View(res); + if(string.IsNullOrEmpty(keyword)){ + return View(res); + } + ViewBag.keyword=keyword; + var tmpList = res.Where(x=>x.StudentName.Contains(keyword) || x.CourseName.Contains(keyword) || x.Score.ToString().Contains(keyword)); + return View(tmpList); // keyword = string.IsNullOrEmpty(keyword) ? " ": keyword.Trim(); // if (string.IsNullOrEmpty(keyword)) // { @@ -39,8 +44,8 @@ public class ScoresController : Controller } public IActionResult Create() { - var students=_db.Students.ToList(); - var courses=_db.Courses.ToList(); + var students=_db.Students.Where(x=>!x.IsDeleted).ToList(); + var courses=_db.Courses.Where(x=>!x.IsDeleted).ToList(); ViewBag.Students=new SelectList(students,"Id","StudentName"); ViewBag.Courses=new SelectList(courses,"Id","CourseName"); return View(); @@ -58,6 +63,13 @@ public class ScoresController : Controller public IActionResult Edit(int id) { var obj = _db.Scores.FirstOrDefault(x=>x.Id==id); + if(obj==null){ + return NotFound(); + } + var students=_db.Students.Where(x=>!x.IsDeleted).ToList(); + var courses=_db.Courses.Where(x=>!x.IsDeleted).ToList(); + ViewBag.Students=new SelectList(students,"Id","StudentName"); + ViewBag.Courses=new SelectList(courses,"Id","CourseName"); return View(obj); } [HttpPost] @@ -69,6 +81,8 @@ public class ScoresController : Controller } obj.Score=input.Score; obj.StudentId=input.StudentId; + obj.CourseId=input.CourseId; + _db.Scores.Update(obj); _db.SaveChanges(); return RedirectToAction("Index"); } diff --git "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/StudentsController.cs" "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/StudentsController.cs" index fed9938..da9792b 100644 --- "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/StudentsController.cs" +++ "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Controllers/StudentsController.cs" @@ -57,6 +57,7 @@ public class StudentsController : Controller { return View(res); } + ViewBag.keyword=keyword; var list = res.Where(x => x.StudentCode.Contains(keyword) || x.StudentName.Contains(keyword)); return View(list); } diff --git "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Views/Courses/Index.cshtml" "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Views/Courses/Index.cshtml" index 49c1e61..ea236fb 100644 --- "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Views/Courses/Index.cshtml" +++ "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\220\216\344\275\234\344\270\232/\346\225\264\346\225\264\344\270\211\344\270\252\350\241\250\345\221\242/ScoreManager/Views/Courses/Index.cshtml" @@ -6,7 +6,7 @@