From b8e4d3b0d3c3a0612f8c816f92f45f421f9509ca Mon Sep 17 00:00:00 2001 From: ji-sang <3136627705@qq.com> Date: Fri, 27 Dec 2024 17:16:43 +0800 Subject: [PATCH] 20241226 --- .../Controllers/CoursesController.cs" | 21 +++++-- .../Controllers/ScoresController.cs" | 50 +++++++++++---- .../Controllers/StudentsController.cs" | 61 +++++++++++++++++-- .../20241226024816_InitialCreate.Designer.cs" | 11 +++- .../20241226024816_InitialCreate.cs" | 9 ++- .../ScoreDbContextModelSnapshot.cs" | 9 +++ .../ScoreManager/Models/Courses.cs" | 1 + .../ScoreManager/Models/Scores.cs" | 1 + .../ScoreManager/Models/Students.cs" | 1 + .../ScoreManager/Views/Courses/Index.cshtml" | 2 +- .../ScoreManager/Views/Scores/Create.cshtml" | 4 +- .../ScoreManager/Views/Scores/Delete.cshtml" | 10 +-- .../ScoreManager/Views/Scores/Index.cshtml" | 10 +-- .../Views/Students/Delete.cshtml" | 3 +- .../ScoreManager/Views/Students/Edit.cshtml" | 1 + .../ScoreManager/Views/Students/Index.cshtml" | 2 +- .../20241120.md" | 2 +- .../20241223.md" | 39 ++++++++++++ .../20241225.md" | 1 + .../20241226.md" | 29 +++++++++ 20 files changed, 225 insertions(+), 42 deletions(-) rename "\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" => "\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" (89%) rename "\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" => "\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" (88%) create mode 100644 "\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241223.md" create mode 100644 "\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241225.md" create mode 100644 "\345\274\240\350\257\255\345\253\243/\350\257\276\345\240\202\347\254\224\350\256\260/20241226.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 8981391..30129c4 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 25dac42..d2cc9f6 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 4ba4ee3..fed9938 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 d7b6f32..4c0bc06 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 057a763..9b9d440 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 aa4797c..6114c00 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 15625b6..0a63438 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 c4f3ff5..2755a1b 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 78a1240..3adce59 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 7e008b9..49c1e61 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 fd90eaf..d0e436b 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 4ca0b17..0d152a7 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 0afc37b..0a3a066 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 ab30d94..2f47ad0 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 f9ea88b..3ff63b0 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 0ad25c3..ffcfec1 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 39bc39f..21f49b6 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 0000000..06a4b68 --- /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 0000000..a4be287 --- /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 0000000..941efd3 --- /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 -- Gitee
学号:@Model.StudentName
年龄:学生年龄: @Model.Age