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

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 ModuleTools.Attributes;
using ModuleTools.Enums;
using ModuleTools.Interfaces;
using System;
@ -13,17 +12,14 @@ namespace DatabaseCore.Models.Security
{
[DataMember]
[Required]
[MapConfiguration("RoleId")]
public Guid RoleId { get; set; }
[DataMember]
[Required]
[MapConfiguration("AccessOperation")]
public AccessOperation AccessOperation { get; set; }
[DataMember]
[Required]
[MapConfiguration("AccessType")]
public AccessType AccessType { get; set; }
//-------------------------------------------------------------------------

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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