/// <summary> /// Updates a userspecializations /// </summary> public static bool Update(UserSpecialization objuserspecializations) { try { using (MySqlConnection cn = new MySqlConnection(connectionString)) { using (MySqlCommand cmd = new MySqlCommand(SP_UPDATE, cn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@User_Id", objuserspecializations.User_Id); cmd.Parameters.AddWithValue("@Specialization_Id", objuserspecializations.Specialization_Id); cn.Open(); int rowsAffected = cmd.ExecuteNonQuery(); return(rowsAffected == 1); } } } catch (Exception ex) { // Put your code for Execption Handling here // 1. Log the error // 2. Handle or Throw Exception // This is my code...Customized!!!! // Note: You may modify code generation template by editing ExceptionHandler CodeBlock throw ex; } }
/// <summary> /// The purpose of this method is to get all userspecializations data based on the Filter Expression criteria. /// </summary> /// <param name="filterExpression">A NameValueCollection object that defines various properties. /// For example, filterExpression - Where condition to be passed in SQL statement. /// </param> /// <returns>List of userspecializationsData object</returns> public static List <UserSpecialization> GetList(string filterExpression) { try { using (MySqlConnection cn = new MySqlConnection(connectionString)) { filterExpression = (string.IsNullOrEmpty(filterExpression) ? string.Empty : "WHERE " + filterExpression.Trim()); string strSQL = string.Format(SP_GET_FILTER, filterExpression); using (MySqlCommand cmd = new MySqlCommand(strSQL, cn)) { cmd.CommandType = CommandType.Text; cn.Open(); IDataReader reader = cmd.ExecuteReader(CommandBehavior.Default); List <UserSpecialization> objList = new List <UserSpecialization>(); while (reader.Read()) { //objList.Add(new userspecializationsData( // (int) reader["User_Id"], (int) reader["Specialization_Id"])); objList.Add(UserSpecialization.Parse(reader)); // Use this to avoid null issues } return(objList); } } } catch (Exception ex) { // Put your code for Execption Handling here // 1. Log the error // 2. Handle or Throw Exception // This is my code...Customized!!!! // Note: You may modify code generation template by editing ExceptionHandler CodeBlock throw ex; } }
/// <summary> /// Returns an existing userspecializationsData object with the specified ID /// </summary> public static UserSpecialization GetDetailsByID(int sRefID) { try { using (MySqlConnection cn = new MySqlConnection(connectionString)) { MySqlCommand cmd = new MySqlCommand(SP_GET_BYID, cn); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@ref_id", sRefID); cn.Open(); IDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { // return new userspecializationsData( // (int) reader["User_Id"], (int) reader["Specialization_Id"]); return(UserSpecialization.Parse(reader)); // Use this to avoid null issues } else { return(null); } } } catch (Exception ex) { // Put your code for Execption Handling here // 1. Log the error // 2. Handle or Throw Exception // This is my code...Customized!!!! // Note: You may modify code generation template by editing ExceptionHandler CodeBlock throw ex; } }
public static UserSpecialization Parse(IDataReader objReader) { UserSpecialization objuserspecializationsData = new UserSpecialization(); objuserspecializationsData.User_Id = (int)(DBNull.Value.Equals(objReader["User_Id"]) ? 0 : objReader["User_Id"]); objuserspecializationsData.Specialization_Id = (int)(DBNull.Value.Equals(objReader["Specialization_Id"]) ? 0 : objReader["Specialization_Id"]); return(objuserspecializationsData); }