public static int Save(StateName stateToSave) { StateName State = new StateName(); State.StateId = stateToSave.StateId; if (stateToSave.StateId > 0) State.StateId = stateToSave.StateId; if (stateToSave.State != null) State.State = stateToSave.State; if (stateToSave.StateAbbreviation != null) State.StateAbbreviation = stateToSave.StateAbbreviation; return StateDAL.Save(stateToSave); }
public static int Save(StateName stateToSave) { int result = 0; ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem; // notes: check for valid OddId - if exists then UPDATE , else INSERT if (stateToSave.StateId > 0) queryId = ExecuteTypeEnum.UpdateItem; using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("usp_ExecuteStateName", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.AddWithValue("@QueryId", queryId); myCommand.Parameters.AddWithValue("@StateId", stateToSave.StateId); if (stateToSave.State != null) myCommand.Parameters.AddWithValue("@State", stateToSave.State); if (stateToSave.StateAbbreviation != null) myCommand.Parameters.AddWithValue("@StateAbbreviation", stateToSave.StateAbbreviation); //notes: add return output parameter to command object myCommand.Parameters.Add(HelperDAL.GetReturnParameterInt("ReturnValue")); myConnection.Open(); myCommand.ExecuteNonQuery(); //notes: get return value from stored procedure and return Id result = (int)myCommand.Parameters["@ReturnValue"].Value; } myConnection.Close(); } return result; }
private static StateName FillDataRecord(IDataRecord myDataRecord) { StateName myObject = new StateName(); myObject.StateId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("StateId")); if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("StateName"))) myObject.State = myDataRecord.GetString(myDataRecord.GetOrdinal("StateName")); if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("StateAbbreviation"))) myObject.StateAbbreviation = myDataRecord.GetString(myDataRecord.GetOrdinal("StateAbbreviation")); return myObject; }