public bool UpdateAddress(Models.Property.PropertyAddress address)
        {
            bool isUpdate = true;

            using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString))
            {
                SqlCommand command = new SqlCommand(StoreProcedure.UPDATEADDRESSS, connection);
                command.CommandType = CommandType.StoredProcedure;

                foreach (var addresss in address.GetType().GetProperties())
                {
                    string name  = addresss.Name;
                    var    value = addresss.GetValue(address, null);
                    command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value));
                }

                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    isUpdate = false;
                    throw new Exception("Exception Updating Data." + e.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
            return(isUpdate);
        }
        public Models.Property.PropertyAddress GetAddressByPropertyId(long propertyId)
        {
            using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString))
            {
                SqlCommand command = new SqlCommand(StoreProcedure.GETADDRESSSBYPROPERTYID, connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@PropertyId", propertyId));

                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    Models.Property.PropertyAddress address = new Models.Property.PropertyAddress();
                    address = UtilityManager.DataReaderMap <Models.Property.PropertyAddress>(reader);
                    return(address);
                }
                catch (Exception e)
                {
                    throw new Exception("Exception retrieving reviews. " + e.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Exemple #3
0
        public static long InsertAddress(Models.Property.PropertyAddress address)
        {
            SqlAddressProvider sqlAddressProvider = new SqlAddressProvider();
            var id = sqlAddressProvider.InsertAddress(address);

            return(id);
        }
        public long InsertAddress(Models.Property.PropertyAddress address)
        {
            long id = 0;

            using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString))
            {
                SqlCommand command = new SqlCommand(StoreProcedure.INSERTADDRESSS, connection);
                command.CommandType = CommandType.StoredProcedure;
                SqlParameter returnValue = new SqlParameter("@" + "PropertyAddressId", SqlDbType.Int);
                returnValue.Direction = ParameterDirection.Output;
                command.Parameters.Add(returnValue);
                foreach (var addresss in address.GetType().GetProperties())
                {
                    if (addresss.Name != "PropertyAddressId")
                    {
                        string name  = addresss.Name;
                        var    value = addresss.GetValue(address, null);

                        command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value));
                    }
                }
                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                    id = (int)command.Parameters["@PropertyAddressId"].Value;
                }
                catch (Exception ex)
                {
                    throw new Exception("Execption Adding Data. " + ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
            return(id);
        }