Sic.Framework-Nanjing-Baishi/MECF.Framework.UI.Client/CenterViews/Configs/Roles/RoleItem.cs

224 lines
5.2 KiB
C#

using System.Collections.ObjectModel;
using System.Linq;
using Caliburn.Micro.Core;
using MECF.Framework.Common.Account.Extends;
namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
public class RoleItem : PropertyChangedBase
{
#region Constructors
public RoleItem(Role role)
{
Role = role;
}
public RoleItem(string roleId)
{
Role = new Role(roleId, string.Empty, false, 0, string.Empty, string.Empty);
}
#endregion
#region Properties
public Role Role { get; }
public string RoleId
{
get => Role.RoleId;
set => Role.RoleId = value;
}
public string RoleName
{
get => Role.RoleName;
set => Role.RoleName = value;
}
public int AutoLogoutTime
{
get => Role.LogoutTime;
set => Role.LogoutTime = value;
}
public string Description
{
get => Role.Description;
set => Role.Description = value;
}
public bool IsAutoLogout
{
get => Role.IsAutoLogout;
set => Role.IsAutoLogout = value;
}
private string _displayRoleName;
public string DisplayRoleName
{
get => _displayRoleName;
set
{
_displayRoleName = value;
NotifyOfPropertyChange();
}
}
public int DisplayAutoLogoutTime
{
get;
set;
}
public bool DisplayIsAutoLogout
{
get;
set;
}
public string DisplayDescription
{
get;
set;
}
private bool _isSelected;
public bool IsSelected
{
get => _isSelected;
set { _isSelected = value; NotifyOfPropertyChange(); }
}
private bool _roleNameTextSaved = true;
public bool RoleNameTextSaved
{
get => _roleNameTextSaved;
set
{
if (_roleNameTextSaved != value)
{
_roleNameTextSaved = value;
NotifyOfPropertyChange();
}
}
}
private bool _timeTextSaved = true;
public bool TimeTextSaved
{
get => _timeTextSaved;
set
{
if (_timeTextSaved != value)
{
_timeTextSaved = value;
NotifyOfPropertyChange();
}
}
}
private bool _descriptionTextSaved = true;
public bool DescriptionTextSaved
{
get => _descriptionTextSaved;
set
{
if (_descriptionTextSaved != value)
{
_descriptionTextSaved = value;
NotifyOfPropertyChange();
}
}
}
public ObservableCollection<MenuInfo> MenuCollection { get; } = new();
public ObservableCollection<RecipeInfo> RecipeCollection { get; } = new();
public ObservableCollection<StepInfo> RecipeStepCollection { get; } = new();
public ObservableCollection<ContentInfo> ContentCollection { get; } = new();
#endregion
#region Methods
public void AddMenuInfo(MenuInfo pInfo)
{
if (null == pInfo)
return;
MenuCollection.Add(pInfo);
}
public void AddRecipeInfo(RecipeInfo pInfo)
{
if (null == pInfo)
return;
RecipeCollection.Add(pInfo);
}
public void AddStepInfo(StepInfo pInfo)
{
if (null == pInfo)
return;
RecipeStepCollection.Add(pInfo);
}
public void AddContentInfo(ContentInfo pInfo)
{
if (null == pInfo)
return;
ContentCollection.Add(pInfo);
}
public bool IsRoleChanged()
{
if (DisplayRoleName != Role.RoleName)
return true;
if (DisplayAutoLogoutTime != Role.LogoutTime)
return true;
if (DisplayIsAutoLogout != Role.IsAutoLogout)
return true;
if (DisplayDescription != Role.Description)
return true;
if (MenuCollection.Any(item => item.DisplayIndexPermission != item.IndexPermission - 1))
{
return true;
}
if (RecipeCollection.Any(item => item.DisplayIndexPermission != item.IndexPermission - 1))
{
return true;
}
if (RecipeStepCollection.Any(item => item.DisplayIndexPermission != item.IndexPermission - 1))
{
return true;
}
if (ContentCollection.Any(item => item.DisplayIndexPermission != item.IndexPermission - 1))
{
return true;
}
return false;
}
#endregion
}
}