public long InsertPropertyRating(PropertyRating propertyRating) { long id = 0; using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.INSERT_PROPERTY_RATING, connection); command.CommandType = CommandType.StoredProcedure; SqlParameter returnValue = new SqlParameter("@" + "PropertyRatingId", SqlDbType.Int); returnValue.Direction = ParameterDirection.Output; command.Parameters.Add(returnValue); foreach (var service in propertyRating.GetType().GetProperties()) { if (service.Name != "PropertyRatingId") { string name = service.Name; var value = service.GetValue(propertyRating, null); command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value)); } } try { connection.Open(); command.ExecuteNonQuery(); id = (int)command.Parameters["@PropertyRatingId"].Value; } catch (Exception ex) { throw new Exception("Exception Adding Data. " + ex.Message); } finally { connection.Close(); } } return(id); }
public static long InsertPropertyRating(PropertyRating propertyRating) { SqlPropertyProvider propertyProvider = new SqlPropertyProvider(); return(propertyProvider.InsertPropertyRating(propertyRating)); }