//******************************************************************************************************
// SecurityGroup.cs - Gbtc
//
// Copyright © 2012, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
// not use this file except in compliance with the License. You may obtain a copy of the License at:
//
// http://www.opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 04/13/2011 - Aniket Salver
// Generated original version of source code.
// 05/02/2011 - J. Ritchie Carroll
// Updated for coding consistency.
// 05/03/2011 - Mehulbhai P Thakkar
// Guid field related changes as well as static functions update.
// 05/05/2011 - Mehulbhai P Thakkar
// Added NULL handling for Save() operation.
// 05/13/2011 - Aniket Salver
// Modified the way Guid is retrived from the Data Base.
// 12/20/2012 - Starlynn Danyelle Gilliam
// Modified Header.
//
//******************************************************************************************************
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using GSF.Data;
using GSF.Identity;
namespace GSF.TimeSeries.UI.DataModels
{
///
/// Represents a record of information as defined in the database.
///
public class SecurityGroup : DataModelBase
{
#region [ Members ]
// Fields
private Guid m_id;
private string m_name;
private string m_description;
private DateTime m_createdOn;
private string m_createdBy;
private DateTime m_updatedOn;
private string m_updatedBy;
private Dictionary m_currentUsers;
private Dictionary m_possibleUsers;
#endregion
#region [ Properties ]
///
/// Gets or sets the current SecurityGroup ID
///
// Field is populated by database via auto-increment and has no screen interaction, so no validation attributes are applied
public Guid ID
{
get
{
return m_id;
}
set
{
m_id = value;
OnPropertyChanged("ID");
}
}
///
/// Gets or sets the current SecurityGroup Name
///
[Required(ErrorMessage = " Security group name is a required field, please provide value.")]
[StringLength(200, ErrorMessage = "Security group name cannot exceed 200 characters.")]
[DefaultValue("Add New Group")]
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
OnPropertyChanged("Name");
}
}
///
/// Gets or sets the current SecurityGroup Description
///
// Because of database design no validation attributes are applied.
public string Description
{
get
{
return m_description;
}
set
{
m_description = value;
OnPropertyChanged("Description");
}
}
///
/// Gets or sets the current SecurityGroup CreatedOn
///
// Field is populated by database via trigger and has no screen interaction, so no validation attributes are applied
public DateTime CreatedOn
{
get
{
return m_createdOn;
}
set
{
m_createdOn = value;
OnPropertyChanged("CreatedOn");
}
}
///
/// Gets or sets the current SecurityGroup CreatedBy
///
// Field is populated by database via trigger and has no screen interaction, so no validation attributes are applied
public string CreatedBy
{
get
{
return m_createdBy;
}
set
{
m_createdBy = value;
}
}
///
/// Gets or sets the current SecurityGroup UpdatedOn
///
// Field is populated by database via trigger and has no screen interaction, so no validation attributes are applied
public DateTime UpdatedOn
{
get
{
return m_updatedOn;
}
set
{
m_updatedOn = value;
}
}
///
/// Gets or sets the current SecurityGroup UpdatedBy
///
// Field is populated by database via trigger and has no screen interaction, so no validation attributes are applied
public string UpdatedBy
{
get
{
return m_updatedBy;
}
set
{
m_updatedBy = value;
}
}
///
/// Gets or sets the current 's CurrentGroupUsers.
///
// Field is populated by database via trigger and has no screen interaction, so no validation attributes are applied
public Dictionary CurrentUsers
{
get
{
return m_currentUsers;
}
set
{
m_currentUsers = value;
OnPropertyChanged("CurrentUsers");
}
}
///
/// Gets or sets the current 's PossibleGroupUsers.
///
// Field is populated by database via trigger and has no screen interaction, so no validation attributes are applied
public Dictionary PossibleUsers
{
get
{
return m_possibleUsers;
}
set
{
m_possibleUsers = value;
OnPropertyChanged("PossibleUsers");
}
}
#endregion
#region [ Static ]
// Static Methods
///
/// Loads information as an style list.
///
/// to connection to database.
/// Collection of .
public static ObservableCollection Load(AdoDataConnection database)
{
bool createdConnection = false;
try
{
createdConnection = CreateConnection(ref database);
ObservableCollection securityGroupList = new ObservableCollection();
DataTable securityGroupTable = database.Connection.RetrieveData(database.AdapterType, "SELECT * FROM SecurityGroup ORDER BY Name");
foreach (DataRow row in securityGroupTable.Rows)
{
Guid id = database.Guid(row, "ID");
securityGroupList.Add(new SecurityGroup()
{
ID = id,
Name = UserInfo.SIDToAccountName(row.Field("Name")),
Description = row.Field