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 898139148c63b3fbe7b870028f6d43c6b1113424..30129c44840db8dbdb57eb1d08d53e2ab9731d9c 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" @@ -10,13 +10,20 @@ public class CoursesController : Controller } public IActionResult Index(string keyword) { - keyword = string.IsNullOrEmpty(keyword) ? " ": keyword.Trim(); + // keyword = string.IsNullOrEmpty(keyword) ? " ": keyword.Trim(); + // if (string.IsNullOrEmpty(keyword)) + // { + // return View(_db.Courses.ToList()); + // } + // keyword = keyword.Trim(); + // var list = _db.Courses.Where(x=>x.CourseName.Contains(keyword)).ToList(); + // return View(list); + var res = _db.Courses.Where(x => !x.IsDeleted); if (string.IsNullOrEmpty(keyword)) { - return View(_db.Courses.ToList()); + return View(res); } - keyword = keyword.Trim(); - var list = _db.Courses.Where(x=>x.CourseName.Contains(keyword)).ToList(); + var list = res.Where(x => x.CourseName.Contains(keyword)).ToList(); return View(list); } public IActionResult Create() @@ -50,6 +57,9 @@ public class CoursesController : Controller public IActionResult Delete(int id) { var obj = _db.Courses.FirstOrDefault(x=>x.Id==id); + if(obj==null){ + return NotFound(); + } return View(obj); } public IActionResult DeleteConfirm(int id) @@ -58,7 +68,8 @@ public class CoursesController : Controller if(obj==null){ return NotFound(); } - _db.Courses.Remove(obj); + obj.IsDeleted=true; + _db.Courses.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/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 25dac42b026005712fc99214953a5f98bbdb2bf3..d2cc9f6a0d3f29244cb505e6eeddcb7e5caf6b2e 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" @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using ScoreManager.Models; +using Microsoft.AspNetCore.Mvc.Rendering; using System.Text.Json; namespace ScoreManager.Controllers; @@ -12,23 +13,41 @@ public class ScoresController : Controller } public IActionResult Index(string keyword) { - keyword = string.IsNullOrEmpty(keyword) ? " ": keyword.Trim(); - if (string.IsNullOrEmpty(keyword)) - { - return View(_db.Scores.ToList()); - } - keyword = keyword.Trim(); - var list = _db.Scores.Where( x => x.StudentId.ToString().Contains(keyword)).ToList(); - return View(list); + var list = _db.Scores.ToList(); + var stus = _db.Students.Where(x=>!x.IsDeleted).ToList(); + var cours = _db.Courses.Where(x=>!x.IsDeleted).ToList(); + var res = list.Select(x => { + var tmpStu = stus.FirstOrDefault(y=>y.Id==x.StudentId); + var tmpCourse = cours.FirstOrDefault(z=>z.Id==x.CourseId); + return new{ + x.Id, + x.StudentId, + StudentName = tmpStu == null ? "" : tmpStu.StudentName, + x.CourseId, + CourseName = tmpCourse == null ? "默认课程" : tmpCourse.CourseName, + x.Score + }; + }); + return View(res); + // keyword = string.IsNullOrEmpty(keyword) ? " ": keyword.Trim(); + // if (string.IsNullOrEmpty(keyword)) + // { + // return View(_db.Scores.ToList()); + // } + // keyword = keyword.Trim(); + // var list = _db.Scores.Where( x => x.StudentId.ToString().Contains(keyword)).ToList(); } public IActionResult Create() { + var students=_db.Students.ToList(); + var courses=_db.Courses.ToList(); + ViewBag.Students=new SelectList(students,"Id","StudentName"); + ViewBag.Courses=new SelectList(courses,"Id","CourseName"); return View(); } [HttpPost] public IActionResult Create(Scores input) { - // _db.StudentId.Add(input); _db.Scores.Add(input); _db.SaveChanges(); return RedirectToAction("Index"); @@ -56,7 +75,15 @@ public class ScoresController : Controller public IActionResult Delete(int id) { var obj = _db.Scores.FirstOrDefault(x=>x.Id==id); - return View(obj); + if(obj == null){ + return NotFound(); + } + var tmpCourse= _db.Courses.FirstOrDefault(x=>x.Id==obj.CourseId); + var tmpStudent= _db.Students.FirstOrDefault(x=>x.Id==obj.StudentId); + var cName = tmpCourse == null ? "":tmpCourse.CourseName; + var sName = tmpStudent == null ? "":tmpStudent.StudentName; + var tmp = new {obj.Id,obj.CourseId,CourseName=cName,obj.StudentId,StudentName=sName,obj.Score}; + return View(tmp); } public IActionResult DeleteConfirm(int id) { @@ -64,7 +91,8 @@ public class ScoresController : Controller if(obj==null){ return NotFound(); } - _db.Scores.Remove(obj); + obj.IsDeleted=true; + _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 4ba4ee3b6835eb630e6edd76d3b628d8011af6a8..fed9938d7837009503e409ee7325a9f1e4ded6d2 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" @@ -9,17 +9,58 @@ public class StudentsController : Controller public StudentsController(){ _db = new ScoreDbContext(); } + // public string Index(string keyword,string name, int pageindex){ + // return JsonSerializer.Serialize(new{keyword,name,pageindex}); + // } + // public IActionResult Index(string keyword) + // { + // IEnumerable list; + // keyword = string.IsNullOrEmpty(keyword) ? " ": keyword.Trim(); + // if (string.IsNullOrEmpty(keyword)) + // { + // return View(_db.Students.ToList()); + // } + // keyword = keyword.Trim(); + // var list = _db.Students.Where(x=>x.StudentName.Contains(keyword)).ToList(); + // return View(list); + // } public IActionResult Index(string keyword) { - keyword = string.IsNullOrEmpty(keyword) ? " ": keyword.Trim(); + // 2种情况 + // 有查找有关键字 + // 没有查找,也没有关键字(关键字为空的情况) + + // 第一种 + // IEnumerable list; + // if (string.IsNullOrEmpty(keyword)) + // { + // list = _db.Students; + // } + // else + // { + // list = _db.Students.Where(x => x.StudentCode.Contains(keyword) || x.StudentName.Contains(keyword)); + // } + // return View(list); + + // 第二种 + // if(string.IsNullOrEmpty(keyword)) + // { + // return View(_db.Students); + // }else{ + // var list=_db.Students.Where(x=>x.StudentCode.Contains(keyword) || x.StudentName.Contains(keyword)); + // return View(list); + // } + + // 第三种 + var res = _db.Students.Where(x => !x.IsDeleted); if (string.IsNullOrEmpty(keyword)) { - return View(_db.Students.ToList()); + return View(res); } - keyword = keyword.Trim(); - var list = _db.Students.Where(x=>x.StudentName.Contains(keyword)).ToList(); + var list = res.Where(x => x.StudentCode.Contains(keyword) || x.StudentName.Contains(keyword)); return View(list); } + [HttpGet] public IActionResult Create() { return View(); @@ -35,7 +76,10 @@ public class StudentsController : Controller public IActionResult Edit(int id) { var obj = _db.Students.FirstOrDefault(x=>x.Id==id); - return View(obj); + if( obj != null){ + return View(obj); + } + return NotFound(); } [HttpPost] public IActionResult Edit(Students input) @@ -47,12 +91,16 @@ public class StudentsController : Controller obj.StudentCode=input.StudentCode; obj.StudentName=input.StudentName; obj.Age=input.Age; + _db.Students.Update(obj); _db.SaveChanges(); return RedirectToAction("Index"); } public IActionResult Delete(int id) { var obj = _db.Students.FirstOrDefault(x=>x.Id==id); + if(obj==null){ + return NotFound(); + } return View(obj); } public IActionResult DeleteConfirm(int id) @@ -61,7 +109,8 @@ public class StudentsController : Controller if(obj==null){ return NotFound(); } - _db.Students.Remove(obj); + obj.IsDeleted=true; + _db.Students.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/Migrations/20241219031651_InitialCreate.Designer.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/Migrations/20241226024816_InitialCreate.Designer.cs" similarity index 89% rename from "\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/Migrations/20241219031651_InitialCreate.Designer.cs" rename to "\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/Migrations/20241226024816_InitialCreate.Designer.cs" index d7b6f320076d09295afb6c83e445a76687817c7e..4c0bc061226ccfd1a804587ec199c1f257935cd8 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/Migrations/20241219031651_InitialCreate.Designer.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/Migrations/20241226024816_InitialCreate.Designer.cs" @@ -11,7 +11,7 @@ using ScoreManager.Models; namespace ScoreManager.Migrations { [DbContext(typeof(ScoreDbContext))] - [Migration("20241219031651_InitialCreate")] + [Migration("20241226024816_InitialCreate")] partial class InitialCreate { /// @@ -36,6 +36,9 @@ namespace ScoreManager.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); + b.Property("IsDeleted") + .HasColumnType("bit"); + b.HasKey("Id"); b.ToTable("Courses"); @@ -52,6 +55,9 @@ namespace ScoreManager.Migrations b.Property("CourseId") .HasColumnType("int"); + b.Property("IsDeleted") + .HasColumnType("bit"); + b.Property("Score") .HasColumnType("decimal(18,2)"); @@ -74,6 +80,9 @@ namespace ScoreManager.Migrations b.Property("Age") .HasColumnType("int"); + b.Property("IsDeleted") + .HasColumnType("bit"); + b.Property("StudentCode") .IsRequired() .HasColumnType("nvarchar(max)"); 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/Migrations/20241219031651_InitialCreate.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/Migrations/20241226024816_InitialCreate.cs" similarity index 88% rename from "\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/Migrations/20241219031651_InitialCreate.cs" rename to "\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/Migrations/20241226024816_InitialCreate.cs" index 057a7639327213ae93cc86b75c1d4431c39780bb..9b9d44078e94eece608b252aec9d4ec0f5bdd943 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/Migrations/20241219031651_InitialCreate.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/Migrations/20241226024816_InitialCreate.cs" @@ -16,7 +16,8 @@ namespace ScoreManager.Migrations { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - CourseName = table.Column(type: "nvarchar(max)", nullable: false) + CourseName = table.Column(type: "nvarchar(max)", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false) }, constraints: table => { @@ -31,7 +32,8 @@ namespace ScoreManager.Migrations .Annotation("SqlServer:Identity", "1, 1"), StudentId = table.Column(type: "int", nullable: false), CourseId = table.Column(type: "int", nullable: false), - Score = table.Column(type: "decimal(18,2)", nullable: false) + Score = table.Column(type: "decimal(18,2)", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false) }, constraints: table => { @@ -46,7 +48,8 @@ namespace ScoreManager.Migrations .Annotation("SqlServer:Identity", "1, 1"), StudentCode = table.Column(type: "nvarchar(max)", nullable: false), StudentName = table.Column(type: "nvarchar(max)", nullable: false), - Age = table.Column(type: "int", nullable: false) + Age = table.Column(type: "int", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false) }, constraints: table => { 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/Migrations/ScoreDbContextModelSnapshot.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/Migrations/ScoreDbContextModelSnapshot.cs" index aa4797c2ed0325821c5fe9b3f401ae8430be965a..6114c0081b60ffcb1536b1be0eeeb8371abeab33 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/Migrations/ScoreDbContextModelSnapshot.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/Migrations/ScoreDbContextModelSnapshot.cs" @@ -33,6 +33,9 @@ namespace ScoreManager.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); + b.Property("IsDeleted") + .HasColumnType("bit"); + b.HasKey("Id"); b.ToTable("Courses"); @@ -49,6 +52,9 @@ namespace ScoreManager.Migrations b.Property("CourseId") .HasColumnType("int"); + b.Property("IsDeleted") + .HasColumnType("bit"); + b.Property("Score") .HasColumnType("decimal(18,2)"); @@ -71,6 +77,9 @@ namespace ScoreManager.Migrations b.Property("Age") .HasColumnType("int"); + b.Property("IsDeleted") + .HasColumnType("bit"); + b.Property("StudentCode") .IsRequired() .HasColumnType("nvarchar(max)"); 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/Models/Courses.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/Models/Courses.cs" index 15625b6643f82154cde768b6adf6bd624b3049d9..0a63438518e2c043b090f3b50f7b993645498aec 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/Models/Courses.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/Models/Courses.cs" @@ -4,4 +4,5 @@ public class Courses { public int Id { get; set; } public string CourseName { get; set; } = null!; + public bool IsDeleted {get;set;}=false; } 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/Models/Scores.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/Models/Scores.cs" index c4f3ff5532702fda51e9f2da58ca4d74992ba7b6..2755a1b3c4e9f31ccb93c7594a7cba7a0ed677b0 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/Models/Scores.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/Models/Scores.cs" @@ -6,4 +6,5 @@ public class Scores public int StudentId {get;set;} public int CourseId {get;set;} public decimal Score {get;set;} + public bool IsDeleted {get;set;}=false; } 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/Models/Students.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/Models/Students.cs" index 78a1240fdde1a26faa47caf2c387c2f225f01734..3adce59cbb74e33331109d24afe13c4f334c35a7 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/Models/Students.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/Models/Students.cs" @@ -6,4 +6,5 @@ public class Students public string StudentCode {get;set;}=null!; public string StudentName {get;set;}=null!; public int Age {get;set;} + public bool IsDeleted {get;set;}=false; } 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 7e008b9e5337be70f92c4a5639291a6d484f9319..49c1e61088707c44cdeb3022ac9e7fa43abc65e3 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" @@ -1,5 +1,5 @@ -@model List; +@* @model 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/Scores/Create.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/Scores/Create.cshtml" index fd90eaf42525a90343eb1249c89580d2f1da3faf..d0e436b454bde3223dd521473703b0166f70b37a 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/Scores/Create.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/Scores/Create.cshtml" @@ -1,7 +1,7 @@ @model ScoreManager.Models.Scores;
-
-
+
+

取消保存 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/Scores/Delete.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/Scores/Delete.cshtml" index 4ca0b1766910a6180298afc9f1efe7def14722af..0d152a7c09fb4aed23753cd01fb1e99efbdd0cfd 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/Scores/Delete.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/Scores/Delete.cshtml" @@ -1,12 +1,12 @@ -@model ScoreManager.Models.Scores; +

你确定要删除这个记录吗?

- - + + - - + + 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/Scores/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/Scores/Index.cshtml" index 0afc37bd7154fc83f8a995ddcb9f8a84bf2ee19a..0a3a066546300d6e5396526101aa649e335cd3d3 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/Scores/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/Scores/Index.cshtml" @@ -1,5 +1,5 @@ -@model List; +@* @model List; *@ 信息表 课程表
@@ -19,8 +19,8 @@
- - + + @@ -30,8 +30,8 @@ { - - + +
学号:@Model.StudentId学生姓名:@Model.StudentName
课程ID:@Model.CourseId课程名称:@Model.CourseName
成绩:
Id学号课程ID学生姓名课程名称 成绩 操作
@item.Id@item.StudentId@item.CourseId@item.StudentName@item.CourseName @item.Score 编辑 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/Students/Delete.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/Students/Delete.cshtml" index ab30d94032e0e3abd27cbc24dab3317c2b6d2f2e..2f47ad0600a9c042c4385c708fb5a65a2d3c8355 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/Students/Delete.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/Students/Delete.cshtml" @@ -1,4 +1,5 @@ @model ScoreManager.Models.Students; +

确认删除名为:@Model.StudentName 的学生吗?

@@ -9,7 +10,7 @@ - + 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/Students/Edit.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/Students/Edit.cshtml" index f9ea88b41296d1e315238360c66120cfe0a0e2cd..3ff63b04104193a85374e4bad4c95257f8748a84 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/Students/Edit.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/Students/Edit.cshtml" @@ -1,4 +1,5 @@ @model ScoreManager.Models.Students; +

编辑-学生-@Model.StudentName


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/Students/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/Students/Index.cshtml" index 0ad25c3405da53fadde52f1fbc997b7f4098436d..ffcfec100f282902c6f7a36f64266d9de997b96d 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/Students/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/Students/Index.cshtml" @@ -1,5 +1,5 @@ -@model List; +@* @model List; *@ 课程表 成绩表
diff --git "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241120.md" "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241120.md" index 39bc39fa113d2dae8876ce0903f693407b556f32..21f49b66f581895f12bd4ce738662c33557e15c0 100644 --- "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241120.md" +++ "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241120.md" @@ -13,7 +13,7 @@ Blog.sln(同级的解决方案,是与src同级) ## 主要流程 1. 新建一个文件夹Blog 2. 创建模板控制器 - - dotnet new mvc -o Blog.web + - dotnet new mvc -o Blog.Web 3. 创建类库 - dotnet new classlib -o Blog.Dao 4. 第二第三步最好按前面的路径存放,so改为: diff --git "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241223.md" "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241223.md" new file mode 100644 index 0000000000000000000000000000000000000000..06a4b6855c43e9e71d2037a52a7a678db73b8100 --- /dev/null +++ "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241223.md" @@ -0,0 +1,39 @@ +### 使用迁移创建数据库 +1. dotnet add package Microsoft.EntityFrameworkCore.SqlServer +2. dotnet tool install --global dotnet-ef +3. dotnet add package Microsoft.EntityFrameworkCore.Design +4. dotnet ef migrations add InitialCreate +5. dotnet ef database update + +### 了解IEnumerable +``` + (可迭代,可遍历) + ----->IEnumerable<----- + | | + | | + ICollection IQueryable + (集合) (linq,可查询) + | + | + IList + (集合) +``` +### 出现405错误 +1. 参数类型出错 +2. method对不上 + +### 或许更美观? +在View中的cshtml中加 +```cshtml +@model Student; +

编辑-学生-@Model.StudentName

+``` + +### 对我来说,暂时没用,但是先写上吧 +```cshtml +@model IEnumerable; +``` + +```cs +ViewBag["Title"]="ABc"; +``` \ No newline at end of file diff --git "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241225.md" "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241225.md" new file mode 100644 index 0000000000000000000000000000000000000000..a4be287a1c7bf693336f14a20ffd97071a042201 --- /dev/null +++ "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241225.md" @@ -0,0 +1 @@ +### 今天是有作业的好像,实现搜索功能————搜索后,输入的搜索文本保留 \ No newline at end of file diff --git "a/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241226.md" "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241226.md" new file mode 100644 index 0000000000000000000000000000000000000000..941efd3a6b8fa38c8ec63ef9798afc866ecc823d --- /dev/null +++ "b/\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241226.md" @@ -0,0 +1,29 @@ +### 成绩表linq查询 +```cs +public IActionResult Index(string keyword) + { + var list = _db.Scores.ToList(); + var stus = _db.Students.Where(x=>!x.IsDeleted).ToList(); + var cours = _db.Courses.Where(x=>!x.IsDeleted).ToList(); + var res = list.Select(x => { + var tmpStu = stus.FirstOrDefault(y=>y.Id==x.StudentId); + var tmpCourse = cours.FirstOrDefault(z=>z.Id==x.CourseId); + return new{ + x.Id, + x.StudentId, + StudentName = tmpStu == null ? "" : tmpStu.StudentName, + x.CourseId, + CourseName = tmpCourse == null ? "默认课程" : tmpCourse.CourseName, + x.Score + }; + }); + return View(res); + // keyword = string.IsNullOrEmpty(keyword) ? " ": keyword.Trim(); + // if (string.IsNullOrEmpty(keyword)) + // { + // return View(_db.Scores.ToList()); + // } + // keyword = keyword.Trim(); + // var list = _db.Scores.Where( x => x.StudentId.ToString().Contains(keyword)).ToList(); + } +``` \ No newline at end of file
学号:@Model.StudentName
年龄:学生年龄: @Model.Age