1.0.0.428.1

Former-commit-id: 46f442338b22aea0cc8107d39344bf2636e0f3f8
TangShanKaiPing
wanggang 5 years ago
parent cc25a7b041
commit 407cfcb261

@ -2,15 +2,16 @@ using Omu.ValueInjecter;
using Omu.ValueInjecter.Injections; using Omu.ValueInjecter.Injections;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection; using System.Reflection;
namespace Infrastructure.Extensions namespace Infrastructure.Extensions
{ {
public static class ObjectMapperExtensions public static class ObjectMapperExtensions
{ {
public static T From<T>(this T target, object source, bool skipNull = false, List<string> skips = null) public static T From<T>(this T target, object source, bool skipNull = false, List<string> skips = null, bool skipReadonly = false)
{ {
var injection = new NullableInjection { SkipNull = skipNull }; var injection = new NullableInjection { SkipNull = skipNull, SkipReadonly = skipReadonly };
if (skips != null) if (skips != null)
{ {
injection.SkipProperties.AddRange(skips); injection.SkipProperties.AddRange(skips);
@ -44,6 +45,7 @@ namespace Infrastructure.Extensions
public bool SkipNull { get; set; } public bool SkipNull { get; set; }
public List<string> SkipProperties { get; } = new List<string>(); public List<string> SkipProperties { get; } = new List<string>();
public Func<PropertyInfo, bool> SkipFunc { get; set; } public Func<PropertyInfo, bool> SkipFunc { get; set; }
public bool SkipReadonly { get; set; }
protected override bool MatchTypes(Type sourceType, Type targetType) protected override bool MatchTypes(Type sourceType, Type targetType)
{ {
@ -83,6 +85,10 @@ namespace Infrastructure.Extensions
return; return;
} }
} }
if (this.SkipReadonly && sp.GetCustomAttribute<ReadOnlyAttribute>() != null)
{
return;
}
base.SetValue(source, target, sp, tp); base.SetValue(source, target, sp, tp);
} }
} }

@ -29,9 +29,14 @@
<div class="col-sm-8"> <div class="col-sm-8">
@if (metadata.Attributes.Attributes.Any(o => o.GetType() == typeof(System.ComponentModel.ReadOnlyAttribute))) @if (metadata.Attributes.Attributes.Any(o => o.GetType() == typeof(System.ComponentModel.ReadOnlyAttribute)))
{ {
<div class="form-control form-control-display"> <div class="form-control form-control-display">
@Html.Hidden(prop.PropertyName) @Html.Hidden(prop.PropertyName)
@Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint) @Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint)
@if (prop.ModelType == typeof(bool))
{
@Html.Label(prop.PropertyName, prop.DisplayName + "", new { @class = "form-check-label" })
}
</div> </div>
} }
else if (!string.IsNullOrEmpty(uihit) && !(uihit == "EmailAddress" || uihit == "PhoneNumber")) else if (!string.IsNullOrEmpty(uihit) && !(uihit == "EmailAddress" || uihit == "PhoneNumber"))
@ -60,7 +65,7 @@
<div class="form-group"> <div class="form-group">
<div class="form-check"> <div class="form-check">
@Html.CheckBox(prop.PropertyName, new { @class = "form-check-input" }) @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" })
</div> </div>
</div> </div>
} }

@ -87,10 +87,7 @@ namespace Infrastructure.Web.Mvc
entity.From(model); entity.From(model);
this.ToEntity(model, entity); this.ToEntity(model, entity);
this.Repo.Add(entity); this.Repo.Add(entity);
if (this.Repo.SaveChanges() > 0) this.Repo.SaveChanges();
{
this.OnInserted(entity);
}
return RedirectTo(); return RedirectTo();
} }
catch (DbUpdateException ex) catch (DbUpdateException ex)
@ -125,13 +122,9 @@ namespace Infrastructure.Web.Mvc
{ {
try try
{ {
this.OnEdit(entity, model); entity.From(model, skipReadonly: true);
entity.From(model);
this.ToEntity(model, entity); this.ToEntity(model, entity);
if (this.Repo.SaveChanges() > 0) this.Repo.SaveChanges();
{
this.OnUpdated(entity);
}
return RedirectTo(); return RedirectTo();
} }
catch (DbUpdateException ex) catch (DbUpdateException ex)
@ -208,10 +201,7 @@ namespace Infrastructure.Web.Mvc
var query = this.Repo.Table(); var query = this.Repo.Table();
var entity = query.FirstOrDefault(o => o.Id == id); var entity = query.FirstOrDefault(o => o.Id == id);
this.Repo.Delete(entity); this.Repo.Delete(entity);
if (this.Repo.SaveChanges() > 0) this.Repo.SaveChanges();
{
this.OnDeleted(entity);
}
} }
return RedirectTo(); 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)] [ApiExplorerSettings(IgnoreApi = true)]
public override void OnActionExecuting(ActionExecutingContext context) public override void OnActionExecuting(ActionExecutingContext context)
{ {

@ -1,4 +1,3 @@
using Infrastructure.Extensions;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
@ -16,7 +15,7 @@ namespace Infrastructure.Web.SignalR
protected void OnConnected() 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); this.Groups.AddToGroupAsync(Context.ConnectionId, Context.ConnectionId);
var group = Context.GetHttpContext().Request.Query["group"].ToString(); var group = Context.GetHttpContext().Request.Query["group"].ToString();
if (!string.IsNullOrEmpty(group)) if (!string.IsNullOrEmpty(group))
@ -40,7 +39,7 @@ namespace Infrastructure.Web.SignalR
protected void OnDisconnected(Exception exception) 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}");
} }
} }
} }

@ -56,6 +56,13 @@
.ke-container { .ke-container {
width: 100% !important; width: 100% !important;
} }
.form-control-display {
border: none;
padding-left: 0;
height: auto !important;
min-height: 34px;
}
/*.content-header2 { /*.content-header2 {
overflow: hidden; overflow: hidden;
} }
@ -65,12 +72,6 @@ select.form-control {
padding: 2px 20px 2px 16px !important; padding: 2px 20px 2px 16px !important;
} }
.form-control-display {
border: none;
padding-left: 0;
height: auto !important;
min-height: 34px;
}

@ -33,15 +33,6 @@ namespace Application.Models
[Display(Name = "海拔")] [Display(Name = "海拔")]
public decimal Altitude { get; set; } 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 = "序号")] [Display(Name = "序号")]
public int DisplayOrder { get; set; } public int DisplayOrder { get; set; }

@ -1,13 +1,15 @@
using Infrastructure.Application;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Infrastructure.Application;
namespace Application.Models namespace Application.Models
{ {
[Display(Name = "用户")] [Display(Name = "用户")]
public class EditUserModel : EditModel public class EditUserModel : EditModel
{ {
[ReadOnly(true)]
[Required(ErrorMessage = nameof(RequiredAttribute))] [Required(ErrorMessage = nameof(RequiredAttribute))]
[RegularExpression("^[a-zA-Z0-9]+$", ErrorMessage = "")] [RegularExpression("^[a-zA-Z0-9]+$", ErrorMessage = "")]
[StringLength(30, MinimumLength = 5, ErrorMessage = "用户名长度为5-30")] [StringLength(30, MinimumLength = 5, ErrorMessage = "用户名长度为5-30")]

@ -58,10 +58,5 @@ namespace IoTCenter.Areas.Admin.Controllers
} }
} }
} }
public override void OnEdit(User entity, EditUserModel model)
{
model.UserName = entity.UserName;
}
} }
} }

@ -14,7 +14,6 @@ namespace Application.Models
[RegularExpression("^[a-zA-Z0-9]+$", ErrorMessage = "")] [RegularExpression("^[a-zA-Z0-9]+$", ErrorMessage = "")]
[StringLength(30, MinimumLength = 5, ErrorMessage = "用户名长度为5-30")] [StringLength(30, MinimumLength = 5, ErrorMessage = "用户名长度为5-30")]
[Display(Name = "用户名")] [Display(Name = "用户名")]
[ReadOnly(true)]
public string UserName { get; set; } public string UserName { get; set; }
[StringLength(100, MinimumLength = 6, ErrorMessage = "密码长度范围为{2}-{1}")] [StringLength(100, MinimumLength = 6, ErrorMessage = "密码长度范围为{2}-{1}")]

@ -1,4 +1,3 @@
using System.Linq;
using Application.Domain.Entities; using Application.Domain.Entities;
using Application.Models; using Application.Models;
using Infrastructure.Application; using Infrastructure.Application;
@ -9,7 +8,8 @@ using Infrastructure.Web.Mvc;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using UserCenter.Services; using System;
using System.Linq;
namespace UserCenter.Areas.Admin.Controllers namespace UserCenter.Areas.Admin.Controllers
{ {
@ -19,15 +19,12 @@ namespace UserCenter.Areas.Admin.Controllers
{ {
private readonly IEncryptionService _encrypitonService; private readonly IEncryptionService _encrypitonService;
private readonly AjaxController _ajax; private readonly AjaxController _ajax;
//private readonly FaceRecognitionService _frs;
public UserController(IRepository<User> userRepo, IEncryptionService encrypitonService, AjaxController ajax public UserController(IRepository<User> userRepo, IEncryptionService encrypitonService, AjaxController ajax
//, FaceRecognitionService frs
) : base(userRepo) ) : base(userRepo)
{ {
this._encrypitonService = encrypitonService; this._encrypitonService = encrypitonService;
this._ajax = ajax; this._ajax = ajax;
//this._frs = frs;
} }
public override IQueryable<User> Include(IQueryable<User> query) public override IQueryable<User> Include(IQueryable<User> query)
@ -72,24 +69,23 @@ namespace UserCenter.Areas.Admin.Controllers
} }
} }
public override void OnEdit(User entity, EditUserModel model) public override IActionResult Add(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)
{ {
//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);
} }
} }
} }

@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyVersion("1.0.0.*")] [assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyInformationalVersion("1.0.0.428")] [assembly: AssemblyInformationalVersion("1.0.0.428.1")]
Loading…
Cancel
Save