From f265374a4b3ae2452bb97f5f5cc8010d1a041c2f Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Mon, 4 Jan 2021 09:40:50 +0800 Subject: [PATCH] update Former-commit-id: c0fb45dae966f9fce616b8428e193b54879857bf Former-commit-id: 1b8b693498d2b423218db4ba3993371139fe1564 --- .../Shared/EditorTemplates/Object.cshtml | 2 +- .../Controllers/AccountController.cs | 10 +- .../TeacherExt/Controllers/HomeController.cs | 98 +- .../TeacherExt/Models/EditTeacherModel.cs | 14 +- .../TeacherExt/Views/Account/Login.cshtml | 46 +- .../TeacherExt/Views/Home/Index.cshtml | 41 +- labs/Teacher/TeacherExt/wwwroot/edit.html | 1992 +++++++++-------- labs/Teacher/TeacherExt/wwwroot/index.html | 234 ++ 8 files changed, 1413 insertions(+), 1024 deletions(-) create mode 100644 labs/Teacher/TeacherExt/wwwroot/index.html diff --git a/labs/Teacher/Infrastructure/Views/Shared/EditorTemplates/Object.cshtml b/labs/Teacher/Infrastructure/Views/Shared/EditorTemplates/Object.cshtml index 17aad0d8..7d46707f 100644 --- a/labs/Teacher/Infrastructure/Views/Shared/EditorTemplates/Object.cshtml +++ b/labs/Teacher/Infrastructure/Views/Shared/EditorTemplates/Object.cshtml @@ -7,7 +7,7 @@ var controller = this.ViewContext.RouteData.Values["controller"].ToString(); var action = this.ViewContext.RouteData.Values["action"].ToString(); var url = HtmlAction ?? (ViewData.Keys.Any(o => o.ToLower() == "returnurl") ? Url.Action(null, null, new { ReturnUrl = ViewData["ReturnUrl"] }) : Url.Action(null, null)); - var props = ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit); + var props = ViewData.ModelMetadata.Properties; }
diff --git a/labs/Teacher/TeacherExt/Controllers/AccountController.cs b/labs/Teacher/TeacherExt/Controllers/AccountController.cs index f11bc9e6..62fcb6a5 100644 --- a/labs/Teacher/TeacherExt/Controllers/AccountController.cs +++ b/labs/Teacher/TeacherExt/Controllers/AccountController.cs @@ -38,9 +38,15 @@ namespace TeacherExt.Controllers Request.HttpContext.JwtSignIn(model.UserName, model.RememberMe); return RedirectToAction("Index","Home"); } - ModelState.AddModelError(nameof(model.Password), "密码错误"); + else + { + ModelState.AddModelError(nameof(model.Password), "密码错误"); + } + } + else + { + ModelState.AddModelError(nameof(model.UserName), "用户不存在"); } - ModelState.AddModelError(nameof(model.UserName), "用户不存在"); } return View(); } diff --git a/labs/Teacher/TeacherExt/Controllers/HomeController.cs b/labs/Teacher/TeacherExt/Controllers/HomeController.cs index 11555c07..c7cdc206 100644 --- a/labs/Teacher/TeacherExt/Controllers/HomeController.cs +++ b/labs/Teacher/TeacherExt/Controllers/HomeController.cs @@ -3,6 +3,7 @@ using Infrastructure.Extensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using NPOI.SS.UserModel; @@ -45,8 +46,14 @@ namespace TeacherExt.Controllers .Take(model.PageSize) .ToList() .Select(o => { - var m = o.To(); - this.EntityToModel(o, m); + var m = o.Teacher != null?o.Teacher.To() : new EditTeacherModel(); + if(o.Teacher!=null) + { + this.EntityToModel(o.Teacher, m); + } + m.UserId = o.Id; + m.Organ = o.Organ.Name; + m.RealName = o.RealName; return m; }).ToList(); model.List.AddRange(list); @@ -70,11 +77,51 @@ namespace TeacherExt.Controllers return View(model); } - public IActionResult Edit(Guid id) + public IActionResult Edit(Guid userId) { - var entity = this._teacherRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == id); + var entity = this._userRepo.ReadOnlyTable() + .Include(o=>o.Organ) + .Include(o=>o.Teacher) + .FirstOrDefault(o => o.Id == userId); var model = entity.To(); - this.ToEditModel(entity, model); + model.UserId = entity.Id; + model.Organ = entity.Organ.Name; + model.RealName = entity.RealName; + this.EntityToModel(entity.Teacher, model); + this.ToEditModel(entity.Teacher, model); + return View(model); + } + + [HttpPost] + public IActionResult Add(EditTeacherModel model) + { + if(ModelState.IsValid) + { + var entity = new Teacher(); + entity.From(model); + this._teacherRepo.Add(entity); + this._teacherRepo.SaveChanges(); + return RedirectToAction("Index"); + } + this.ToEditModel(null, model); + return View(model); + } + + [HttpPost] + public IActionResult Edit(EditTeacherModel model) + { + var entity = this._userRepo.Table().FirstOrDefault(o => o.Id == model.UserId); + if (ModelState.IsValid) + { + if(entity.Teacher==null) + { + entity.Teacher = new Teacher().From(model); + } + this._userRepo.SaveChanges(); + return RedirectToAction("Index"); + } + this.EntityToModel(entity?.Teacher, model); + this.ToEditModel(entity?.Teacher, model); return View(model); } @@ -97,10 +144,9 @@ namespace TeacherExt.Controllers return File(ms.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"教师列表_{DateTime.Now.ToString("yyyy_MM-dd_HH_mm_ss")}.xlsx"); } - private IQueryable Query(QueryTeacherModel model) + private IQueryable Query(QueryTeacherModel model) { var userName = User.Identity.Name; - var query = this._teacherRepo.ReadOnlyTable(); var organId = this._userRepo.ReadOnlyTable().Where(o => o.UserName == userName).Select(o => o.OrganId).FirstOrDefault(); model.OrganId = model.OrganId.HasValue ? model.OrganId : organId; if (User.IsInRole("局管理员")) @@ -111,17 +157,18 @@ namespace TeacherExt.Controllers { model.Organs = this._organRepo.ReadOnlyTable().ToList().Where(o => o.Id == organId).ToList(); } + var query = this._userRepo.ReadOnlyTable().Include(o=>o.Organ).Include(o=>o.Teacher).AsQueryable(); if (User.IsInRole("校管理员")) { - query = query.Where(o => o.User.OrganId == organId); + query = query.Where(o => o.OrganId == organId); } else { - query = query.Where(o => o.User.UserName == userName); + query = query.Where(o => o.UserName == userName); } query = query - .WhereIf(!string.IsNullOrEmpty(model.RequestEditStatus), o => o.RequestEditStatus == model.RequestEditStatus) - .WhereIf(!string.IsNullOrEmpty(model.CheckStatus), o => o.CheckStatus == model.CheckStatus) + .WhereIf(!string.IsNullOrEmpty(model.RequestEditStatus), o => o.Teacher.RequestEditStatus == model.RequestEditStatus) + .WhereIf(!string.IsNullOrEmpty(model.CheckStatus), o => o.Teacher.CheckStatus == model.CheckStatus) .WhereIf(!string.IsNullOrEmpty(model.RealName), o => o.RealName.Contains(model.RealName)); return query; } @@ -136,8 +183,14 @@ namespace TeacherExt.Controllers var list = this.Query(model) .ToList() .Select(o => { - var m = o.To(); - this.EntityToModel(o, m); + var m = o.Teacher != null ? o.Teacher.To() : new EditTeacherModel(); + if (o.Teacher != null) + { + this.EntityToModel(o.Teacher, m); + } + m.UserId = o.Id; + m.Organ = o.Organ.Name; + m.RealName = o.RealName; return m; }) .ToList(); @@ -281,15 +334,18 @@ namespace TeacherExt.Controllers public void EntityToModel(Teacher entity, EditTeacherModel model) { - if (!string.IsNullOrEmpty(entity.IdNumber)) + if(entity!=null) { - var value = entity.IdNumber.Length == 15 ? $"19{entity.IdNumber.Substring(6, 6)}" : entity.IdNumber.Substring(6, 8); - var birthday = DateTime.ParseExact(value, "yyyyMMdd", CultureInfo.InvariantCulture); - model.Age = DateTime.Now.Year - birthday.Year; - } - if (entity.JobStart.HasValue) - { - model.JobAge = DateTime.Now.Year - entity.JobStart.Value.Year; + if (!string.IsNullOrEmpty(entity.IdNumber)) + { + var value = entity.IdNumber.Length == 15 ? $"19{entity.IdNumber.Substring(6, 6)}" : entity.IdNumber.Substring(6, 8); + var birthday = DateTime.ParseExact(value, "yyyyMMdd", CultureInfo.InvariantCulture); + model.Age = DateTime.Now.Year - birthday.Year; + } + if (entity.JobStart.HasValue) + { + model.JobAge = DateTime.Now.Year - entity.JobStart.Value.Year; + } } } diff --git a/labs/Teacher/TeacherExt/Models/EditTeacherModel.cs b/labs/Teacher/TeacherExt/Models/EditTeacherModel.cs index f91e1834..1cf413f5 100644 --- a/labs/Teacher/TeacherExt/Models/EditTeacherModel.cs +++ b/labs/Teacher/TeacherExt/Models/EditTeacherModel.cs @@ -15,13 +15,21 @@ namespace TeacherExt.Models [HiddenInput] [ReadOnly(true)] [ScaffoldColumn(false)] + [Display(Order = -3, Name = "申请修改状态")] + public Guid UserId { get; set; } + + [SkipSearch, SkipList] + [HiddenInput] + [ReadOnly(true)] + [ScaffoldColumn(false)] + [Display(Order = -2, Name = "申请修改状态")] public Guid Id { get; set; } = Guid.NewGuid(); [HiddenInput] [ReadOnly(true)] [Required(ErrorMessage = "必填项")] [Display(Order = -1, Name = "申请修改状态")] - public string RequestEditStatus { get; set; } + public string RequestEditStatus { get; set; } = "未申请"; [SelectList] [HiddenInput] @@ -44,9 +52,9 @@ namespace TeacherExt.Models public string UserType { get; set; } [Description("使用并修改已有字段[教师姓名]为[姓名]")] + [ReadOnly(true)] [Required(ErrorMessage = "必填项")] - [StringLength(4,MinimumLength =2,ErrorMessage ="{0}的长度在{2}-{1}之间")] - [RegularExpression(@"[\u4e00-\u9fa5]+", ErrorMessage = "姓名格式错误")] + [RegularExpression(@"^[\u4e00-\u9fa5]+$", ErrorMessage = "姓名格式错误")] [Display(Order = 30, Name = "姓名")] public string RealName { get; set; } diff --git a/labs/Teacher/TeacherExt/Views/Account/Login.cshtml b/labs/Teacher/TeacherExt/Views/Account/Login.cshtml index 048e2df8..f750b32d 100644 --- a/labs/Teacher/TeacherExt/Views/Account/Login.cshtml +++ b/labs/Teacher/TeacherExt/Views/Account/Login.cshtml @@ -1,2 +1,46 @@ @model LoginModel -@Html.EditorForModel() \ No newline at end of file + +
+
+ @Html.AntiForgeryToken() +
+
+
+ @Html.ValidationSummary(true, "错误:", new { @class = "text-danger col-sm-8" }, "div") +
+
+
+
+
+
+
+
+ @Html.TextBoxFor(o => o.UserName, new { @class= "form-control",placeholder = "用户名" }) + @Html.ValidationMessageFor(o => o.UserName) +
+
+
+
+
+ @Html.PasswordFor(o => o.Password, new { @class = "form-control", placeholder = "密码" }) + @Html.ValidationMessageFor(o => o.Password) +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ diff --git a/labs/Teacher/TeacherExt/Views/Home/Index.cshtml b/labs/Teacher/TeacherExt/Views/Home/Index.cshtml index 8a01ebc9..d12d1e78 100644 --- a/labs/Teacher/TeacherExt/Views/Home/Index.cshtml +++ b/labs/Teacher/TeacherExt/Views/Home/Index.cshtml @@ -13,7 +13,7 @@
-
+
@@ -45,7 +45,7 @@
- @if (User.IsInRole("局管理员") || User.IsInRole("校管理员")) @@ -53,17 +53,18 @@ 新建 - - + }
- +
+ @@ -71,13 +72,19 @@ - - + @if (User.IsInRole("局管理员") || User.IsInRole("校管理员")) + { + + } + @foreach (var item in Model.List) { index++; + @@ -85,8 +92,11 @@ - - + @if (User.IsInRole("局管理员") || User.IsInRole("校管理员")) + { + + } + }
行号 申请修改状态 审核状态性别 民族 籍贯查看修改审核编辑
+ + @index @item.RequestEditStatus @item.CheckStatus@item.Sex @item.Nation @item.NativePlace查看编辑审核编辑
@@ -128,13 +138,10 @@ @section scripts{ } \ No newline at end of file diff --git a/labs/Teacher/TeacherExt/wwwroot/edit.html b/labs/Teacher/TeacherExt/wwwroot/edit.html index cd5ad919..152f9ef8 100644 --- a/labs/Teacher/TeacherExt/wwwroot/edit.html +++ b/labs/Teacher/TeacherExt/wwwroot/edit.html @@ -21,970 +21,973 @@ - + - +
- +
- -
+ +
-
-
-
-

-
-
- -
-
+
- -
-
- -
-
-
- -
-
-
-
-
-
-
- -
-
- - 测试数据 + +
+
+ +
+
+
+ +
+
+
- -
-
- 是否使用已有字段:所属单位/学校 -
-
-
-
-
- -
- -
-
- (1)是否使用已有字段:教师状态(2)选型项不一致 -
-
-
-
-
- -
- -
-
- 使用并修改已有字段[教师姓名]为[姓名] -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 使用并修改已有字段[出生日期]为[出生年月] -
-
-
-
-
- -
- -
-
- 是否保留[其他]选择项?是否按照国标设置? -
-
-
-
-
- -
- -
-
- 以 省/自治区/直辖市 + 区/县 等形式填写 -
-
-
-
-
- -
- -
-
- 是否必填 -
-
-
-
-
- -
- -
-
- 是否必填 -
-
-
-
-
- -
- -
-
- 是否必填 -
-
-
-
-
- -
- -
-
- 是否必填 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 是否必填 -
-
-
-
-
- -
- -
-
- 是否必填 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 如:乡村教师职评、暂未岗位变更、新考/调入等 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 是否必填 -
-
-
-
-
- -
- -
-
- excel单元格提供的选项和批注提供的不一致 -
-
-
-
-
- -
- -
-
- 是否提示【以文件为准】 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 是否提示【以文件为准】 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 是否提示【填写毕业院校全称】 -
-
-
-
-
- -
- -
-
- 是否提示【严格按照毕业证书填写】 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 是否提示【填写毕业院校全称】 -
-
-
-
-
- -
- -
-
- 是否提示【严格按照毕业证书填写】 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 是否提示【选择项中没有则手动填写】 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 选择项中没有则手动填写 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 是否提示【选择项中没有则手动填写】 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 是否显示【填写所教学科全称】 -
-
-
-
-
- -
- -
-
- 是否显示【长期病假 产假 挂职 支教 其他(请写出具体原因)】 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
- 是否提示【严格按照资格证书填写】 -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
-
-
- -
-
-
-
-
-
-
- - 返回 - - +
+
+
+ +
+
+ + 测试数据 +
+ +
+
+ 是否使用已有字段:所属单位/学校 +
+
+
+
+
+ +
+ +
+
+ (1)是否使用已有字段:教师状态(2)选型项不一致 +
+
+
+
+
+ +
+ +
+
+ 使用并修改已有字段[教师姓名]为[姓名] +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 使用并修改已有字段[出生日期]为[出生年月] +
+
+
+
+
+ +
+ +
+
+ 是否保留[其他]选择项?是否按照国标设置? +
+
+
+
+
+ +
+ +
+
+ 以 省/自治区/直辖市 + 区/县 等形式填写 +
+
+
+
+
+ +
+ +
+
+ 是否必填 +
+
+
+
+
+ +
+ +
+
+ 是否必填 +
+
+
+
+
+ +
+ +
+
+ 是否必填 +
+
+
+
+
+ +
+ +
+
+ 是否必填 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 是否必填 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 如:乡村教师职评、暂未岗位变更、新考/调入等 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 是否必填 +
+
+
+
+
+ +
+ +
+
+ excel单元格提供的选项和批注提供的不一致 +
+
+
+
+
+ +
+ +
+
+ 是否提示【以文件为准】 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 是否提示【以文件为准】 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 是否提示【填写毕业院校全称】 +
+
+
+
+
+ +
+ +
+
+ 是否提示【严格按照毕业证书填写】 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 是否提示【填写毕业院校全称】 +
+
+
+
+
+ +
+ +
+
+ 是否提示【严格按照毕业证书填写】 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 是否提示【选择项中没有则手动填写】 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 选择项中没有则手动填写 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 是否提示【选择项中没有则手动填写】 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 是否显示【填写所教学科全称】 +
+
+
+
+
+ +
+ +
+
+ 是否显示【长期病假 产假 挂职 支教 其他(请写出具体原因)】 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ 是否提示【严格按照资格证书填写】 +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ + 返回 + + +
+
+
+
+
+ +
-
-
-
-
- -
-
- - - +