102 lines
3.0 KiB
C#
102 lines
3.0 KiB
C#
///
|
|
/// Copyright (c) 2016 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
using Users.Entities;
|
|
using NHibernate;
|
|
using FluentNHibernate;
|
|
|
|
namespace Users
|
|
{
|
|
/// <summary>
|
|
/// Enum Grp.GID specifies GID-s of user groups.
|
|
/// An instance of this class represenst a group, which contains a list of its members (users).
|
|
/// Static private array 'groups' of this class, accesible through indexer, contains all groups.
|
|
/// </summary>
|
|
public class Grp
|
|
{
|
|
/// <summary>
|
|
/// GID-s of user groups, each user is member of one or more groups.
|
|
/// </summary>
|
|
public enum GID
|
|
{
|
|
// The first NrOfGroups items are GroupID-s (0..NrOfGroups-1)
|
|
Testers = 0,
|
|
TestingSpecialists,
|
|
HeadOfLab,
|
|
MaintenanceSpecialists,
|
|
Metrologists,
|
|
CalibrationSpecialists,
|
|
Administrators, // application / network / database administrator
|
|
Custom1,
|
|
Custom2,
|
|
Custom3,
|
|
NrOfGroups, // Number of groups (this is not a GroupID)
|
|
None, // Not a GroupID, can be used to indicate no group membership is required
|
|
Invalid = -1, // Not a GroupID, indicates a variable has not been properly set so far
|
|
}
|
|
|
|
/// <summary>
|
|
/// Number of groups.
|
|
/// </summary>
|
|
public const int Count = (int)GID.NrOfGroups;
|
|
|
|
// Static array of all groups.
|
|
static Grp[] groups;
|
|
|
|
/// <summary>
|
|
/// Static constructor, creates all groups with no members.
|
|
/// </summary>
|
|
static Grp()
|
|
{
|
|
groups = new Grp[Count];
|
|
for (int i = 0; i < Count; i++)
|
|
{
|
|
groups[i] = new Grp((GID)i);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a Group from Id.
|
|
/// </summary>
|
|
/// <param name="id">Group Gid</param>
|
|
/// <returns>Entities.Group object reference</returns>
|
|
public static Entities.Group FromId(GID gid)
|
|
{
|
|
int i = (int)gid;
|
|
|
|
if (i >= 0 && i < Count)
|
|
{
|
|
return groups[i].group;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
///////////////////// ^ static ^ ///////////////////// v instance v /////////////////////
|
|
|
|
/// Public properties
|
|
public GID Gid { get { return (GID)group.Gid; } }
|
|
public string Name { get { return group.Name; } set { group.Name = value; } }
|
|
|
|
/// Private fields
|
|
Entities.Group group;
|
|
|
|
/// <summary>
|
|
/// Instance constructor.
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
public Grp(GID gid)
|
|
{
|
|
group = new Entities.Group();
|
|
this.group.Gid = (int)gid;
|
|
this.group.Name = gid.ToString();
|
|
}
|
|
}
|
|
}
|