/// <summary> /// Update consultant area. /// </summary> /// <param name="update">Used to specify what dataset needs to update.</param> public async Task Update(ConsultantArea update) { try { // Initialize command obj. using SqlCommand cmd = _databaseAccess.GetCommand("RemoveConsultantArea", CommandType.StoredProcedure); // Define input parameters. cmd.Parameters.AddWithValue("@id", update.Identifier); cmd.Parameters.AddWithValue("@name", update.Name); // Open connection to database. await _databaseAccess.OpenConnectionAsync(); // Execute command, catch return code. await cmd.ExecuteNonQueryAsync(); } finally { _databaseAccess.CloseConnection(); } }
/// <summary> /// Create a consultant area. /// </summary> /// <param name="create">Used to specify the data set.</param> public async Task Create(ConsultantArea create) { try { // Initialize command obj. using SqlCommand cmd = _databaseAccess.GetCommand("CreateConsultantArea", CommandType.StoredProcedure); // Define input parameters. cmd.Parameters.AddWithValue("@name", create.Name); cmd.Parameters.Add("@output", SqlDbType.Int).Direction = ParameterDirection.ReturnValue; // Open connection to database. await _databaseAccess.OpenConnectionAsync(); // Execute command. await cmd.ExecuteNonQueryAsync(); } finally { _databaseAccess.CloseConnection(); } }
/// <summary> /// Get consultant area by id. /// </summary> /// <param name="id">Used to specify the data to return.</param> /// <returns>A <see cref="ConsultantArea"/>.</returns> public async Task <ConsultantArea> GetById(int id) { try { // Initialize temporary obj. ConsultantArea tempConsultantArea = new ConsultantArea(); // Initialize command obj. using SqlCommand cmd = _databaseAccess.GetCommand("GetConsultantAreaById", CommandType.StoredProcedure); // Define input parameters. cmd.Parameters.AddWithValue("@id", id); cmd.Parameters.Add("@output", SqlDbType.Int).Direction = ParameterDirection.Output; // Initialize data reader. using SqlDataReader reader = await _databaseAccess.GetSqlDataReader(); // Check if any data. if (reader.HasRows) { // Read dataset. while (await reader.ReadAsync()) { tempConsultantArea.Identifier = reader.GetInt32("Id"); tempConsultantArea.Name = reader.GetString("Name"); } } // Return data obj. return(tempConsultantArea); } finally { _databaseAccess.CloseConnection(); } }