From 407cfcb26115a2233ce00ee9de669a14caaaba8d Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Tue, 28 Apr 2020 15:46:05 +0800 Subject: [PATCH] 1.0.0.428.1 Former-commit-id: 46f442338b22aea0cc8107d39344bf2636e0f3f8 --- .../Extensions/ObjectMapperExtensions.cs | 10 ++++- .../Views/Shared/EditorTemplates/Input.cshtml | 7 +++- .../Infrastructure/Web/Mvc/CrudController.cs | 38 ++----------------- .../Infrastructure/Web/SignalR/BasePageHub.cs | 5 +-- projects/Infrastructure/wwwroot/css/site.css | 13 ++++--- .../Application/Models/EditNodeModel.cs | 9 ----- .../Application/Models/Users/EditUserModel.cs | 4 +- .../Areas/Admin/Controllers/UserController.cs | 5 --- .../Application/Models/EditUserModel.cs | 1 - .../Areas/Admin/Controllers/UserController.cs | 34 ++++++++--------- projects/Version.cs | 2 +- 11 files changed, 46 insertions(+), 82 deletions(-) diff --git a/projects/Infrastructure/Extensions/ObjectMapperExtensions.cs b/projects/Infrastructure/Extensions/ObjectMapperExtensions.cs index 5331e15c..a0eb53de 100644 --- a/projects/Infrastructure/Extensions/ObjectMapperExtensions.cs +++ b/projects/Infrastructure/Extensions/ObjectMapperExtensions.cs @@ -2,15 +2,16 @@ using Omu.ValueInjecter; using Omu.ValueInjecter.Injections; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Reflection; namespace Infrastructure.Extensions { public static class ObjectMapperExtensions { - public static T From(this T target, object source, bool skipNull = false, List skips = null) + public static T From(this T target, object source, bool skipNull = false, List skips = null, bool skipReadonly = false) { - var injection = new NullableInjection { SkipNull = skipNull }; + var injection = new NullableInjection { SkipNull = skipNull, SkipReadonly = skipReadonly }; if (skips != null) { injection.SkipProperties.AddRange(skips); @@ -44,6 +45,7 @@ namespace Infrastructure.Extensions public bool SkipNull { get; set; } public List SkipProperties { get; } = new List(); public Func SkipFunc { get; set; } + public bool SkipReadonly { get; set; } protected override bool MatchTypes(Type sourceType, Type targetType) { @@ -83,6 +85,10 @@ namespace Infrastructure.Extensions return; } } + if (this.SkipReadonly && sp.GetCustomAttribute() != null) + { + return; + } base.SetValue(source, target, sp, tp); } } diff --git a/projects/Infrastructure/Views/Shared/EditorTemplates/Input.cshtml b/projects/Infrastructure/Views/Shared/EditorTemplates/Input.cshtml index 6590c66b..229e1580 100644 --- a/projects/Infrastructure/Views/Shared/EditorTemplates/Input.cshtml +++ b/projects/Infrastructure/Views/Shared/EditorTemplates/Input.cshtml @@ -29,9 +29,14 @@
@if (metadata.Attributes.Attributes.Any(o => o.GetType() == typeof(System.ComponentModel.ReadOnlyAttribute))) { +
@Html.Hidden(prop.PropertyName) @Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint) + @if (prop.ModelType == typeof(bool)) + { + @Html.Label(prop.PropertyName, prop.DisplayName + ":", new { @class = "form-check-label" }) + }
} else if (!string.IsNullOrEmpty(uihit) && !(uihit == "EmailAddress" || uihit == "PhoneNumber")) @@ -60,7 +65,7 @@
@Html.CheckBox(prop.PropertyName, new { @class = "form-check-input" }) - @Html.Label(prop.PropertyName, prop.GetDisplayName() + ":", new { @class = "form-check-label" }) + @Html.Label(prop.PropertyName, prop.DisplayName + ":", new { @class = "form-check-label" })
} diff --git a/projects/Infrastructure/Web/Mvc/CrudController.cs b/projects/Infrastructure/Web/Mvc/CrudController.cs index 45fab7f8..6273e486 100644 --- a/projects/Infrastructure/Web/Mvc/CrudController.cs +++ b/projects/Infrastructure/Web/Mvc/CrudController.cs @@ -87,10 +87,7 @@ namespace Infrastructure.Web.Mvc entity.From(model); this.ToEntity(model, entity); this.Repo.Add(entity); - if (this.Repo.SaveChanges() > 0) - { - this.OnInserted(entity); - } + this.Repo.SaveChanges(); return RedirectTo(); } catch (DbUpdateException ex) @@ -125,13 +122,9 @@ namespace Infrastructure.Web.Mvc { try { - this.OnEdit(entity, model); - entity.From(model); + entity.From(model, skipReadonly: true); this.ToEntity(model, entity); - if (this.Repo.SaveChanges() > 0) - { - this.OnUpdated(entity); - } + this.Repo.SaveChanges(); return RedirectTo(); } catch (DbUpdateException ex) @@ -208,10 +201,7 @@ namespace Infrastructure.Web.Mvc var query = this.Repo.Table(); var entity = query.FirstOrDefault(o => o.Id == id); this.Repo.Delete(entity); - if (this.Repo.SaveChanges() > 0) - { - this.OnDeleted(entity); - } + this.Repo.SaveChanges(); } return RedirectTo(); } @@ -249,26 +239,6 @@ namespace Infrastructure.Web.Mvc { } - [ApiExplorerSettings(IgnoreApi = true)] - public virtual void OnEdit(TEntity entity, TEditModel model) - { - } - - [ApiExplorerSettings(IgnoreApi = true)] - public virtual void OnInserted(TEntity entity) - { - } - - [ApiExplorerSettings(IgnoreApi = true)] - public virtual void OnUpdated(TEntity entity) - { - } - - [ApiExplorerSettings(IgnoreApi = true)] - public virtual void OnDeleted(TEntity entity) - { - } - [ApiExplorerSettings(IgnoreApi = true)] public override void OnActionExecuting(ActionExecutingContext context) { diff --git a/projects/Infrastructure/Web/SignalR/BasePageHub.cs b/projects/Infrastructure/Web/SignalR/BasePageHub.cs index b692e4b1..4c75f824 100644 --- a/projects/Infrastructure/Web/SignalR/BasePageHub.cs +++ b/projects/Infrastructure/Web/SignalR/BasePageHub.cs @@ -1,4 +1,3 @@ -using Infrastructure.Extensions; using Microsoft.AspNetCore.SignalR; using System; using System.Diagnostics; @@ -16,7 +15,7 @@ namespace Infrastructure.Web.SignalR protected void OnConnected() { - Debug.WriteLine($"{Context.ConnectionId} has connected which request url is {Context.GetHttpContext().Request.GetUrl()}"); + Debug.WriteLine($"{Context.ConnectionId} has connected: {Context.GetHttpContext().Request.QueryString}"); this.Groups.AddToGroupAsync(Context.ConnectionId, Context.ConnectionId); var group = Context.GetHttpContext().Request.Query["group"].ToString(); if (!string.IsNullOrEmpty(group)) @@ -40,7 +39,7 @@ namespace Infrastructure.Web.SignalR protected void OnDisconnected(Exception exception) { - Debug.WriteLine($"{Context.ConnectionId} has disconnected which request url is {Context.GetHttpContext().Request.GetUrl()}"); + Debug.WriteLine($"{Context.ConnectionId} has disconnected: {exception}"); } } } \ No newline at end of file diff --git a/projects/Infrastructure/wwwroot/css/site.css b/projects/Infrastructure/wwwroot/css/site.css index 1a1218ea..edb9ea94 100644 --- a/projects/Infrastructure/wwwroot/css/site.css +++ b/projects/Infrastructure/wwwroot/css/site.css @@ -56,6 +56,13 @@ .ke-container { width: 100% !important; } + +.form-control-display { + border: none; + padding-left: 0; + height: auto !important; + min-height: 34px; +} /*.content-header2 { overflow: hidden; } @@ -65,12 +72,6 @@ select.form-control { padding: 2px 20px 2px 16px !important; } -.form-control-display { - border: none; - padding-left: 0; - height: auto !important; - min-height: 34px; -} diff --git a/projects/IoT.Shared/Application/Models/EditNodeModel.cs b/projects/IoT.Shared/Application/Models/EditNodeModel.cs index c229dd0a..05c907c6 100644 --- a/projects/IoT.Shared/Application/Models/EditNodeModel.cs +++ b/projects/IoT.Shared/Application/Models/EditNodeModel.cs @@ -33,15 +33,6 @@ namespace Application.Models [Display(Name = "海拔")] public decimal Altitude { get; set; } - //[Display(Name = "类型")] - //public string Type { get; set; } - - //[Display(Name = "模板")] - //public string Template { get; set; } - - //[Display(Name = "移动模板")] - //public string MobileTemplate { get; set; } - [Display(Name = "序号")] public int DisplayOrder { get; set; } diff --git a/projects/StudyCenter/Application/Models/Users/EditUserModel.cs b/projects/StudyCenter/Application/Models/Users/EditUserModel.cs index 0bf852cc..4674a633 100644 --- a/projects/StudyCenter/Application/Models/Users/EditUserModel.cs +++ b/projects/StudyCenter/Application/Models/Users/EditUserModel.cs @@ -1,13 +1,15 @@ +using Infrastructure.Application; using System; using System.Collections.Generic; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; -using Infrastructure.Application; namespace Application.Models { [Display(Name = "用户")] public class EditUserModel : EditModel { + [ReadOnly(true)] [Required(ErrorMessage = nameof(RequiredAttribute))] [RegularExpression("^[a-zA-Z0-9]+$", ErrorMessage = "用户名只能由数字和字母组成")] [StringLength(30, MinimumLength = 5, ErrorMessage = "用户名长度为5-30")] diff --git a/projects/StudyCenter/Areas/Admin/Controllers/UserController.cs b/projects/StudyCenter/Areas/Admin/Controllers/UserController.cs index 3ea8c86a..aaebe98c 100644 --- a/projects/StudyCenter/Areas/Admin/Controllers/UserController.cs +++ b/projects/StudyCenter/Areas/Admin/Controllers/UserController.cs @@ -58,10 +58,5 @@ namespace IoTCenter.Areas.Admin.Controllers } } } - - public override void OnEdit(User entity, EditUserModel model) - { - model.UserName = entity.UserName; - } } } \ No newline at end of file diff --git a/projects/UserCenter/Application/Models/EditUserModel.cs b/projects/UserCenter/Application/Models/EditUserModel.cs index cafc6a7e..ea9c7af7 100644 --- a/projects/UserCenter/Application/Models/EditUserModel.cs +++ b/projects/UserCenter/Application/Models/EditUserModel.cs @@ -14,7 +14,6 @@ namespace Application.Models [RegularExpression("^[a-zA-Z0-9]+$", ErrorMessage = "用户名只能由数字和字母组成")] [StringLength(30, MinimumLength = 5, ErrorMessage = "用户名长度为5-30")] [Display(Name = "用户名")] - [ReadOnly(true)] public string UserName { get; set; } [StringLength(100, MinimumLength = 6, ErrorMessage = "密码长度范围为{2}-{1}")] diff --git a/projects/UserCenter/Areas/Admin/Controllers/UserController.cs b/projects/UserCenter/Areas/Admin/Controllers/UserController.cs index 6b7bf0e9..d0c27fa2 100644 --- a/projects/UserCenter/Areas/Admin/Controllers/UserController.cs +++ b/projects/UserCenter/Areas/Admin/Controllers/UserController.cs @@ -1,4 +1,3 @@ -using System.Linq; using Application.Domain.Entities; using Application.Models; using Infrastructure.Application; @@ -9,7 +8,8 @@ using Infrastructure.Web.Mvc; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using UserCenter.Services; +using System; +using System.Linq; namespace UserCenter.Areas.Admin.Controllers { @@ -19,15 +19,12 @@ namespace UserCenter.Areas.Admin.Controllers { private readonly IEncryptionService _encrypitonService; private readonly AjaxController _ajax; - //private readonly FaceRecognitionService _frs; public UserController(IRepository userRepo, IEncryptionService encrypitonService, AjaxController ajax - //, FaceRecognitionService frs ) : base(userRepo) { this._encrypitonService = encrypitonService; this._ajax = ajax; - //this._frs = frs; } public override IQueryable Include(IQueryable query) @@ -72,24 +69,23 @@ namespace UserCenter.Areas.Admin.Controllers } } - public override void OnEdit(User entity, EditUserModel model) - { - model.UserName = entity.UserName; - } - - public override void OnInserted(User entity) - { - //this._frs.AddFace(entity.UserName, entity.FaceImage); - } - - public override void OnUpdated(User entity) + public override IActionResult Add(EditUserModel model) { - //this._frs.UpdateFace(entity.UserName, entity.FaceImage); + if (string.IsNullOrEmpty(model.Password)) + { + ModelState.AddModelError("Password", "벻Ϊ"); + } + return base.Add(model); } - public override void OnDeleted(User entity) + public override IActionResult Edit(EditUserModel model) { - //this._frs.RemoveFace(entity.UserName); + var entity = this.Repo.Table().FirstOrDefault(o => o.Id == model.Id); + if (entity.UserName != model.UserName) + { + ModelState.AddModelError("UserName", "û޸"); + } + return base.Edit(model); } } } \ No newline at end of file diff --git a/projects/Version.cs b/projects/Version.cs index 23a6907c..9e0e5329 100644 --- a/projects/Version.cs +++ b/projects/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyVersion("1.0.0.*")] -[assembly: AssemblyInformationalVersion("1.0.0.428")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.428.1")] \ No newline at end of file