AspnetSchemaversionsDTO Partial Class

A partial data object class for the “Schemaversions” table in the ASP.NET 2.0 provider database. The relevant data transfer objects contain only the serializable data of a data object.

[csharp]

 //*****************************************************************************
// This file is part of the data access layer example to the ASP.NET 2.0 provider database
// This file was written by Adam Buenz [WSS MVP] of ARB Security Solutions, LLC
// http://www.sharepointsecurity.com
//
// This file and its parts is free for re-distribution, for use in both free
// and commercial applications, however this header must remain intact for legal
// use. The data access layer example is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//*****************************************************************************
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Aspnet.Provider.Datalayer.Commands;
using Aspnet.Provider.Datalayer.DataTransferObjects;

namespace Aspnet.Provider.Datalayer
{
///
/// The AspnetUsers class.
///
public partial class AspnetUsers : IPersistable
{
#region Members

private bool isNew;
private bool _isNew;
private Guid applicationid;
private Guid userid;
private string username;
private string loweredusername;
private string mobilealias;
private bool isanonymous;
private DateTime lastactivitydate;

#endregion

#region Properties

///
/// The Applicationid.
///
public virtual Guid Applicationid
{
get { return this.applicationid; }
set { this.applicationid = value; }
}

///
/// The Userid.
///
public virtual Guid Userid
{
get { return this.userid; }
set { this.userid = value; }
}

///
/// The Username.
///
[StringInfo(256, true)]
public virtual string Username
{
get { return this.username; }
set { this.username = value; }
}

///
/// The Loweredusername.
///
[StringInfo(256, true)]
public virtual string Loweredusername
{
get { return this.loweredusername; }
set { this.loweredusername = value; }
}

///
/// The Mobilealias.
///
[StringInfo(16, false)]
public virtual string Mobilealias
{
get { return this.mobilealias; }
set { this.mobilealias = value; }
}

///
/// The Isanonymous.
///
public virtual bool Isanonymous
{
get { return this.isanonymous; }
set { this.isanonymous = value; }
}

///
/// The Lastactivitydate.
///
public virtual DateTime Lastactivitydate
{
get { return this.lastactivitydate; }
set { this.lastactivitydate = value; }
}

#endregion

#region ColumnNames

///
/// The corresponding schema name.
///
internal const string SchemaName = “dbo”;

///
/// The corresponding table name.
///
internal const string TableName = “aspnet_Users”;

///
/// The column names.
///
internal class ColumnNames
{
///
/// The column name of the Applicationid property.
///
public const string Applicationid=”ApplicationId”;
///
/// The column name of the Userid property.
///
public const string Userid=”UserId”;
///
/// The column name of the Username property.
///
public const string Username=”UserName”;
///
/// The column name of the Loweredusername property.
///
public const string Loweredusername=”LoweredUserName”;
///
/// The column name of the Mobilealias property.
///
public const string Mobilealias=”MobileAlias”;
///
/// The column name of the Isanonymous property.
///
public const string Isanonymous=”IsAnonymous”;
///
/// The column name of the Lastactivitydate property.
///
public const string Lastactivitydate=”LastActivityDate”;
}

#endregion

///
/// The default constructor.
///
public AspnetUsers()
{
this.isNew = true;
PersistenceManager.InvokeInstanceMethod(this, “CreationComplete”, null);
}

///
/// The constructor of the required fields.
///
///
The Applicationid. ///
The Userid. ///
The Username. ///
The Loweredusername. ///
The Isanonymous. ///
The Lastactivitydate. public AspnetUsers(Guid applicationid, Guid userid, string username, string loweredusername, bool isanonymous, DateTime lastactivitydate)
{
this.applicationid = applicationid;
this.userid = userid;
this.username = username;
this.loweredusername = loweredusername;
this.isanonymous = isanonymous;
this.lastactivitydate = lastactivitydate;

this.isNew = true;
PersistenceManager.InvokeInstanceMethod(this, “CreationComplete”, null);
}

///
/// The constructor from IDataReader.
///
///
An initalized IDataReader. internal AspnetUsers(IDataReader reader)
{
if ((reader[“ApplicationId”] != null) && (reader[“ApplicationId”] != DBNull.Value))
this.applicationid = (Guid)reader[“ApplicationId”];
if ((reader[“UserId”] != null) && (reader[“UserId”] != DBNull.Value))
this.userid = (Guid)reader[“UserId”];
if ((reader[“UserName”] != null) && (reader[“UserName”] != DBNull.Value))
this.username = (string)reader[“UserName”];
if ((reader[“LoweredUserName”] != null) && (reader[“LoweredUserName”] != DBNull.Value))
this.loweredusername = (string)reader[“LoweredUserName”];
if ((reader[“MobileAlias”] != null) && (reader[“MobileAlias”] != DBNull.Value))
this.mobilealias = (string)reader[“MobileAlias”];
if ((reader[“IsAnonymous”] != null) && (reader[“IsAnonymous”] != DBNull.Value))
this.isanonymous = (bool)reader[“IsAnonymous”];
if ((reader[“LastActivityDate”] != null) && (reader[“LastActivityDate”] != DBNull.Value))
this.lastactivitydate = (DateTime)reader[“LastActivityDate”];

this.isNew = false;
}

///
/// Creates an IDbCommand to insert an object into the database.
///
/// An initialized IDbCommand object.
internal virtual IDbCommand CreateInsertCommand()
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = “insert into [dbo].[aspnet_Users] ([ApplicationId], [UserId], [UserName], [LoweredUserName], [MobileAlias], [IsAnonymous], [LastActivityDate]) values (@applicationid, @userid, @username, @loweredusername, @mobilealias, @isanonymous, @lastactivitydate)”;
cmd.Parameters.AddWithValue(“@applicationid”, this.applicationid);
cmd.Parameters.AddWithValue(“@userid”, this.userid);
cmd.Parameters.AddWithValue(“@username”, this.username);
cmd.Parameters.AddWithValue(“@loweredusername”, this.loweredusername);
if (String.IsNullOrEmpty(this.mobilealias))
cmd.Parameters.AddWithValue(“@mobilealias”, DBNull.Value);
else
cmd.Parameters.AddWithValue(“@mobilealias”, this.mobilealias);
cmd.Parameters.AddWithValue(“@isanonymous”, this.isanonymous);
cmd.Parameters.AddWithValue(“@lastactivitydate”, this.lastactivitydate);

cmd.Connection = PersistenceManager.Connection;
return cmd;
}

///
/// Creates an IDbCommand to update an object in the database.
///
/// An initialized IDbCommand object.
internal virtual IDbCommand CreateUpdateCommand()
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = “update [dbo].[aspnet_Users] set [ApplicationId]=@applicationid, [UserName]=@username, [LoweredUserName]=@loweredusername, [MobileAlias]=@mobilealias, [IsAnonymous]=@isanonymous, [LastActivityDate]=@lastactivitydate where ([UserId]=@userid)”;
cmd.Parameters.AddWithValue(“@applicationid”, this.applicationid);
cmd.Parameters.AddWithValue(“@username”, this.username);
cmd.Parameters.AddWithValue(“@loweredusername”, this.loweredusername);
if (String.IsNullOrEmpty(this.mobilealias))
cmd.Parameters.AddWithValue(“@mobilealias”, DBNull.Value);
else
cmd.Parameters.AddWithValue(“@mobilealias”, this.mobilealias);
cmd.Parameters.AddWithValue(“@isanonymous”, this.isanonymous);
cmd.Parameters.AddWithValue(“@lastactivitydate”, this.lastactivitydate);
cmd.Parameters.AddWithValue(“@userid”, this.userid);

cmd.Connection = PersistenceManager.Connection;
return cmd;
}

///
/// Creates an IDbCommand to delete an object in the database.
///
/// An initialized IDbCommand object.
internal virtual IDbCommand CreateDeleteCommand()
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = “delete from [dbo].[aspnet_Users] where ([UserId]=@userid)”;
cmd.Parameters.AddWithValue(“@userid”, this.userid);

cmd.Connection = PersistenceManager.Connection;
return cmd;
}

///
/// Persists the object.
///
public virtual void Persist()
{
PersistenceManager.InvokeInstanceMethod(this, “PrePersist”, null);

IDbCommand cmd;

if (this.isNew)
cmd = this.CreateInsertCommand();
else
cmd = this.CreateUpdateCommand();

cmd.Transaction = PersistenceManager.Transaction;
PersistenceManager.RegisterInTransaction(this);

bool connWasClosed =
PersistenceManager.Connection.State.Equals(ConnectionState.Closed) ||
PersistenceManager.Connection.State.Equals(ConnectionState.Broken);

try
{
if (connWasClosed)
PersistenceManager.Connection.Open();

cmd.ExecuteNonQuery();

this.isNew = false;

if (connWasClosed)
PersistenceManager.Connection.Close();
}
catch (Exception ex)
{
if (connWasClosed)
PersistenceManager.Connection.Close();
throw ex;
}
}

///
/// Deletes the object.
///
public virtual void Delete()
{
PersistenceManager.InvokeInstanceMethod(this, “PreDelete”, null);

IDbCommand cmd = this.CreateDeleteCommand();
cmd.Transaction = PersistenceManager.Transaction;

bool connWasClosed =
PersistenceManager.Connection.State.Equals(ConnectionState.Closed) ||
PersistenceManager.Connection.State.Equals(ConnectionState.Broken);

try
{
if (connWasClosed)
PersistenceManager.Connection.Open();

cmd.ExecuteNonQuery();

if (connWasClosed)
PersistenceManager.Connection.Close();
}
catch (Exception ex)
{
if (connWasClosed)
PersistenceManager.Connection.Close();
throw ex;
}
}

///
/// Retrieves a AspnetUsers object by its primary key (Throws System.DataException).
///
///
The Userid. /// The AspnetUsers object.
public static AspnetUsers Get(Guid userid)
{
AspnetUsers aspnetusers;
if (AspnetUsers.TryGet(userid, out aspnetusers))
return aspnetusers;
else
throw new DataException(“‘AspnetUsers’ object not found.”);
}

///
/// Tries to retrieve a AspnetUsers object by its primary key.
///
///
The Userid. ///
The found AspnetUsers or null if the primary key value does not exist. /// True if the AspnetUsers exists, else false.
public static bool TryGet(Guid userid, out AspnetUsers aspnetusers)
{
SqlCommand cmd = new SqlCommand(“select * from [dbo].[aspnet_Users] where ([UserId]=@userid)”);
cmd.Parameters.AddWithValue(“@userid”, userid);

IList list = AspnetUsers.Query(cmd);

if (list.Count == 0)
{
aspnetusers = null;
return false;
}
else
{
aspnetusers = list[0];
return true;
}
}

///
/// For internal use only.
///
public virtual void SaveState()
{
this._isNew = this.isNew;
}

///
/// For internal use only.
///
public virtual void RestoreState()
{
this.isNew = this._isNew;
}

///
/// Refreshes the internal state of the object.
///
/// This method should be called after xml deserialization to refresh internal flags.
public virtual void RefreshState()
{
AspnetUsers aspnetusers;

if (AspnetUsers.TryGet(this.userid, out aspnetusers))
{
this.isNew = false;
}
else
{
this.isNew = true;
}
}

///
/// Returns a Data Transfer Object of this AspnetUsers.
///
/// A Data Transfer Object of this AspnetUsers.
public virtual AspnetUsersDTO GetDTO()
{
AspnetUsersDTO dto = new AspnetUsersDTO();

dto.Applicationid = this.Applicationid;
dto.Userid = this.Userid;
dto.Username = this.Username;
dto.Loweredusername = this.Loweredusername;
dto.Mobilealias = this.Mobilealias;
dto.Isanonymous = this.Isanonymous;
dto.Lastactivitydate = this.Lastactivitydate;

return dto;
}

///
/// Applies a Data Transfer Object data to this AspnetUsers.
///
///
The Data Transfer Object. public virtual void SetDTO(AspnetUsersDTO dto)
{
this.Applicationid = dto.Applicationid;
this.Userid = dto.Userid;
this.Username = dto.Username;
this.Loweredusername = dto.Loweredusername;
this.Mobilealias = dto.Mobilealias;
this.Isanonymous = dto.Isanonymous;
this.Lastactivitydate = dto.Lastactivitydate;
}

///
/// Perfoms a query on AspnetUsers objects.
///
///
An IDbCommand containing the select statement. /// A result list of AspnetUsers objects.
internal static IList Query(IDbCommand command)
{
command.Connection = PersistenceManager.Connection;
command.Transaction = PersistenceManager.Transaction;

bool connWasClosed =
PersistenceManager.Connection.State.Equals(ConnectionState.Closed) ||
PersistenceManager.Connection.State.Equals(ConnectionState.Broken);

try
{
if (connWasClosed)
PersistenceManager.Connection.Open();

List list = new List();
IDataReader reader = command.ExecuteReader();

using (reader)
{
while (reader.Read())
list.Add(new AspnetUsers(reader));
}

if (connWasClosed)
PersistenceManager.Connection.Close();

return list;
}
catch (Exception ex)
{
if (connWasClosed)
PersistenceManager.Connection.Close();
throw ex;
}
}

///
/// Finds all AspnetUsers objects with a certain Applicationid value.
///
///
The Applicationid value. /// All AspnetUsers objects with a certain Applicationid value.
public static IList FindByApplicationid(Guid applicationid)
{
return AspnetUsers.Query(AspnetUsersCommands.FindByApplicationid(applicationid));
}

///
/// Finds all AspnetUsers objects with a certain Username value.
///
///
The Username value (‘*’ can be used as a wildcard). /// All AspnetUsers objects with a certain Username value.
public static IList FindByUsername(string username)
{
return AspnetUsers.Query(AspnetUsersCommands.FindByUsername(username));
}

///
/// Finds all AspnetUsers objects with a certain Loweredusername value.
///
///
The Loweredusername value (‘*’ can be used as a wildcard). /// All AspnetUsers objects with a certain Loweredusername value.
public static IList FindByLoweredusername(string loweredusername)
{
return AspnetUsers.Query(AspnetUsersCommands.FindByLoweredusername(loweredusername));
}

///
/// Finds all AspnetUsers objects with a certain Mobilealias value.
///
///
The Mobilealias value (‘*’ can be used as a wildcard). /// All AspnetUsers objects with a certain Mobilealias value.
public static IList FindByMobilealias(string mobilealias)
{
return AspnetUsers.Query(AspnetUsersCommands.FindByMobilealias(mobilealias));
}

///
/// Finds all AspnetUsers objects with a certain Isanonymous value.
///
///
The Isanonymous value. /// All AspnetUsers objects with a certain Isanonymous value.
public static IList FindByIsanonymous(bool isanonymous)
{
return AspnetUsers.Query(AspnetUsersCommands.FindByIsanonymous(isanonymous));
}

///
/// Finds all AspnetUsers objects with a certain Lastactivitydate value.
///
///
The Lastactivitydate value. /// All AspnetUsers objects with a certain Lastactivitydate value.
public static IList FindByLastactivitydate(DateTime lastactivitydate)
{
return AspnetUsers.Query(AspnetUsersCommands.FindByLastactivitydate(lastactivitydate));
}

}
}

[/csharp]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *