//******************************************************************************************************
// UserAccount.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 UserAccount : DataModelBase
{
#region [ Members ]
private Guid m_id;
private string m_name;
private string m_password;
private string m_firstName;
private string m_lastName;
private Guid m_defaultNodeID;
private string m_phone;
private string m_email;
private bool m_lockedOut;
private bool m_useADAuthentication;
private DateTime m_changePasswordOn;
private DateTime m_createdOn;
private string m_createdBy;
private DateTime m_updatedOn;
private string m_updatedBy;
#endregion
#region [ Properties ]
///
/// Gets or sets 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 Name.
///
[Required(ErrorMessage = " User account name is a required field, please provide value.")]
[StringLength(200, ErrorMessage = "User account name cannot exceed 200 characters.")]
[DefaultValue("Add New User")]
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
OnPropertyChanged("Name");
}
}
///
/// Gets or sets Password.
///
[StringLength(200, ErrorMessage = "User Account password cannot exceed 200 characters.")]
public string Password
{
get
{
return m_password;
}
set
{
m_password = value;
OnPropertyChanged("Password");
}
}
///
/// Gets or sets FirstName.
///
[StringLength(200, ErrorMessage = "User Account password cannot exceed 200 characters.")]
public string FirstName
{
get
{
return m_firstName;
}
set
{
m_firstName = value;
OnPropertyChanged("FirstName");
}
}
///
/// Gets or sets LastName.
///
[StringLength(200, ErrorMessage = "User Account password cannot exceed 200 characters.")]
public string LastName
{
get
{
return m_lastName;
}
set
{
m_lastName = value;
OnPropertyChanged("LastName");
}
}
///
/// Gets or sets DefaultNodeID.
///
[Required(ErrorMessage = "User account default node ID is a required field, please select a value.")]
public Guid DefaultNodeID
{
get
{
return m_defaultNodeID;
}
set
{
m_defaultNodeID = value;
OnPropertyChanged("DefaultNodeID");
}
}
///
/// Gets or sets Phone
///
[StringLength(200, ErrorMessage = "User Account password cannot exceed 200 characters.")]
public string Phone
{
get
{
return m_phone;
}
set
{
m_phone = value;
OnPropertyChanged("Phone");
}
}
///
/// Gets or sets Email
///
[StringLength(200, ErrorMessage = "User Account password cannot exceed 200 characters.")]
public string Email
{
get
{
return m_email;
}
set
{
m_email = value;
OnPropertyChanged("Email");
}
}
///
/// Gets or sets LockedOut.
///
[DefaultValue(false)]
public bool LockedOut
{
get
{
return m_lockedOut;
}
set
{
m_lockedOut = value;
OnPropertyChanged("LockedOut");
}
}
///
/// Gets or sets UseADAuthentication.
///
[DefaultValue(true)]
public bool UseADAuthentication
{
get
{
return m_useADAuthentication;
}
set
{
m_useADAuthentication = value;
OnPropertyChanged("UseADAuthentication");
}
}
///
/// Gets or sets ChangePasswordOn.
///
// Because of database design no validation attributes are applied.
public DateTime ChangePasswordOn
{
get
{
return m_changePasswordOn;
}
set
{
m_changePasswordOn = value;
OnPropertyChanged("ChangePasswordOn");
}
}
///
/// Gets or sets CreatedOn
///
// Field is populated by 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 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 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 trigger and has no screen interaction, so no validation attributes are applied
public string UpdatedBy
{
get
{
return m_updatedBy;
}
set
{
m_updatedBy = value;
}
}
#endregion
#region [ Static ]
// Static Methods
///
/// Loads information as an OberservableCollection{T}"/> style list.
///
/// to connection to database.
/// Collection of
public static ObservableCollection Load(AdoDataConnection database)
{
bool createdConnection = false;
try
{
createdConnection = CreateConnection(ref database);
ObservableCollection userAccountList = new ObservableCollection();
DataTable userAccountTable = database.Connection.RetrieveData(database.AdapterType, "SELECT * From UserAccount WHERE DefaultNodeID = '" + database.CurrentNodeID() + "' ORDER BY Name");
foreach (DataRow row in userAccountTable.Rows)
{
userAccountList.Add(new UserAccount()
{
ID = database.Guid(row, "ID"),
Name = UserInfo.SIDToAccountName(row.Field("Name")),
Password = row.Field