//******************************************************************************************************
// ApplicationRole.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 value and Guid parameter handling for Save() operation.
// 12/20/2012 - Starlynn Danyelle Gilliam
// Modified Header.
//
//******************************************************************************************************
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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 ApplicationRole : DataModelBase
{
#region [ Members ]
// Fields
private Guid m_id;
private Guid m_nodeID;
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_currentGroups;
private Dictionary m_possibleGroups;
private Dictionary m_currentUsers;
private Dictionary m_possibleUsers;
#endregion
#region [ Properties ]
///
/// Gets or sets ID.
///
// Field is populated by database via trigger and has no screen interaction, so no validation attributes are applied
public Guid ID
{
get
{
return m_id;
}
set
{
m_id = value;
}
}
///
/// Gets or sets NodeID.
///
[Required(ErrorMessage = "Application role node ID is a required field, please select a value.")]
public Guid NodeID
{
get
{
return m_nodeID;
}
set
{
m_nodeID = value;
OnPropertyChanged("NodeID");
}
}
///
/// Gets or sets Name.
///
[Required(ErrorMessage = " Application role name is a required field, please provide value.")]
[StringLength(200, ErrorMessage = "Application role name cannot exceed 200 characters.")]
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
OnPropertyChanged("Name");
}
}
///
/// Gets or sets 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 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;
}
}
///
/// Gets or sets 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 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 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 CurrentRoleGroups.
///
public Dictionary CurrentGroups
{
get
{
return m_currentGroups;
}
set
{
m_currentGroups = value;
OnPropertyChanged("CurrentGroups");
}
}
///
/// Gets or sets PossibleRoleGroups.
///
public Dictionary PossibleGroups
{
get
{
return m_possibleGroups;
}
set
{
m_possibleGroups = value;
OnPropertyChanged("PossibleGroups");
}
}
///
/// Gets or sets CurrentRoleUsers.
///
public Dictionary CurrentUsers
{
get
{
return m_currentUsers;
}
set
{
m_currentUsers = value;
OnPropertyChanged("CurrentUsers");
}
}
///
/// Gets or sets PossibleRoleUsers.
///
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 applicationRoleList = new ObservableCollection();
string query = database.ParameterizedQueryString("SELECT * FROM ApplicationRole WHERE NodeID = {0} ORDER BY Name", "nodeID");
DataTable applicationRoleTable = database.Connection.RetrieveData(database.AdapterType, query, database.CurrentNodeID());
foreach (DataRow row in applicationRoleTable.Rows)
{
applicationRoleList.Add(new ApplicationRole()
{
ID = database.Guid(row, "ID"), //Guid.Parse(row.Field