Files
BeWoPlaner/BeWo/ViewModel/UserGroupVM.cs

219 lines
7.9 KiB
C#

using System.Collections.Generic;
using System.Linq;
using BeWo.Validation;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
namespace BeWo.ViewModel
{
public class UserGroupVM : AbstractDCMapperVM<UserGroupDC>
{
public static string PropertyName_Description = "Description";
public static string PropertyName_Name = "Name";
public static string PropertyName_PossibleRights = "PossibleRights";
public static string PropertyName_Rights = "Rights";
private string _Description;
private string _Name;
private ObservableSortCollection<UserRightType> _Rights;
public UserGroupVM(UserGroupDC pDataContract) : base(pDataContract, pDataContract.UserGroupOid == null) { }
public string Description
{
get { return _Description; }
set
{
if (AreDifferent(_Description, value))
{
_Description = value;
StoreDirtyInformation(AreDifferent(DataContract.Description, value), PropertyName_Description);
FirePropertyChanged(PropertyName_Description);
}
}
}
[Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
public string Name
{
get { return _Name; }
set
{
if (AreDifferent(_Name, value))
{
_Name = value;
StoreDirtyInformation(AreDifferent(DataContract.Name, value), PropertyName_Name);
FirePropertyChanged(PropertyName_Name);
}
}
}
public List<UserRightType> PossibleRights
{
get
{
List<UserRightType> possibleRights = new List<UserRightType>();
foreach (var r in Utils.GetAllEnumValues<UserRightType>().Except(this._Rights).ToList())
{
#if DEBUG
possibleRights.Add(r);
#else
if (r != UserRightType.AdditionalService_View || (MainSession.Mandator.BeWoClientType == 3) || MainSession.AppSettings.ShowAdditionalService)
{
if (!IsKalenderRight(r) || MainSession.AppSettings.IsSchedulerAllowed)
{
if (!IsWohnheimRight(r) || MainSession.AppSettings.IsWohnheimAllowed)
{
if (!IsSbdRight(r) || MainSession.Mandator.AllowSbd)
{
if (!IsResourceRight(r) || MainSession.AppSettings.ShowRessources)
{
if (!IsChatRight(r) || MainSession.AppSettings.IsChatAllowed)
{
if (!IsHiddenRight(r))
{
if (!IsMedicationRight(r) || MainSession.AppSettings.IsMedicationAllowed)
{
possibleRights.Add(r);
}
}
}
}
}
}
}
}
#endif
}
return possibleRights;
}
}
private static bool IsMedicationRight(UserRightType userRightType)
{
if (userRightType == UserRightType.Customer_ViewMedication)
return true;
return false;
}
private static bool IsChatRight(UserRightType userRightType)
{
if (userRightType == UserRightType.ChatSettings)
return true;
return false;
}
private static bool IsWohnheimRight(UserRightType userRightType)
{
if (userRightType == UserRightType.WohnheimView_Create
|| userRightType == UserRightType.WohnheimView_Delete
|| userRightType == UserRightType.WohnheimView_Edit
|| userRightType == UserRightType.WohnheimView_View
|| userRightType == UserRightType.Wohnheim_AllowArchiving)
return true;
return false;
}
private static bool IsHiddenRight(UserRightType userRightType)
{
if (userRightType == UserRightType.CustomerTeam_View
|| userRightType == UserRightType.CustomerTeam_Create
|| userRightType == UserRightType.CustomerTeam_Edit
|| userRightType == UserRightType.CustomerTeam_Delete)
return true;
return false;
}
private static bool IsSbdRight(UserRightType userRightType)
{
if (userRightType == UserRightType.VertretungenView_View)
return true;
return false;
}
private static bool IsResourceRight(UserRightType userRightType)
{
if (userRightType == UserRightType.
ResourceBookingView_AllowEditResourcesFromOtherEmployees
|| userRightType == UserRightType.ResourceBookingView_Create
|| userRightType == UserRightType.ResourceBookingView_View
|| userRightType == UserRightType.ResourceBookingView_Delete
|| userRightType == UserRightType.ResourceBookingView_Edit)
return true;
return false;
}
private static bool IsKalenderRight(UserRightType userRightType)
{
if (userRightType == UserRightType.KalenderAnsehen
|| userRightType == UserRightType.KalenderKliententermineAendern
|| userRightType == UserRightType.KalenderKliententermineAlleAnsehen
|| userRightType == UserRightType.KalenderKliententermineAnlegen
|| userRightType == UserRightType.KalenderMitarbeitertermineAendern
|| userRightType == UserRightType.KalenderMitarbeitertermineAnlegen
|| userRightType == UserRightType.KalenderMitarbeitertermineAnsehen
|| userRightType == UserRightType.KalenderRessourcentermineAendern
|| userRightType == UserRightType.KalenderRessourcentermineAndererAendern
|| userRightType == UserRightType.KalenderRessourcentermineAnlegen
|| userRightType == UserRightType.KalenderRessourcentermineAnsehen
|| userRightType == UserRightType.KalenderInZeiterfassungUebernehmen)
{
return true;
}
return false;
}
public ObservableSortCollection<UserRightType> Rights
{
get { return _Rights; }
set
{
if (AreDifferent(_Rights, value))
{
_Rights = value;
_Rights.CollectionChanged += (s, e) => RightsChanged();
RightsChanged();
}
}
}
protected override void InitByDataContract(UserGroupDC pDataContract)
{
_Name = pDataContract.Name;
_Description = pDataContract.Description;
Rights = pDataContract.Rights != null ? pDataContract.Rights.ToObservableSortCollection() : new ObservableSortCollection<UserRightType>();
}
protected override UserGroupDC MapToDataContract(UserGroupDC pDataContract, bool doCommit)
{
pDataContract.Rights = _Rights.ToList();
pDataContract.Name = _Name;
pDataContract.Description = _Description;
return pDataContract;
}
private void RightsChanged()
{
StoreDirtyInformation(!_Rights.ContainsSameItemsAs(DataContract.Rights), PropertyName_Rights);
FirePropertyChanged(PropertyName_Rights);
FirePropertyChanged(PropertyName_PossibleRights);
}
}
}