private void DataPortal_Fetch(ProfileCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; string commandText = String.Format("SELECT [UniqueID], [Username], [ApplicationName], [IsAnonymous], [LastActivityDate], [LastUpdatedDate] FROM [dbo].[Profiles] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using(var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) Map(reader); else throw new Exception(String.Format("The record was not found in 'dbo.Profiles' using the following criteria: {0}.", criteria)); } } } OnFetched(); }
/// <summary> /// Fetch ProfileList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public ProfileList Fetch(ProfileCriteria criteria) { ProfileList item = (ProfileList)Activator.CreateInstance(typeof(ProfileList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return item; // Fetch Child objects. string commandText = String.Format("SELECT [UniqueID], [Username], [ApplicationName], [IsAnonymous], [LastActivityDate], [LastUpdatedDate] FROM [dbo].[Profiles] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using(var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { item.Add(new ProfileFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return item; }
private Profile Create(ProfileCriteria criteria) { var item = (Profile)Activator.CreateInstance(typeof(Profile), true); bool cancel = false; OnCreating(ref cancel); if (cancel) return item; var resource = Fetch(criteria); using (BypassPropertyChecks(item)) { item.Username = resource.Username; item.ApplicationName = resource.ApplicationName; item.IsAnonymous = resource.IsAnonymous; item.LastActivityDate = resource.LastActivityDate; item.LastUpdatedDate = resource.LastUpdatedDate; } CheckRules(item); MarkNew(item); OnCreated(); return item; }
private void DataPortal_Fetch(ProfileCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; RaiseListChangedEvents = false; // Fetch Child objects. string commandText = String.Format("SELECT [UniqueID], [Username], [ApplicationName], [IsAnonymous], [LastActivityDate], [LastUpdatedDate] FROM [dbo].[Profiles] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) { do { this.Add(PetShop.Business.Profile.GetProfile(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
public static void GetProfileList(System.String username, EventHandler<DataPortalResult<ProfileList>> handler) { var criteria = new ProfileCriteria { Username = username }; var dp = new DataPortal<ProfileList>(); dp.FetchCompleted += handler; dp.BeginFetch(criteria); }
/// <summary> /// Fetch ProfileList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public ProfileList Fetch(ProfileCriteria criteria) { ProfileList item = (ProfileList)Activator.CreateInstance(typeof(ProfileList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(item); } // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Profile_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_IsAnonymousHasValue", criteria.IsAnonymousHasValue); command.Parameters.AddWithValue("@p_LastActivityDateHasValue", criteria.LastActivityDateHasValue); command.Parameters.AddWithValue("@p_LastUpdatedDateHasValue", criteria.LastUpdatedDateHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { item.Add(new ProfileFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return(item); }
/// <summary> /// Fetch Profile. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Profile Fetch(ProfileCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Profile item; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Profile_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_IsAnonymousHasValue", criteria.IsAnonymousHasValue); command.Parameters.AddWithValue("@p_LastActivityDateHasValue", criteria.LastActivityDateHasValue); command.Parameters.AddWithValue("@p_LastUpdatedDateHasValue", criteria.LastUpdatedDateHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { item = Map(reader); } else { throw new Exception(String.Format("The record was not found in 'dbo.Profiles' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); OnFetched(); return(item); }
protected void DoDelete(ref Profile item) { // If we're not dirty then don't update the database. if (!item.IsDirty) { return; } // If we're new then don't call delete. if (item.IsNew) { return; } var criteria = new ProfileCriteria { UniqueID = item.UniqueID }; DoDelete(criteria); MarkNew(item); }
/// <summary> /// Fetch ProfileList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public ProfileList Fetch(ProfileCriteria criteria) { ProfileList item = (ProfileList)Activator.CreateInstance(typeof(ProfileList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(item); } // Fetch Child objects. string commandText = String.Format("SELECT [UniqueID], [Username], [ApplicationName], [IsAnonymous], [LastActivityDate], [LastUpdatedDate] FROM [dbo].[Profiles] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { item.Add(new ProfileFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return(item); }
/// <summary> /// Fetch Profile. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Profile Fetch(ProfileCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Profile item; string commandText = String.Format("SELECT [UniqueID], [Username], [ApplicationName], [IsAnonymous], [LastActivityDate], [LastUpdatedDate] FROM [dbo].[Profiles] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { item = Map(reader); } else { throw new Exception(String.Format("The record was not found in 'dbo.Profiles' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); OnFetched(); return(item); }
/// <summary> /// Fetch ProfileList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public ProfileList Fetch(ProfileCriteria criteria) { ProfileList item = (ProfileList)Activator.CreateInstance(typeof(ProfileList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return item; // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Profile_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_IsAnonymousHasValue", criteria.IsAnonymousHasValue); command.Parameters.AddWithValue("@p_LastActivityDateHasValue", criteria.LastActivityDateHasValue); command.Parameters.AddWithValue("@p_LastUpdatedDateHasValue", criteria.LastUpdatedDateHasValue); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) { do { item.Add(new ProfileFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return item; }
/// <summary> /// CodeSmith generated stub method that is called when deleting the <see cref="Profile"/> object. /// </summary> /// <param name="criteria"><see cref="ProfileCriteria"/> object containing the criteria of the object to delete.</param> /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param> partial void OnDeleting(ProfileCriteria criteria, ref bool cancel);
/// <summary> /// CodeSmith generated stub method that is called when fetching the <see cref="Profile"/> object. /// </summary> /// <param name="criteria"><see cref="ProfileCriteria"/> object containing the criteria of the object to fetch.</param> /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param> partial void OnFetching(ProfileCriteria criteria, ref bool cancel);
public static Profile GetByUsername(System.String username) { var criteria = new ProfileCriteria { Username = username }; return DataPortal.Fetch<Profile>(criteria); }
public void Delete(ProfileCriteria criteria) { //Note: this call to delete is for immediate deletion and doesn't keep track of any entity state. DoDelete(criteria); }
/// <summary> /// This call to delete is for immediate deletion and doesn't keep track of any entity state. /// </summary> /// <param name="criteria">The Criteria.</param> private void DoDelete(ProfileCriteria criteria) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) return; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Profile_Delete]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); } } OnDeleted(); }
/// <summary> /// CodeSmith generated stub method that is called when fetching the child <see cref="Profile"/> object. /// </summary> /// <param name="criteria"><see cref="ProfileCriteria"/> object containing the criteria of the object to fetch.</param> /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param> partial void OnFetching(ProfileCriteria criteria, ref bool cancel);
/// <summary> /// Fetch Profile. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Profile Fetch(ProfileCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return null; Profile item; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Profile_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_IsAnonymousHasValue", criteria.IsAnonymousHasValue); command.Parameters.AddWithValue("@p_LastActivityDateHasValue", criteria.LastActivityDateHasValue); command.Parameters.AddWithValue("@p_LastUpdatedDateHasValue", criteria.LastUpdatedDateHasValue); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) item = Map(reader); else throw new Exception(String.Format("The record was not found in 'dbo.Profiles' using the following criteria: {0}.", criteria)); } } } MarkOld(item); OnFetched(); return item; }
//[Transactional(TransactionalTypes.TransactionScope)] protected void DataPortal_Delete(ProfileCriteria criteria, SqlConnection connection) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) return; string commandText = String.Format("DELETE FROM [dbo].[Profiles] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); } OnDeleted(); }
public void Delete(ProfileCriteria criteria) { // Note: this call to delete is for immediate deletion and doesn't keep track of any entity state. DoDelete(criteria); }
protected void DoDelete(ref Profile item) { // If we're not dirty then don't update the database. if (!item.IsDirty) return; // If we're new then don't call delete. if (item.IsNew) return; var criteria = new ProfileCriteria{UniqueID = item.UniqueID}; DoDelete(criteria); MarkNew(item); }