/// <summary> /// Deletes all roles from the database which are connected with specific member. /// </summary> /// <returns>Returns true if it was successfully deleted.</returns> public virtual bool Delete() { this.WasDeleted = false; SpRoleAdmin sp = new SpRoleAdmin(String.Format("DELETE FROM {0} WHERE MemberTokenID=@MemberTokenID", Table)); sp.AddParameter("MemberTokenID", MemberTokenID); if (sp.ExecuteNonQuery() == 0) { this.WasDeleted = true; } return(this.WasDeleted); }
/// <summary> /// Deletes all roles from the database which are connected with specific member. /// </summary> /// <returns>Returns true if it was successfully deleted.</returns> public virtual bool Delete() { this.WasDeleted = false; SpRoleAdmin sp = new SpRoleAdmin(String.Format(@" DELETE FROM DomainProfileFields WHERE DomainID = @DomainID; DELETE FROM MemberDomains WHERE DomainID = @DomainID; DELETE FROM {0} WHERE DomainID = @DomainID;", Table)); sp.AddParameter("DomainID", DomainID); if (sp.ExecuteNonQuery() == 0) { this.WasDeleted = true; } return(this.WasDeleted); }
/// <summary> /// Updates member token string and set modification date. /// </summary> /// <returns>Returns true if it was successfully deleted.</returns> public virtual bool SaveToken() { bool result = false; SpRoleAdmin sp = null; if (this.MemberID > 0) { sp = new SpRoleAdmin(String.Format(@" UPDATE {0} SET Token = @Token, Modified = @Modified WHERE MemberID = @MemberID", Table)); sp.AddParameter("MemberID", MemberID); sp.AddParameter("Token", Token); sp.AddParameter("Modified", DateTime.Now.ToUniversalTime()); if (sp.ExecuteNonQuery() == 0) { result = true; } } return(result); }
/// <summary> /// Save attempt number for specific type. /// </summary> /// <returns></returns> public virtual bool SaveAttempts() { bool result = false; SpRoleAdmin sp = null; if (this.MemberID > 0) { sp = new SpRoleAdmin(@" UPDATE " + ApplicationTables.TableName(this) + @" SET Attempts = @Attempts, Modified = @Modified WHERE MemberID = @MemberID"); sp.AddParameter("MemberID", MemberID); sp.AddParameter("Attempts", Attempts); sp.AddParameter("AttemptType", AttemptType); sp.AddParameter("Modified", DateTime.Now.ToUniversalTime()); if (sp.ExecuteNonQuery() == 0) { result = true; } } return(result); }
/// <summary> /// Inserts an object in database according to class properties. /// </summary> /// <returns>Returns true if it was successfully saved.</returns> public virtual bool Save() { this.WasSaved = false; SpRoleAdmin sp = null; if (this.MemberTokenID > 0) { sp = new SpRoleAdmin(String.Format(@" UPDATE {0} SET Token = @Token, GeneratedBy = @GeneratedBy, Modified = @Modified WHERE MemberTokenID = @MemberTokenID", Table)); sp.AddParameter("MemberTokenID", MemberTokenID); sp.AddParameter("Modified", DateTime.UtcNow); } else { sp = new SpRoleAdmin(String.Format(@" INSERT INTO {0} ( MemberID, Token,GeneratedBy, Created, Modified) VALUES( @MemberID, @Token, @GeneratedBy, @Created, @Modified); SELECT @MemberTokenID = @@IDENTITY", Table)); sp.AddParameter("MemberTokenID", MemberID, System.Data.ParameterDirection.Output); if (Modified != DateTime.MinValue) { sp.AddParameter("Modified", Created); } else { sp.AddParameter("Modified", DateTime.UtcNow); } } sp.AddParameter("MemberID", MemberID); sp.AddParameter("GeneratedBy", GeneratedBy); sp.AddParameter("Token", Token); if (Created != DateTime.MinValue) { sp.AddParameter("Created", Created); } else { sp.AddParameter("Created", DateTime.UtcNow); } if (sp.ExecuteNonQuery() == 0) { this.WasSaved = true; } if (this.MemberTokenID <= 0) { switch (DbRoleAdmin.CurrentProvider) { case DatabaseProvider.MSSQLServer: { MemberID = (long)sp.GetParameter("MemberTokenID"); break; } case DatabaseProvider.MySQLServer: { break; } } } return(this.WasSaved); }
/// <summary> /// Deletes all roles from the database which are connected with specific member. /// </summary> /// <returns>Returns true if it was successfully deleted.</returns> public virtual bool Delete() { this.WasDeleted = false; SpRoleAdmin sp = new SpRoleAdmin(String.Format("DELETE FROM {0} WHERE MemberTokenID=@MemberTokenID",Table)); sp.AddParameter("MemberTokenID", MemberTokenID); if (sp.ExecuteNonQuery() == 0) this.WasDeleted = true; return this.WasDeleted; }
/// <summary> /// Updates member token string and set modification date. /// </summary> /// <returns>Returns true if it was successfully deleted.</returns> public virtual bool SaveToken() { bool result = false; SpRoleAdmin sp = null; if (this.MemberID > 0) { sp = new SpRoleAdmin(String.Format(@" UPDATE {0} SET Token = @Token, Modified = @Modified WHERE MemberID = @MemberID",Table)); sp.AddParameter("MemberID", MemberID); sp.AddParameter("Token", Token); sp.AddParameter("Modified", DateTime.Now.ToUniversalTime()); if (sp.ExecuteNonQuery() == 0) result = true; } return result; }
/// <summary> /// Inserts an object in database according to class properties. /// </summary> /// <returns>Returns true if it was successfully saved.</returns> public virtual bool Save() { this.WasSaved = false; SpRoleAdmin sp = null; if (this.MemberTokenID > 0) { sp = new SpRoleAdmin(String.Format(@" UPDATE {0} SET Token = @Token, GeneratedBy = @GeneratedBy, Modified = @Modified WHERE MemberTokenID = @MemberTokenID",Table)); sp.AddParameter("MemberTokenID", MemberTokenID); sp.AddParameter("Modified", DateTime.UtcNow); } else { sp = new SpRoleAdmin(String.Format(@" INSERT INTO {0} ( MemberID, Token,GeneratedBy, Created, Modified) VALUES( @MemberID, @Token, @GeneratedBy, @Created, @Modified); SELECT @MemberTokenID = @@IDENTITY",Table)); sp.AddParameter("MemberTokenID", MemberID, System.Data.ParameterDirection.Output); if (Modified != DateTime.MinValue) sp.AddParameter("Modified", Created); else sp.AddParameter("Modified", DateTime.UtcNow); } sp.AddParameter("MemberID", MemberID); sp.AddParameter("GeneratedBy", GeneratedBy); sp.AddParameter("Token", Token); if(Created != DateTime.MinValue) sp.AddParameter("Created", Created); else sp.AddParameter("Created", DateTime.UtcNow); if (sp.ExecuteNonQuery() == 0) this.WasSaved = true; if (this.MemberTokenID <= 0) { switch (DbRoleAdmin.CurrentProvider) { case DatabaseProvider.MSSQLServer: { MemberID = (long)sp.GetParameter("MemberTokenID"); break; } case DatabaseProvider.MySQLServer: { break; } } } return this.WasSaved; }
/// <summary> /// Inserts an object in database according to class properties. /// </summary> /// <returns>Returns true if it was successfully saved.</returns> public virtual bool Save() { this.WasSaved = false; SpRoleAdmin sp = null; if (this.DomainID > 0) { sp = new SpRoleAdmin(String.Format(@" UPDATE {0} SET Name = @Name, Description = @Description, Modified = @Modified WHERE DomainID = @DomainID ", Table)); sp.AddParameter("DomainID", DomainID); sp.AddParameter("Modified", DateTime.UtcNow); } else { sp = new SpRoleAdmin(String.Format(@" INSERT INTO {0} (Name, Description, Created) VALUES(@Name, @Description, @Created); SELECT @DomainID = @@IDENTITY", Table)); sp.AddParameter("DomainID", DomainID, System.Data.ParameterDirection.Output); } sp.AddParameter("Name", Name); if (Description == null || Description.Trim().Length == 0) { sp.AddParameter("Description", DBNull.Value); } else { sp.AddParameter("Description", Description); } if (Created != DateTime.MinValue) { sp.AddParameter("Created", Created); } else { sp.AddParameter("Created", DateTime.UtcNow); } if (sp.ExecuteNonQuery() == 0) { this.WasSaved = true; } if (this.DomainID <= 0) { switch (DbRoleAdmin.CurrentProvider) { case DatabaseProvider.MSSQLServer: { DomainID = (int)sp.GetParameter("DomainID"); break; } case DatabaseProvider.MySQLServer: { MySqlCommand cm = (MySqlCommand)sp.SqlCommand; if (cm.LastInsertedId > 0) { DomainID = Convert.ToInt32(cm.LastInsertedId); } break; } } } return(this.WasSaved); }
/// <summary> /// Deletes all roles from the database which are connected with specific member. /// </summary> /// <returns>Returns true if it was successfully deleted.</returns> public virtual bool Delete() { this.WasDeleted = false; SpRoleAdmin sp = new SpRoleAdmin(String.Format(@" DELETE FROM DomainProfileFields WHERE DomainID = @DomainID; DELETE FROM MemberDomains WHERE DomainID = @DomainID; DELETE FROM {0} WHERE DomainID = @DomainID;", Table)); sp.AddParameter("DomainID", DomainID); if (sp.ExecuteNonQuery() == 0) this.WasDeleted = true; return this.WasDeleted; }
/// <summary> /// Inserts an object in database according to class properties. /// </summary> /// <returns>Returns true if it was successfully saved.</returns> public virtual bool Save() { this.WasSaved = false; SpRoleAdmin sp = null; if (this.DomainID > 0) { sp = new SpRoleAdmin(String.Format(@" UPDATE {0} SET Name = @Name, Description = @Description, Modified = @Modified WHERE DomainID = @DomainID ", Table)); sp.AddParameter("DomainID", DomainID); sp.AddParameter("Modified", DateTime.UtcNow); } else { sp = new SpRoleAdmin(String.Format(@" INSERT INTO {0} (Name, Description, Created) VALUES(@Name, @Description, @Created); SELECT @DomainID = @@IDENTITY", Table)); sp.AddParameter("DomainID", DomainID, System.Data.ParameterDirection.Output); } sp.AddParameter("Name", Name); if (Description == null || Description.Trim().Length == 0) sp.AddParameter("Description", DBNull.Value); else sp.AddParameter("Description", Description); if (Created != DateTime.MinValue) sp.AddParameter("Created", Created); else sp.AddParameter("Created", DateTime.UtcNow); if (sp.ExecuteNonQuery() == 0) this.WasSaved = true; if (this.DomainID <= 0) { switch (DbRoleAdmin.CurrentProvider) { case DatabaseProvider.MSSQLServer: { DomainID = (int)sp.GetParameter("DomainID"); break; } case DatabaseProvider.MySQLServer: { MySqlCommand cm = (MySqlCommand)sp.SqlCommand; if (cm.LastInsertedId > 0) DomainID = Convert.ToInt32(cm.LastInsertedId); break; } } } return this.WasSaved; }
/// <summary> /// Inserts an object in database according to class properties. /// </summary> /// <returns>Returns true if it was successfully saved.</returns> public virtual bool Save() { this.WasSaved = false; SpRoleAdmin sp = null; if (this.AttemptID > 0) { sp = new SpRoleAdmin(String.Format(@" UPDATE {0} SET Attempts = @Attempts, AttemptType = @AttemptType, IsAttemptValid = @IsAttemptValid, Modified = @Modified WHERE AttemptID = @AttemptID", Table)); sp.AddParameter("AttemptID", AttemptID); sp.AddParameter("Modified", DateTime.UtcNow); } else { switch (DbRoleAdmin.CurrentProvider) { case DatabaseProvider.MSSQLServer: { sp = new SpRoleAdmin(String.Format(@" IF NOT EXISTS(SELECT AttemptID FROM {0} WHERE MemberID = @MemberID AND AttemptType = @AttemptType AND Year(Created) = Year(@Created) AND Month(Created) = Month(@Created) AND Day(Created) = Day(@Created) AND IsAttemptValid = 1) BEGIN INSERT INTO {0} ( MemberID, Attempts,AttemptType, Created, IsAttemptValid) VALUES( @MemberID, @Attempts, @AttemptType, @CreatedNow, @IsAttemptValid); SELECT @AttemptID = @@IDENTITY END ELSE BEGIN UPDATE {0} SET Attempts = @Attempts, Modified = @Modified WHERE AttemptID = @AttemptID AND AttemptType = @AttemptType END ", Table)); break; } case DatabaseProvider.MySQLServer: { sp = new SpRoleAdmin(String.Format(@" INSERT INTO {0} (MemberID, Attempts, AttemptType, Created, IsAttemptValid) SELECT @MemberID, @Attempts, @AttemptType, @CreatedNow, @IsAttemptValid FROM DUAL WHERE NOT EXISTS(SELECT * FROM {0} WHERE MemberID = @MemberID AND AttemptType = @AttemptType AND Year(Created) = Year(@Created) AND Month(Created) = Month(@Created) AND Day(Created) = Day(@Created) AND IsAttemptValid = 1) LIMIT 1; UPDATE {0} SET Attempts = @Attempts, Modified = @Modified WHERE AttemptID = @AttemptID AND AttemptType = @AttemptType; ", Table)); break; } } sp.AddParameter("AttemptID", MemberID, System.Data.ParameterDirection.Output); sp.AddParameter("Modified", DateTime.UtcNow); } sp.AddParameter("MemberID", MemberID); sp.AddParameter("AttemptType", AttemptType); sp.AddParameter("Attempts", Attempts); sp.AddParameter("CreatedNow", DateTime.UtcNow); sp.AddParameter("Created", Created != DateTime.MinValue ? Created : DateTime.UtcNow); sp.AddParameter("IsAttemptValid", IsAttemptValid); if (sp.ExecuteNonQuery() == 0) { this.WasSaved = true; } if (this.AttemptID <= 0) { switch (DbRoleAdmin.CurrentProvider) { case DatabaseProvider.MSSQLServer: { AttemptID = (long)sp.GetParameter("AttemptID"); break; } case DatabaseProvider.MySQLServer: { MySqlCommand cm = (MySqlCommand)sp.SqlCommand; if (cm.LastInsertedId > 0) { AttemptID = Convert.ToInt64(cm.LastInsertedId); } break; } } } return(this.WasSaved); }
/// <summary> /// Save attempt number for specific type. /// </summary> /// <returns></returns> public virtual bool SaveAttempts() { bool result = false; SpRoleAdmin sp = null; if (this.MemberID > 0) { sp = new SpRoleAdmin(@" UPDATE " + ApplicationTables.TableName(this) + @" SET Attempts = @Attempts, Modified = @Modified WHERE MemberID = @MemberID"); sp.AddParameter("MemberID", MemberID); sp.AddParameter("Attempts", Attempts); sp.AddParameter("AttemptType", AttemptType); sp.AddParameter("Modified",DateTime.Now.ToUniversalTime()); if (sp.ExecuteNonQuery() == 0) result = true; } return result; }
/// <summary> /// Inserts an object in database according to class properties. /// </summary> /// <returns>Returns true if it was successfully saved.</returns> public virtual bool Save() { this.WasSaved = false; SpRoleAdmin sp = null; if (this.AttemptID > 0) { sp = new SpRoleAdmin(String.Format(@" UPDATE {0} SET Attempts = @Attempts, AttemptType = @AttemptType, IsAttemptValid = @IsAttemptValid, Modified = @Modified WHERE AttemptID = @AttemptID",Table)); sp.AddParameter("AttemptID", AttemptID); sp.AddParameter("Modified", DateTime.UtcNow); } else { switch (DbRoleAdmin.CurrentProvider) { case DatabaseProvider.MSSQLServer: { sp = new SpRoleAdmin(String.Format(@" IF NOT EXISTS(SELECT AttemptID FROM {0} WHERE MemberID = @MemberID AND AttemptType = @AttemptType AND Year(Created) = Year(@Created) AND Month(Created) = Month(@Created) AND Day(Created) = Day(@Created) AND IsAttemptValid = 1) BEGIN INSERT INTO {0} ( MemberID, Attempts,AttemptType, Created, IsAttemptValid) VALUES( @MemberID, @Attempts, @AttemptType, @CreatedNow, @IsAttemptValid); SELECT @AttemptID = @@IDENTITY END ELSE BEGIN UPDATE {0} SET Attempts = @Attempts, Modified = @Modified WHERE AttemptID = @AttemptID AND AttemptType = @AttemptType END ", Table)); break; } case DatabaseProvider.MySQLServer: { sp = new SpRoleAdmin(String.Format(@" INSERT INTO {0} (MemberID, Attempts, AttemptType, Created, IsAttemptValid) SELECT @MemberID, @Attempts, @AttemptType, @CreatedNow, @IsAttemptValid FROM DUAL WHERE NOT EXISTS(SELECT * FROM {0} WHERE MemberID = @MemberID AND AttemptType = @AttemptType AND Year(Created) = Year(@Created) AND Month(Created) = Month(@Created) AND Day(Created) = Day(@Created) AND IsAttemptValid = 1) LIMIT 1; UPDATE {0} SET Attempts = @Attempts, Modified = @Modified WHERE AttemptID = @AttemptID AND AttemptType = @AttemptType; ", Table)); break; } } sp.AddParameter("AttemptID", MemberID, System.Data.ParameterDirection.Output); sp.AddParameter("Modified", DateTime.UtcNow); } sp.AddParameter("MemberID", MemberID); sp.AddParameter("AttemptType", AttemptType); sp.AddParameter("Attempts", Attempts); sp.AddParameter("CreatedNow", DateTime.UtcNow); sp.AddParameter("Created", Created != DateTime.MinValue ? Created : DateTime.UtcNow); sp.AddParameter("IsAttemptValid", IsAttemptValid); if (sp.ExecuteNonQuery() == 0) this.WasSaved = true; if (this.AttemptID <= 0) { switch (DbRoleAdmin.CurrentProvider) { case DatabaseProvider.MSSQLServer: { AttemptID = (long)sp.GetParameter("AttemptID"); break; } case DatabaseProvider.MySQLServer: { MySqlCommand cm = (MySqlCommand)sp.SqlCommand; if (cm.LastInsertedId > 0) AttemptID = Convert.ToInt64(cm.LastInsertedId); break; } } } return this.WasSaved; }