вводим проект с моделями

This commit is contained in:
kotcheshir73 2022-03-18 12:47:34 +04:00
parent c4402d976d
commit 9b066d5c25
36 changed files with 235 additions and 98 deletions

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ModuleTools\ModuleTools.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,27 @@
using CoreModels.Tools;
using ModuleTools.Attributes;
using ModuleTools.Enums;
using System;
namespace CoreModels.ModelsSecurity
{
[EntityDescription("Access", "Доступные действия для ролей")]
[EntityDependency("Role", "RoleId", "Доступные дейсвтиия создаются под конкретную роль")]
public interface IAccessModel : IId
{
/// <summary>
/// Илентификатор роли
/// </summary>
Guid RoleId { get; }
/// <summary>
/// Тип операции
/// </summary>
AccessOperation AccessOperation { get; }
/// <summary>
/// Режим доступа
/// </summary>
AccessType AccessType { get; }
}
}

View File

@ -0,0 +1,27 @@
using CoreModels.Tools;
using ModuleTools.Attributes;
namespace CoreModels.ModelsSecurity
{
/// <summary>
/// Модель, описывающиая общие настройки системы
/// </summary>
[EntityDescription("EnviromentSetting", "Общие настройки системы")]
public interface IEnviromentSettingModel : IId
{
/// <summary>
/// Ключ настройки
/// </summary>
string Key { get; }
/// <summary>
/// Значение настройки
/// </summary>
string Value { get; }
/// <summary>
/// Описание настройки
/// </summary>
string Description { get; }
}
}

View File

@ -0,0 +1,16 @@
using CoreModels.Tools;
using ModuleTools.Attributes;
namespace CoreModels.ModelsSecurity
{
/// <summary>
/// Модель, описывающиая роль в системе
/// </summary>
[EntityDescription("Role", "Роли в системе")]
public interface IRoleModel : IId
{
string RoleName { get; }
int RolePriority { get; }
}
}

View File

@ -0,0 +1,27 @@
using CoreModels.Tools;
using ModuleTools.Attributes;
using System;
namespace CoreModels.ModelsSecurity
{
/// <summary>
/// Модель, описывающиая пользователя системы
/// </summary>
[EntityDescription("User", "Пользователи системы")]
public interface IUserModel : IId
{
string UserName { get; }
string PasswordHash { get; }
byte[] Avatar { get; }
DateTime? DateLastVisit { get; }
bool IsBanned { get; }
DateTime? DateBanned { get; }
int CountAttempt { get; }
}
}

View File

@ -0,0 +1,19 @@
using CoreModels.Tools;
using ModuleTools.Attributes;
using System;
namespace CoreModels.ModelsSecurity
{
/// <summary>
/// Связка пользователь - роль
/// </summary>
[EntityDescription("UserRole", "Связь пользователей системы с ролями, которые им назначены")]
[EntityDependency("Role", "RoleId", "К какой роли относится пользователь")]
[EntityDependency("User", "UserId", "К какой роли относится пользователь")]
public interface IUserRoleModel : IId
{
Guid RoleId { get; }
Guid UserId { get; }
}
}

View File

@ -0,0 +1,9 @@
using System;
namespace CoreModels.Tools
{
public interface IId
{
Guid Id { get; }
}
}

View File

@ -14,6 +14,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CoreModels\CoreModels.csproj" />
<ProjectReference Include="..\ModuleTools\ModuleTools.csproj" /> <ProjectReference Include="..\ModuleTools\ModuleTools.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.Enums; using ModuleTools.Enums;
using ModuleTools.Interfaces; using ModuleTools.Interfaces;
using System; using System;
@ -7,13 +8,8 @@ using System.Runtime.Serialization;
namespace DatabaseCore.Models.Security namespace DatabaseCore.Models.Security
{ {
/// <summary> [DataContract]
/// Класс, описывающий возможные действия для роли public class Access : BaseEntity, IEntitySecurityExtenstion<Access>, IAccessModel
/// </summary>
[DataContract]
[EntityDescription("Access", "Доступные действия для ролей")]
[EntityDependency("Role", "RoleId", "Доступные дейсвтиия создаются под конкретную роль")]
public class Access : BaseEntity, IEntitySecurityExtenstion<Access>
{ {
[DataMember] [DataMember]
[Required] [Required]
@ -47,6 +43,6 @@ namespace DatabaseCore.Models.Security
return entity; return entity;
} }
public override string ToString() => $"{Role.RoleName}-{AccessOperation.ToString("G")}({AccessType.ToString("G")})"; public override string ToString() => $"{Role.RoleName}-{AccessOperation:G}({AccessType:G})";
} }
} }

View File

@ -1,16 +1,13 @@
using ModuleTools.Attributes; 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
{ {
/// <summary>
/// Класс, описывающий общие настройки системы
/// </summary>
[DataContract] [DataContract]
[EntityDescription("EnviromentSetting", "Общие настройки системы")] public class EnviromentSetting : BaseEntity, IEntitySecurityExtenstion<EnviromentSetting>, IEnviromentSettingModel
public class EnviromentSetting : BaseEntity, IEntitySecurityExtenstion<EnviromentSetting>
{ {
[DataMember] [DataMember]
[Required] [Required]

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; 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;
@ -7,12 +8,8 @@ using System.Runtime.Serialization;
namespace DatabaseCore.Models.Security namespace DatabaseCore.Models.Security
{ {
/// <summary>
/// Класс, описывающий роль в системе
/// </summary>
[DataContract] [DataContract]
[EntityDescription("Role", "Роли в системе")] public class Role : BaseEntity, IEntitySecurityExtenstion<Role>, IRoleModel
public class Role : BaseEntity, IEntitySecurityExtenstion<Role>
{ {
[DataMember] [DataMember]
[Required] [Required]

View File

@ -1,4 +1,5 @@
using DatabaseCore.Models.Department; using CoreModels.ModelsSecurity;
using DatabaseCore.Models.Department;
using ModuleTools.Attributes; using ModuleTools.Attributes;
using ModuleTools.Interfaces; using ModuleTools.Interfaces;
using System; using System;
@ -9,21 +10,17 @@ using System.Runtime.Serialization;
namespace DatabaseCore.Models.Security namespace DatabaseCore.Models.Security
{ {
/// <summary>
/// Класс, описывающий пользователя системы
/// </summary>
[DataContract] [DataContract]
[EntityDescription("User", "Пользователи системы")] public class User : BaseEntity, IEntitySecurityExtenstion<User>, IUserModel
public class User : BaseEntity, IEntitySecurityExtenstion<User>
{ {
[DataMember] [DataMember]
[Required] [Required]
[MapConfiguration("Login")] [MapConfiguration("UserName")]
public string UserName { get; set; } public string UserName { get; set; }
[DataMember] [DataMember]
[Required] [Required]
[MapConfiguration("Password")] [MapConfiguration("PasswordHash")]
public string PasswordHash { get; set; } public string PasswordHash { get; set; }
[DataMember] [DataMember]

View File

@ -1,18 +1,13 @@
using ModuleTools.Attributes; 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
{ {
/// <summary>
/// Связка пользователь - роль
/// </summary>
[DataContract] [DataContract]
[EntityDescription("UserRole", "Связь пользователей системы с ролями, которые им назначены")] public class UserRole : BaseEntity, IEntitySecurityExtenstion<UserRole>, IUserRoleModel
[EntityDependency("Role", "RoleId", "К какой роли относится пользователь")]
[EntityDependency("User", "UserId", "К какой роли относится пользователь")]
public class UserRole : BaseEntity, IEntitySecurityExtenstion<UserRole>
{ {
[DataMember] [DataMember]
[MapConfiguration("RoleId")] [MapConfiguration("RoleId")]

View File

@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace DatabaseCore namespace DatabaseCore
{ {
public class SecurityManager : ISecurityManager public class SecurityManager : ISecurityManager
{ {
private readonly int _countDayToBanned = 3; private readonly int _countDayToBanned = 3;

View File

@ -4,10 +4,10 @@ using System;
namespace DesktopTools.Interfaces namespace DesktopTools.Interfaces
{ {
/// <summary> /// <summary>
/// Основные параметры для контрола /// Основные параметры для контрола
/// </summary> /// </summary>
public interface IControl public interface IControl
{ {
/// <summary> /// <summary>
/// Идентификатор контрола /// Идентификатор контрола

View File

@ -6,7 +6,7 @@ using System.Windows.Forms;
namespace DesktopTools.Controls namespace DesktopTools.Controls
{ {
public partial class MainControlViewEntityElement : UserControl, IControl, IControlChildEntity public partial class MainControlViewEntityElement : UserControl, IControl, IControlChildEntity
{ {
/// <summary> /// <summary>
/// Методы для реализации в generic-контроле /// Методы для реализации в generic-контроле

View File

@ -6,7 +6,7 @@ using System.Windows.Forms;
namespace DesktopTools.Controls namespace DesktopTools.Controls
{ {
public partial class MainControlViewEntityList : UserControl, IControl, IControlChildEntity, IControlEntityList, IControlEntitySelectable public partial class MainControlViewEntityList : UserControl, IControl, IControlChildEntity, IControlEntityList, IControlEntitySelectable
{ {
/// <summary> /// <summary>
/// Методы для реализации в generic-контроле /// Методы для реализации в generic-контроле

View File

@ -6,7 +6,7 @@ namespace ModuleTools.Attributes
/// Оописание зависимости сущности от другой сущности (требуется для выстраивания последоватльности сохранения и загрузки данных, /// Оописание зависимости сущности от другой сущности (требуется для выстраивания последоватльности сохранения и загрузки данных,
/// применяется к классам-описывающим сущности в хранилище) /// применяется к классам-описывающим сущности в хранилище)
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
public class EntityDependencyAttribute : Attribute public class EntityDependencyAttribute : Attribute
{ {
/// <summary> /// <summary>

View File

@ -6,7 +6,7 @@ namespace ModuleTools.Attributes
/// Оописание класса из базы данных, его назначение (требуется для выстраивания иерархии с описанием классов, /// Оописание класса из базы данных, его назначение (требуется для выстраивания иерархии с описанием классов,
/// применяется к классам-описывающим сущности в хранилище) /// применяется к классам-описывающим сущности в хранилище)
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Class)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
public class EntityDescriptionAttribute : Attribute public class EntityDescriptionAttribute : Attribute
{ {
/// <summary> /// <summary>

View File

@ -68,8 +68,8 @@ namespace DepartmentWindowsDesktop.EntityControls
{ {
var newuser = logic.Create(new UserSetBindingModel var newuser = logic.Create(new UserSetBindingModel
{ {
Login = userName, UserName = userName,
Password = model.DateBirth.ToShortDateString(), PasswordHash = model.DateBirth.ToShortDateString(),
Avatar = model.Photo Avatar = model.Photo
}); });
if (newuser == null) if (newuser == null)
@ -107,7 +107,7 @@ namespace DepartmentWindowsDesktop.EntityControls
DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя"); DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя");
return; return;
} }
user.Password = model.DateBirth.ToShortDateString(); user.PasswordHash = model.DateBirth.ToShortDateString();
user = logic.Update(Mapper.MapToClass<UserViewModel, UserSetBindingModel>(user, true)); user = logic.Update(Mapper.MapToClass<UserViewModel, UserSetBindingModel>(user, true));
if (user == null) if (user == null)
{ {

View File

@ -68,8 +68,8 @@ namespace DepartmentWindowsDesktop.EntityControls
{ {
var newuser = logic.Create(new UserSetBindingModel var newuser = logic.Create(new UserSetBindingModel
{ {
Login = userName, UserName = userName,
Password = model.DateBirth.ToShortDateString(), PasswordHash = model.DateBirth.ToShortDateString(),
Avatar = model.Photo Avatar = model.Photo
}); });
if (newuser == null) if (newuser == null)
@ -107,7 +107,7 @@ namespace DepartmentWindowsDesktop.EntityControls
DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя"); DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя");
return; return;
} }
user.Password = model.DateBirth.ToShortDateString(); user.PasswordHash = model.DateBirth.ToShortDateString();
user = logic.Update(Mapper.MapToClass<UserViewModel, UserSetBindingModel>(user, true)); user = logic.Update(Mapper.MapToClass<UserViewModel, UserSetBindingModel>(user, true));
if (user == null) if (user == null)
{ {

View File

@ -62,8 +62,8 @@ namespace DepartmentWindowsDesktop.EntityControls
} }
user = logic.Create(new UserSetBindingModel user = logic.Create(new UserSetBindingModel
{ {
Login = model.NumberOfBook, UserName = model.NumberOfBook,
Password = userName, PasswordHash = userName,
Avatar = model.Photo Avatar = model.Photo
}); });
if (user == null) if (user == null)
@ -100,7 +100,7 @@ namespace DepartmentWindowsDesktop.EntityControls
DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя"); DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя");
return; return;
} }
user.Password = model.NumberOfBook; user.PasswordHash = model.NumberOfBook;
user = logic.Update(Mapper.MapToClass<UserViewModel, UserSetBindingModel>(user, true)); user = logic.Update(Mapper.MapToClass<UserViewModel, UserSetBindingModel>(user, true));
if (user == null) if (user == null)
{ {

View File

@ -23,11 +23,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModuleTools", "Common\Modul
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Department", "Department", "{A19E7709-6AD8-4E9B-B3AB-4339C67D9F39}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Department", "Department", "{A19E7709-6AD8-4E9B-B3AB-4339C67D9F39}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DepartmentBusinessLogic", "Department\DepartmentBusinessLogic\DepartmentBusinessLogic.csproj", "{69B94DB1-D1BE-4905-81AC-A5D49D0C9719}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DepartmentBusinessLogic", "Department\DepartmentBusinessLogic\DepartmentBusinessLogic.csproj", "{69B94DB1-D1BE-4905-81AC-A5D49D0C9719}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DepartmentDatabaseImplementation", "Department\DepartmentDatabaseImplementation.csproj\DepartmentDatabaseImplementation.csproj", "{1A9E20FE-6324-4839-A3AD-5726305122A5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DepartmentDatabaseImplementation", "Department\DepartmentDatabaseImplementation.csproj\DepartmentDatabaseImplementation.csproj", "{1A9E20FE-6324-4839-A3AD-5726305122A5}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DepartmentWindowsDesktop", "Department\DepartmentWindowsDesktop\DepartmentWindowsDesktop.csproj", "{8E12DE14-0D83-48D8-964D-8B2BB06DB129}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DepartmentWindowsDesktop", "Department\DepartmentWindowsDesktop\DepartmentWindowsDesktop.csproj", "{8E12DE14-0D83-48D8-964D-8B2BB06DB129}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreModels", "Common\CoreModels\CoreModels.csproj", "{FDF81413-ABAD-4890-A60F-4FEC62DD2A7D}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -75,6 +77,10 @@ Global
{8E12DE14-0D83-48D8-964D-8B2BB06DB129}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E12DE14-0D83-48D8-964D-8B2BB06DB129}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E12DE14-0D83-48D8-964D-8B2BB06DB129}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E12DE14-0D83-48D8-964D-8B2BB06DB129}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E12DE14-0D83-48D8-964D-8B2BB06DB129}.Release|Any CPU.Build.0 = Release|Any CPU {8E12DE14-0D83-48D8-964D-8B2BB06DB129}.Release|Any CPU.Build.0 = Release|Any CPU
{FDF81413-ABAD-4890-A60F-4FEC62DD2A7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDF81413-ABAD-4890-A60F-4FEC62DD2A7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDF81413-ABAD-4890-A60F-4FEC62DD2A7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDF81413-ABAD-4890-A60F-4FEC62DD2A7D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -89,6 +95,7 @@ Global
{69B94DB1-D1BE-4905-81AC-A5D49D0C9719} = {A19E7709-6AD8-4E9B-B3AB-4339C67D9F39} {69B94DB1-D1BE-4905-81AC-A5D49D0C9719} = {A19E7709-6AD8-4E9B-B3AB-4339C67D9F39}
{1A9E20FE-6324-4839-A3AD-5726305122A5} = {A19E7709-6AD8-4E9B-B3AB-4339C67D9F39} {1A9E20FE-6324-4839-A3AD-5726305122A5} = {A19E7709-6AD8-4E9B-B3AB-4339C67D9F39}
{8E12DE14-0D83-48D8-964D-8B2BB06DB129} = {A19E7709-6AD8-4E9B-B3AB-4339C67D9F39} {8E12DE14-0D83-48D8-964D-8B2BB06DB129} = {A19E7709-6AD8-4E9B-B3AB-4339C67D9F39}
{FDF81413-ABAD-4890-A60F-4FEC62DD2A7D} = {6F154F8D-3437-45EE-9D89-02B96BDF3E8E}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FBA0CB49-EF2D-4538-9D00-FCEDA24879A9} SolutionGuid = {FBA0CB49-EF2D-4538-9D00-FCEDA24879A9}

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using ModuleTools.Enums; using ModuleTools.Enums;
using System; using System;
@ -6,10 +7,10 @@ using System.ComponentModel.DataAnnotations;
namespace SecurityBusinessLogic.BindingModels namespace SecurityBusinessLogic.BindingModels
{ {
/// <summary> /// <summary>
/// Получение информации по доступу /// Получение информации по доступу
/// </summary> /// </summary>
public class AccessGetBindingModel : GetBindingModel public class AccessGetBindingModel : GetBindingModel
{ {
/// <summary> /// <summary>
/// Для вывода списка доступов по роли в контроле десктопном /// Для вывода списка доступов по роли в контроле десктопном
@ -20,7 +21,7 @@ namespace SecurityBusinessLogic.BindingModels
/// <summary> /// <summary>
/// Сохранение информации по доступу /// Сохранение информации по доступу
/// </summary> /// </summary>
public class AccessSetBindingModel : SetBindingModel public class AccessSetBindingModel : SetBindingModel, IAccessModel
{ {
[MapConfiguration("RoleId")] [MapConfiguration("RoleId")]
public Guid RoleId { get; set; } public Guid RoleId { get; set; }

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -15,7 +16,7 @@ namespace SecurityBusinessLogic.BindingModels
/// <summary> /// <summary>
/// Сохранение общих настроек системы /// Сохранение общих настроек системы
/// </summary> /// </summary>
public class EnviromentSettingSetBindingModel : SetBindingModel public class EnviromentSettingSetBindingModel : SetBindingModel, IEnviromentSettingModel
{ {
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("Key")] [MapConfiguration("Key")]

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -12,7 +13,7 @@ namespace SecurityBusinessLogic.BindingModels
/// <summary> /// <summary>
/// Сохранение роли /// Сохранение роли
/// </summary> /// </summary>
public class RoleSetBindingModel : SetBindingModel public class RoleSetBindingModel : SetBindingModel, IRoleModel
{ {
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("RoleName")] [MapConfiguration("RoleName")]

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -18,15 +19,15 @@ namespace SecurityBusinessLogic.BindingModels
/// <summary> /// <summary>
/// Сохранение пользователя /// Сохранение пользователя
/// </summary> /// </summary>
public class UserSetBindingModel : SetBindingModel public class UserSetBindingModel : SetBindingModel, IUserModel
{ {
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("Login")] [MapConfiguration("UserName")]
public string Login { get; set; } public string UserName { get; set; }
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("Password")] [MapConfiguration("Password")]
public string Password { get; set; } public string PasswordHash { get; set; }
[MapConfiguration("Avatar")] [MapConfiguration("Avatar")]
public byte[] Avatar { get; set; } public byte[] Avatar { get; set; }
@ -42,5 +43,5 @@ namespace SecurityBusinessLogic.BindingModels
[MapConfiguration("CountAttempt")] [MapConfiguration("CountAttempt")]
public int CountAttempt { get; set; } public int CountAttempt { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -18,7 +19,7 @@ namespace SecurityBusinessLogic.BindingModels
/// <summary> /// <summary>
/// Сохранение связи пользователя с ролью /// Сохранение связи пользователя с ролью
/// </summary> /// </summary>
public class UserRoleSetBindingModel : SetBindingModel public class UserRoleSetBindingModel : SetBindingModel, IUserRoleModel
{ {
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("UserId")] [MapConfiguration("UserId")]

View File

@ -39,8 +39,8 @@ namespace SecurityBusinessLogic.BusinessLogics
{ {
result = Service.Create(new UserSetBindingModel result = Service.Create(new UserSetBindingModel
{ {
Login = model.Login, UserName = model.Login,
Password = password PasswordHash = password
}); });
} }
if (!result.IsSucceeded) if (!result.IsSucceeded)

View File

@ -9,6 +9,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Common\CoreModels\CoreModels.csproj" />
<ProjectReference Include="..\..\Common\ModuleTools\ModuleTools.csproj" /> <ProjectReference Include="..\..\Common\ModuleTools\ModuleTools.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,20 +1,21 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.Enums; using ModuleTools.Enums;
using ModuleTools.ViewModels; using ModuleTools.ViewModels;
using System; using System;
namespace SecurityBusinessLogic.ViewModels namespace SecurityBusinessLogic.ViewModels
{ {
/// <summary> /// <summary>
/// Список достпуов /// Список достпуов
/// </summary> /// </summary>
public class AccessListViewModel : ListViewModel<AccessViewModel> { } public class AccessListViewModel : ListViewModel<AccessViewModel> { }
/// <summary> /// <summary>
/// Элемент доступа /// Элемент доступа
/// </summary> /// </summary>
[ViewModelControlElementClass()] [ViewModelControlElementClass()]
public class AccessViewModel : ElementViewModel public class AccessViewModel : ElementViewModel, IAccessModel
{ {
[ViewModelControlElementProperty("Роль", ControlType.ControlGuid, MustHaveValue = true, ReadOnly = true, ControlTypeObject = "SecurityWindowsDesktop.EntityControls.ControlRoleList, SecurityWindowsDesktop")] [ViewModelControlElementProperty("Роль", ControlType.ControlGuid, MustHaveValue = true, ReadOnly = true, ControlTypeObject = "SecurityWindowsDesktop.EntityControls.ControlRoleList, SecurityWindowsDesktop")]
[MapConfiguration("RoleId", AllowCopyWithoutRigth = false)] [MapConfiguration("RoleId", AllowCopyWithoutRigth = false)]

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.Enums; using ModuleTools.Enums;
using ModuleTools.ViewModels; using ModuleTools.ViewModels;
@ -13,7 +14,7 @@ namespace SecurityBusinessLogic.ViewModels
/// Элемент общих настроек системы /// Элемент общих настроек системы
/// </summary> /// </summary>
[ViewModelControlElementClass()] [ViewModelControlElementClass()]
public class EnviromentSettingViewModel : ElementViewModel public class EnviromentSettingViewModel : ElementViewModel, IEnviromentSettingModel
{ {
[ViewModelControlListProperty("Ключ")] [ViewModelControlListProperty("Ключ")]
[ViewModelControlElementProperty("Ключ", ControlType.ControlString, MustHaveValue = true, ReadOnly = true)] [ViewModelControlElementProperty("Ключ", ControlType.ControlString, MustHaveValue = true, ReadOnly = true)]

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.Enums; using ModuleTools.Enums;
using ModuleTools.ViewModels; using ModuleTools.ViewModels;
@ -17,7 +18,7 @@ namespace SecurityBusinessLogic.ViewModels
ControlTypeObject = "SecurityWindowsDesktop.EntityControls.ControlAccessList, SecurityWindowsDesktop")] ControlTypeObject = "SecurityWindowsDesktop.EntityControls.ControlAccessList, SecurityWindowsDesktop")]
[ViewModelControlElementDependenceEntity(Title = "Пользователи", Order = 2, ParentPropertyName = "RoleId", [ViewModelControlElementDependenceEntity(Title = "Пользователи", Order = 2, ParentPropertyName = "RoleId",
ControlTypeObject = "SecurityWindowsDesktop.EntityControls.ControlUserRoleList, SecurityWindowsDesktop")] ControlTypeObject = "SecurityWindowsDesktop.EntityControls.ControlUserRoleList, SecurityWindowsDesktop")]
public class RoleViewModel : ElementViewModel public class RoleViewModel : ElementViewModel, IRoleModel
{ {
[ViewModelControlListProperty("Название роли")] [ViewModelControlListProperty("Название роли")]
[ViewModelControlElementProperty("Название роли", ControlType.ControlString, MustHaveValue = true)] [ViewModelControlElementProperty("Название роли", ControlType.ControlString, MustHaveValue = true)]

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.Enums; using ModuleTools.Enums;
using ModuleTools.ViewModels; using ModuleTools.ViewModels;
using System; using System;
@ -14,7 +15,7 @@ namespace SecurityBusinessLogic.ViewModels
/// Элемент пользователей /// Элемент пользователей
/// </summary> /// </summary>
[ViewModelControlElementClass()] [ViewModelControlElementClass()]
public class UserRoleViewModel : ElementViewModel public class UserRoleViewModel : ElementViewModel, IUserRoleModel
{ {
[ViewModelControlElementProperty("Пользователь", ControlType.ControlGuid, MustHaveValue = true, ReadOnly = false, ControlTypeObject = "SecurityWindowsDesktop.EntityControls.ControlUserList, SecurityWindowsDesktop")] [ViewModelControlElementProperty("Пользователь", ControlType.ControlGuid, MustHaveValue = true, ReadOnly = false, ControlTypeObject = "SecurityWindowsDesktop.EntityControls.ControlUserList, SecurityWindowsDesktop")]
[MapConfiguration("UserId", AllowCopyWithoutRigth = false)] [MapConfiguration("UserId", AllowCopyWithoutRigth = false)]

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using CoreModels.ModelsSecurity;
using ModuleTools.Attributes;
using ModuleTools.Enums; using ModuleTools.Enums;
using ModuleTools.ViewModels; using ModuleTools.ViewModels;
using System; using System;
@ -16,15 +17,15 @@ namespace SecurityBusinessLogic.ViewModels
[ViewModelControlElementClass(HaveDependenceEntities = true, Width = 800, Height = 400)] [ViewModelControlElementClass(HaveDependenceEntities = true, Width = 800, Height = 400)]
[ViewModelControlElementDependenceEntity(Title = "Роли", Order = 1, ParentPropertyName = "UserId", [ViewModelControlElementDependenceEntity(Title = "Роли", Order = 1, ParentPropertyName = "UserId",
ControlTypeObject = "SecurityWindowsDesktop.EntityControls.ControlUserRoleList, SecurityWindowsDesktop")] ControlTypeObject = "SecurityWindowsDesktop.EntityControls.ControlUserRoleList, SecurityWindowsDesktop")]
public class UserViewModel : ElementViewModel public class UserViewModel : ElementViewModel, IUserModel
{ {
[ViewModelControlListProperty("Пользователь")] [ViewModelControlListProperty("Пользователь")]
[ViewModelControlElementProperty("Логин", ControlType.ControlString, MustHaveValue = true)] [ViewModelControlElementProperty("Логин", ControlType.ControlString, MustHaveValue = true)]
[MapConfiguration("UserName")] [MapConfiguration("UserName")]
public string Login { get; set; } public string UserName { get; set; }
[MapConfiguration("PasswordHash", AllowCopyWithoutRigth = false)] [MapConfiguration("PasswordHash", AllowCopyWithoutRigth = false)]
public string Password { get; set; } public string PasswordHash { get; set; }
[ViewModelControlElementProperty("Фото", ControlType.ControlImage, Width = 200, Height = 200)] [ViewModelControlElementProperty("Фото", ControlType.ControlImage, Width = 200, Height = 200)]
[MapConfiguration("Avatar")] [MapConfiguration("Avatar")]

View File

@ -22,11 +22,11 @@ namespace SecurityDatabaseImplementation.Implementations
{ {
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, UserSetBindingModel model) protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, UserSetBindingModel model)
{ {
if (model.Password.IsEmpty()) if (model.PasswordHash.IsEmpty())
{ {
model.Password = "qwerty"; model.PasswordHash = "qwerty";
} }
model.Password = SecurityManager.GetPasswordHash(model.Password); model.PasswordHash = SecurityManager.GetPasswordHash(model.PasswordHash);
return OperationResultModel.Success(null); return OperationResultModel.Success(null);
} }
@ -69,7 +69,7 @@ namespace SecurityDatabaseImplementation.Implementations
context.SaveChanges(); context.SaveChanges();
} }
protected override User GetUniqueEntity(UserSetBindingModel model, DbContext context) => context.Set<User>().FirstOrDefault(x => x.UserName == model.Login && x.Id != model.Id); protected override User GetUniqueEntity(UserSetBindingModel model, DbContext context) => context.Set<User>().FirstOrDefault((System.Linq.Expressions.Expression<Func<User, bool>>)(x => x.UserName == model.UserName && x.Id != model.Id));
protected override IQueryable<User> IncludingWhenReading(IQueryable<User> query) => query; protected override IQueryable<User> IncludingWhenReading(IQueryable<User> query) => query;