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 System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
namespace Infrastructure.Extensions
{
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)
{
injection.SkipProperties.AddRange(skips);
@ -44,6 +45,7 @@ namespace Infrastructure.Extensions
public bool SkipNull { get; set; }
public List<string> SkipProperties { get; } = new List<string>();
public Func<PropertyInfo, bool> 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<ReadOnlyAttribute>() != null)
{
return;
}
base.SetValue(source, target, sp, tp);
}
}

@ -29,9 +29,14 @@
<div class="col-sm-8">
@if (metadata.Attributes.Attributes.Any(o => o.GetType() == typeof(System.ComponentModel.ReadOnlyAttribute)))
{
<div class="form-control form-control-display">
@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" })
}
</div>
}
else if (!string.IsNullOrEmpty(uihit) && !(uihit == "EmailAddress" || uihit == "PhoneNumber"))
@ -60,7 +65,7 @@
<div class="form-group">
<div class="form-check">
@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>
}

@ -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)
{

@ -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}");
}
}
}

@ -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;
}

@ -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; }

@ -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")]

@ -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 = "")]
[StringLength(30, MinimumLength = 5, ErrorMessage = "用户名长度为5-30")]
[Display(Name = "用户名")]
[ReadOnly(true)]
public string UserName { get; set; }
[StringLength(100, MinimumLength = 6, ErrorMessage = "密码长度范围为{2}-{1}")]

@ -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<User> userRepo, IEncryptionService encrypitonService, AjaxController ajax
//, FaceRecognitionService frs
) : base(userRepo)
{
this._encrypitonService = encrypitonService;
this._ajax = ajax;
//this._frs = frs;
}
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)
{
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);
}
}
}

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