убрали необходимость мапить поля с одинаковым именем

This commit is contained in:
kotcheshir73 2022-03-18 12:57:40 +04:00
parent 9b066d5c25
commit 6e2e10aa14
13 changed files with 28 additions and 72 deletions

View File

@ -1,5 +1,4 @@
using CoreModels.ModelsSecurity; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.Enums; using ModuleTools.Enums;
using ModuleTools.Interfaces; using ModuleTools.Interfaces;
using System; using System;
@ -13,17 +12,14 @@ namespace DatabaseCore.Models.Security
{ {
[DataMember] [DataMember]
[Required] [Required]
[MapConfiguration("RoleId")]
public Guid RoleId { get; set; } public Guid RoleId { get; set; }
[DataMember] [DataMember]
[Required] [Required]
[MapConfiguration("AccessOperation")]
public AccessOperation AccessOperation { get; set; } public AccessOperation AccessOperation { get; set; }
[DataMember] [DataMember]
[Required] [Required]
[MapConfiguration("AccessType")]
public AccessType AccessType { get; set; } public AccessType AccessType { get; set; }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------

View File

@ -1,26 +1,22 @@
using CoreModels.ModelsSecurity; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.Interfaces; using ModuleTools.Interfaces;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace DatabaseCore.Models.Security namespace DatabaseCore.Models.Security
{ {
[DataContract] [DataContract]
public class EnviromentSetting : BaseEntity, IEntitySecurityExtenstion<EnviromentSetting>, IEnviromentSettingModel public class EnviromentSetting : BaseEntity, IEntitySecurityExtenstion<EnviromentSetting>, IEnviromentSettingModel
{ {
[DataMember] [DataMember]
[Required] [Required]
[MapConfiguration("Key")]
public string Key { get; set; } public string Key { get; set; }
[DataMember] [DataMember]
[Required] [Required]
[MapConfiguration("Value")]
public string Value { get; set; } public string Value { get; set; }
[DataMember] [DataMember]
[MapConfiguration("Description")]
public string Description { get; set; } public string Description { get; set; }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------

View File

@ -1,5 +1,4 @@
using CoreModels.ModelsSecurity; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.Interfaces; using ModuleTools.Interfaces;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -8,16 +7,14 @@ using System.Runtime.Serialization;
namespace DatabaseCore.Models.Security namespace DatabaseCore.Models.Security
{ {
[DataContract] [DataContract]
public class Role : BaseEntity, IEntitySecurityExtenstion<Role>, IRoleModel public class Role : BaseEntity, IEntitySecurityExtenstion<Role>, IRoleModel
{ {
[DataMember] [DataMember]
[Required] [Required]
[MapConfiguration("RoleName")]
public string RoleName { get; set; } public string RoleName { get; set; }
[DataMember] [DataMember]
[MapConfiguration("RolePriority")]
public int RolePriority { get; set; } public int RolePriority { get; set; }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------

View File

@ -15,32 +15,25 @@ namespace DatabaseCore.Models.Security
{ {
[DataMember] [DataMember]
[Required] [Required]
[MapConfiguration("UserName")]
public string UserName { get; set; } public string UserName { get; set; }
[DataMember] [DataMember]
[Required] [Required]
[MapConfiguration("PasswordHash")]
public string PasswordHash { get; set; } public string PasswordHash { get; set; }
[DataMember] [DataMember]
[MapConfiguration("Avatar")]
public byte[] Avatar { get; set; } public byte[] Avatar { get; set; }
[DataMember] [DataMember]
[MapConfiguration("DateLastVisit")]
public DateTime? DateLastVisit { get; set; } public DateTime? DateLastVisit { get; set; }
[DataMember] [DataMember]
[MapConfiguration("IsBanned")]
public bool IsBanned { get; set; } public bool IsBanned { get; set; }
[DataMember] [DataMember]
[MapConfiguration("DateBanned")]
public DateTime? DateBanned { get; set; } public DateTime? DateBanned { get; set; }
[DataMember] [DataMember]
[MapConfiguration("CountAttempt")]
public int CountAttempt { get; set; } public int CountAttempt { get; set; }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------

View File

@ -1,20 +1,17 @@
using CoreModels.ModelsSecurity; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.Interfaces; using ModuleTools.Interfaces;
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace DatabaseCore.Models.Security namespace DatabaseCore.Models.Security
{ {
[DataContract] [DataContract]
public class UserRole : BaseEntity, IEntitySecurityExtenstion<UserRole>, IUserRoleModel public class UserRole : BaseEntity, IEntitySecurityExtenstion<UserRole>, IUserRoleModel
{ {
[DataMember] [DataMember]
[MapConfiguration("RoleId")]
public Guid RoleId { get; set; } public Guid RoleId { get; set; }
[DataMember] [DataMember]
[MapConfiguration("UserId")]
public Guid UserId { get; set; } public Guid UserId { get; set; }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------

View File

@ -56,10 +56,10 @@ namespace ModuleTools.BusinessLogics
var properties = typeTo.GetProperties(); var properties = typeTo.GetProperties();
foreach (var property in properties) foreach (var property in properties)
{ {
object value = obj;
var customAttribute = property.GetCustomAttribute<MapConfigurationAttribute>(); var customAttribute = property.GetCustomAttribute<MapConfigurationAttribute>();
if (customAttribute != null) if (customAttribute != null)
{ {
object value = obj;
if (customAttribute.IsDifficle) if (customAttribute.IsDifficle)
{ {
var props = customAttribute.PropertyNameFromModel.Split('.'); var props = customAttribute.PropertyNameFromModel.Split('.');
@ -136,10 +136,6 @@ namespace ModuleTools.BusinessLogics
value = bindingProperty.GetValue(obj); value = bindingProperty.GetValue(obj);
} }
} }
if (value is null)
{
continue;
}
if ((haveRigth && !customAttribute.AllowCopyWithoutRigth) || customAttribute.AllowCopyWithoutRigth) if ((haveRigth && !customAttribute.AllowCopyWithoutRigth) || customAttribute.AllowCopyWithoutRigth)
{ {
if (property.PropertyType.Name.StartsWith("Nullable")) if (property.PropertyType.Name.StartsWith("Nullable"))
@ -153,6 +149,14 @@ namespace ModuleTools.BusinessLogics
property.SetValue(newObject, value); property.SetValue(newObject, value);
} }
} }
else
{
var bindingProperty = value.GetType().GetProperty(property.Name);
if (bindingProperty != null)
{
property.SetValue(newObject, bindingProperty.GetValue(value));
}
}
} }
return newObject; return newObject;

View File

@ -1,5 +1,4 @@
using CoreModels.ModelsSecurity; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using ModuleTools.Enums; using ModuleTools.Enums;
using System; using System;
@ -23,14 +22,11 @@ namespace SecurityBusinessLogic.BindingModels
/// </summary> /// </summary>
public class AccessSetBindingModel : SetBindingModel, IAccessModel public class AccessSetBindingModel : SetBindingModel, IAccessModel
{ {
[MapConfiguration("RoleId")]
public Guid RoleId { get; set; } public Guid RoleId { get; set; }
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("AccessOperation")]
public AccessOperation AccessOperation { get; set; } public AccessOperation AccessOperation { get; set; }
[MapConfiguration("AccessType")]
public AccessType AccessType { get; set; } public AccessType AccessType { get; set; }
} }
} }

View File

@ -1,14 +1,13 @@
using CoreModels.ModelsSecurity; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace SecurityBusinessLogic.BindingModels namespace SecurityBusinessLogic.BindingModels
{ {
/// <summary> /// <summary>
/// Получение общих настроек системы /// Получение общих настроек системы
/// </summary> /// </summary>
public class EnviromentSettingGetBindingModel : GetBindingModel public class EnviromentSettingGetBindingModel : GetBindingModel
{ {
public string Key { get; set; } public string Key { get; set; }
} }
@ -19,15 +18,12 @@ namespace SecurityBusinessLogic.BindingModels
public class EnviromentSettingSetBindingModel : SetBindingModel, IEnviromentSettingModel public class EnviromentSettingSetBindingModel : SetBindingModel, IEnviromentSettingModel
{ {
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("Key")]
public string Key { get; set; } public string Key { get; set; }
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("Value")]
public string Value { get; set; } public string Value { get; set; }
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("Description")]
public string Description { get; set; } public string Description { get; set; }
} }
} }

View File

@ -1,5 +1,4 @@
using CoreModels.ModelsSecurity; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -16,11 +15,9 @@ namespace SecurityBusinessLogic.BindingModels
public class RoleSetBindingModel : SetBindingModel, IRoleModel public class RoleSetBindingModel : SetBindingModel, IRoleModel
{ {
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("RoleName")]
public string RoleName { get; set; } public string RoleName { get; set; }
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("RolePriority")]
public int RolePriority { get; set; } public int RolePriority { get; set; }
} }
} }

View File

@ -1,15 +1,14 @@
using CoreModels.ModelsSecurity; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace SecurityBusinessLogic.BindingModels namespace SecurityBusinessLogic.BindingModels
{ {
/// <summary> /// <summary>
/// Получение пользователя /// Получение пользователя
/// </summary> /// </summary>
public class UserGetBindingModel : GetBindingModel public class UserGetBindingModel : GetBindingModel
{ {
public string UserNameForSearch { get; set; } public string UserNameForSearch { get; set; }
@ -22,26 +21,19 @@ namespace SecurityBusinessLogic.BindingModels
public class UserSetBindingModel : SetBindingModel, IUserModel public class UserSetBindingModel : SetBindingModel, IUserModel
{ {
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("UserName")]
public string UserName { get; set; } public string UserName { get; set; }
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("Password")]
public string PasswordHash { get; set; } public string PasswordHash { get; set; }
[MapConfiguration("Avatar")]
public byte[] Avatar { get; set; } public byte[] Avatar { get; set; }
[MapConfiguration("DateLastVisit")]
public DateTime? DateLastVisit { get; set; } public DateTime? DateLastVisit { get; set; }
[MapConfiguration("IsBanned")]
public bool IsBanned { get; set; } public bool IsBanned { get; set; }
[MapConfiguration("DateBanned")]
public DateTime? DateBanned { get; set; } public DateTime? DateBanned { get; set; }
[MapConfiguration("CountAttempt")]
public int CountAttempt { get; set; } public int CountAttempt { get; set; }
} }
} }

View File

@ -1,15 +1,14 @@
using CoreModels.ModelsSecurity; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace SecurityBusinessLogic.BindingModels namespace SecurityBusinessLogic.BindingModels
{ {
/// <summary> /// <summary>
/// Получение связи пользователя с ролью /// Получение связи пользователя с ролью
/// </summary> /// </summary>
public class UserRoleGetBindingModel : GetBindingModel public class UserRoleGetBindingModel : GetBindingModel
{ {
public Guid? UserId { get; set; } public Guid? UserId { get; set; }
@ -22,11 +21,9 @@ namespace SecurityBusinessLogic.BindingModels
public class UserRoleSetBindingModel : SetBindingModel, IUserRoleModel public class UserRoleSetBindingModel : SetBindingModel, IUserRoleModel
{ {
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("UserId")]
public Guid UserId { get; set; } public Guid UserId { get; set; }
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("RoleId")]
public Guid RoleId { get; set; } public Guid RoleId { get; set; }
} }
} }

View File

@ -5,10 +5,10 @@ using ModuleTools.ViewModels;
namespace SecurityBusinessLogic.ViewModels namespace SecurityBusinessLogic.ViewModels
{ {
/// <summary> /// <summary>
/// Список ролей /// Список ролей
/// </summary> /// </summary>
public class RoleListViewModel : ListViewModel<RoleViewModel> { } public class RoleListViewModel : ListViewModel<RoleViewModel> { }
/// <summary> /// <summary>
/// Элемент ролей /// Элемент ролей
@ -22,12 +22,10 @@ namespace SecurityBusinessLogic.ViewModels
{ {
[ViewModelControlListProperty("Название роли")] [ViewModelControlListProperty("Название роли")]
[ViewModelControlElementProperty("Название роли", ControlType.ControlString, MustHaveValue = true)] [ViewModelControlElementProperty("Название роли", ControlType.ControlString, MustHaveValue = true)]
[MapConfiguration("RoleName")]
public string RoleName { get; set; } public string RoleName { get; set; }
[ViewModelControlListProperty("Приоритет", ColumnWidth = 100)] [ViewModelControlListProperty("Приоритет", ColumnWidth = 100)]
[ViewModelControlElementProperty("Приоритет", ControlType.ControlInt, MustHaveValue = true)] [ViewModelControlElementProperty("Приоритет", ControlType.ControlInt, MustHaveValue = true)]
[MapConfiguration("RolePriority")]
public int RolePriority { get; set; } public int RolePriority { get; set; }
} }
} }

View File

@ -21,18 +21,15 @@ namespace SecurityBusinessLogic.ViewModels
{ {
[ViewModelControlListProperty("Пользователь")] [ViewModelControlListProperty("Пользователь")]
[ViewModelControlElementProperty("Логин", ControlType.ControlString, MustHaveValue = true)] [ViewModelControlElementProperty("Логин", ControlType.ControlString, MustHaveValue = true)]
[MapConfiguration("UserName")]
public string UserName { get; set; } public string UserName { get; set; }
[MapConfiguration("PasswordHash", AllowCopyWithoutRigth = false)] [MapConfiguration("PasswordHash", AllowCopyWithoutRigth = false)]
public string PasswordHash { get; set; } public string PasswordHash { get; set; }
[ViewModelControlElementProperty("Фото", ControlType.ControlImage, Width = 200, Height = 200)] [ViewModelControlElementProperty("Фото", ControlType.ControlImage, Width = 200, Height = 200)]
[MapConfiguration("Avatar")]
public byte[] Avatar { get; set; } public byte[] Avatar { get; set; }
[ViewModelControlListProperty("Посл. визит", ColumnWidth = 100, DefaultCellStyleFormat = "dd.MM.yyyy")] [ViewModelControlListProperty("Посл. визит", ColumnWidth = 100, DefaultCellStyleFormat = "dd.MM.yyyy")]
[MapConfiguration("DateLastVisit")]
public DateTime? DateLastVisit { get; set; } public DateTime? DateLastVisit { get; set; }
[ViewModelControlElementProperty("Заблокирован", ControlType.ControlBool, MustHaveValue = true)] [ViewModelControlElementProperty("Заблокирован", ControlType.ControlBool, MustHaveValue = true)]