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 30129c44840db8dbdb57eb1d08d53e2ab9731d9c..ecd485204215d9b64149337e609604d76b05ea59 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 d2cc9f6a0d3f29244cb505e6eeddcb7e5caf6b2e..c41a088dc74f131f34c787f8a18f559f5417d2c6 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 fed9938d7837009503e409ee7325a9f1e4ded6d2..da9792b6e78d91819fb9310cdf209e6d04f19534 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 49c1e61088707c44cdeb3022ac9e7fa43abc65e3..ea236fba338e7bf4a34ae586d552b07fc17ff8b9 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 @@