diff --git a/labs/Teacher/Infrastructure/Extensions/ObjectMapperExtensions.cs b/labs/Teacher/Infrastructure/Extensions/ObjectMapperExtensions.cs index 1b01817e..2f50d3c3 100644 --- a/labs/Teacher/Infrastructure/Extensions/ObjectMapperExtensions.cs +++ b/labs/Teacher/Infrastructure/Extensions/ObjectMapperExtensions.cs @@ -38,6 +38,12 @@ namespace Infrastructure.Extensions }; return (T)target.InjectFrom(injection, source); } + + public static T FromWhere(this T target, object source, Func update) + { + var injection = new NullableInjection { update = update }; + return (T)target.InjectFrom(injection, source); + } } public class NullableInjection : LoopInjection @@ -47,6 +53,8 @@ namespace Infrastructure.Extensions public Func SkipFunc { get; set; } public bool SkipReadonly { get; set; } + public Func update { get; set; } + protected override bool MatchTypes(Type sourceType, Type targetType) { var snt = Nullable.GetUnderlyingType(sourceType); @@ -59,6 +67,13 @@ namespace Infrastructure.Extensions protected override void SetValue(object source, object target, PropertyInfo sp, PropertyInfo tp) { + if(this.update is not null) + { + if(!update.Invoke(sp,tp)) + { + return; + } + } if (sp is null) { throw new ArgumentNullException(nameof(sp)); diff --git a/labs/Teacher/TeacherExt/Controllers/HomeController.cs b/labs/Teacher/TeacherExt/Controllers/HomeController.cs index 5f01e2e3..ad4efafb 100644 --- a/labs/Teacher/TeacherExt/Controllers/HomeController.cs +++ b/labs/Teacher/TeacherExt/Controllers/HomeController.cs @@ -210,8 +210,9 @@ namespace TeacherExt.Controllers ToStatus = model.CheckStatus }); } - entity.From(model); - this.ModelToEntity(model, entity); + this.UpdateInternal(entity,model); + //entity.From(model); + //this.ModelToEntity(model, entity); this._personRepo.SaveChanges(); if (this.IsJsonRequest()) { @@ -223,6 +224,67 @@ namespace TeacherExt.Controllers model.LoginName = login.LoginName; return Result(model); } + + private void UpdateInternal(Person entity, EditTeacherModel model) + { + var self = this.HttpContext.Request.Query.ContainsKey("self") || (this.HttpContext.Request.Method == "POST" && this.HttpContext.Request.Form.ContainsKey("self")); + if(self) + { + if (entity.CheckStatus==model.CheckStatus) + { + if(model.CheckStatus== "未提交"||model.CheckStatus== "审核失败") + { + entity.From(model); + this.ModelToEntity(model, entity); + } + else + { + if(entity.RequestEditStatus!=model.RequestEditStatus) + { + entity.RequestEditStatus = model.RequestEditStatus; + } + } + } + else + { + if (entity.CheckStatus == "未提交" || entity.CheckStatus == "审核失败") + { + if (model.CheckStatus == "待审核") + { + entity.From(model); + this.ModelToEntity(model, entity); + } + } + } + } + else + { + if (User.IsInRole("城中区教育局管理员")) + { + if (model.CheckStatus == "未提交"&&model.RequestEditStatus== "未申请") + { + entity.CheckStatus = model.CheckStatus; + entity.RequestEditStatus = model.RequestEditStatus; + entity.Comment = model.Comment; + } + } + else if (User.IsInRole("学校管理员")) + { + if (model.CheckStatus == "审核成功" || model.CheckStatus == "审核失败") + { + entity.Comment = model.Comment; + entity.CheckStatus = model.CheckStatus; + entity.FromWhere(model,(s,t)=>s.Name.EndsWith("Checked")); + } + if (entity.RequestEditStatus!=model.RequestEditStatus) + { + entity.CheckStatus = model.CheckStatus; + entity.RequestEditStatus = model.RequestEditStatus; + } + } + } + } + private void ValidModelStatus(Person entity, EditTeacherModel model) { var self = this.HttpContext.Request.Query.ContainsKey("self") || (this.HttpContext.Request.Method == "POST" && this.HttpContext.Request.Form.ContainsKey("self")); @@ -271,11 +333,11 @@ namespace TeacherExt.Controllers ModelState.AddModelError(nameof(model.CheckStatus), $"无法从[{entity.CheckStatus}]状态修改为[{model.CheckStatus}]状态"); } } - if(model.RequestEditStatus== "未申请") + if(entity.RequestEditStatus != model.RequestEditStatus) { - if(entity.RequestEditStatus!="已申请") + if(entity.CheckStatus!="待审核"&& entity.CheckStatus != "审核成功") { - ModelState.AddModelError(nameof(model.RequestEditStatus), $"无法从[{entity.CheckStatus}]状态修改为[{model.RequestEditStatus}]状态"); + ModelState.AddModelError(nameof(model.RequestEditStatus), $"无法从[{entity.RequestEditStatus}]状态修改为[{model.RequestEditStatus}]状态"); } } } diff --git a/labs/Teacher/TeacherExt/TeacherExt.csproj b/labs/Teacher/TeacherExt/TeacherExt.csproj index 95795a06..f89d7828 100644 --- a/labs/Teacher/TeacherExt/TeacherExt.csproj +++ b/labs/Teacher/TeacherExt/TeacherExt.csproj @@ -5,7 +5,7 @@ true en true - 0.7.0.0 + 0.8.0.0 13a75881-1072-47ca-88e9-4d78bd678d65 diff --git a/labs/Teacher/TeacherExt/Views/Home/Update.cshtml b/labs/Teacher/TeacherExt/Views/Home/Update.cshtml index 938db6cb..e953dfa7 100644 --- a/labs/Teacher/TeacherExt/Views/Home/Update.cshtml +++ b/labs/Teacher/TeacherExt/Views/Home/Update.cshtml @@ -81,7 +81,7 @@ } @Html.ValidationMessage(prop.PropertyName, new { @class = "text-danger" }) -
+
@{ var checkedProp = props.FirstOrDefault(o => o.PropertyName == prop.PropertyName + "Checked"); @if (checkedProp != null) @@ -130,59 +130,54 @@
-
-
-
-
-
- @if (!iframe) +
+
+ @if (!iframe) + { + 返回 + } + @if (self) + { + @if (Model.CheckStatus == "未提交" || Model.CheckStatus == "审核失败") + { + + + } + else + { + if (Model.RequestEditStatus == "已申请") { - 返回 + } - @if (self) + else { - @if (Model.CheckStatus == "未提交" || Model.CheckStatus == "审核失败") - { - - - } - else - { - if (Model.RequestEditStatus == "已申请") - { - - } - else - { - - } - } + } - else + } + } + else + { + @if (User.IsInRole("城中区教育局管理员") && Model.CheckStatus == "审核成功") + { + 教育局管理员: + + } + else if (User.IsInRole("学校管理员")) + { + @if (Model.CheckStatus == "待审核") { - @if (User.IsInRole("城中区教育局管理员") && Model.CheckStatus == "审核成功") - { - 教育局管理员: - - } - else if (User.IsInRole("学校管理员")) - { - @if (Model.CheckStatus == "待审核") - { - 学校管理员: - - - } - @if (Model.RequestEditStatus == "已申请") - { - 学校管理员: - - - } - } + 学校管理员: + + } -
-
+ @if (Model.RequestEditStatus == "已申请") + { + 学校管理员: + + + } + } + }
diff --git a/labs/Teacher/TeacherExt/wwwroot/css/site.css b/labs/Teacher/TeacherExt/wwwroot/css/site.css index 64e6c214..b166b4ee 100644 --- a/labs/Teacher/TeacherExt/wwwroot/css/site.css +++ b/labs/Teacher/TeacherExt/wwwroot/css/site.css @@ -162,4 +162,7 @@ button.swal2-styled{ } .swal2-popup{ width:16em!important; +} +.swal2-title { + font-size: 14px !important; } \ No newline at end of file diff --git a/labs/Teacher/TeacherExt/wwwroot/js/update.js b/labs/Teacher/TeacherExt/wwwroot/js/update.js index 74584431..57609b63 100644 --- a/labs/Teacher/TeacherExt/wwwroot/js/update.js +++ b/labs/Teacher/TeacherExt/wwwroot/js/update.js @@ -42,7 +42,7 @@ $('#cancelModifyRequest').click(function () { }); }); //////////////////////////////////////////////////////////////////////////////// -//批准申请修改 +//退回 $('#super').click(function () { var form = $(this).parents('form'); var msg = '确认' + $(this).text() + '?'; @@ -55,6 +55,13 @@ $('#super').click(function () { //审核成功 $('#admin1').click(function () { var form = $(this).parents('form'); + if (form.find("input[name$='Checked']").filter(':visible').not(':checked').length > 0) { + Swal.fire({ + position: 'bottom', + text: '请审核全部待审核项', + confirmButtonText: '确定'}); + return; + } var msg = '确认' + $(this).text() + '?'; submit(msg, function () { $('#Comment').val(''); @@ -65,6 +72,14 @@ $('#admin1').click(function () { //审核失败 $('#admin2').click(function () { var form = $(this).parents('form'); + if (!$('#Comment').val()) { + Swal.fire({ + position: 'bottom', + text: '请填写审核失败原因', + confirmButtonText: '确定' + }); + return; + } var msg = '确认' + $(this).text() + '?'; submit(msg, function () { $('#CheckStatus').val('审核失败');