public DBLocation CreateDBLocation(StreetAddress address) { if (String.IsNullOrWhiteSpace(address.CountryRegion)) { throw new ArgumentException("Country Required"); } if (String.IsNullOrWhiteSpace(address.AdminDistrict)) { throw new ArgumentException("State Required"); } if (String.IsNullOrWhiteSpace(address.Locality)) { throw new ArgumentException("City Required"); } DBLocation model = new DBLocation(address); using (SqlCommand cmd = new SqlCommand("[dbo].[sp_Locations_CreateOne]", new SqlConnection(Ctx.Config.dbUniHangoutsWrite)) { CommandType = CommandType.StoredProcedure }) { SqlParameter @LocationID = cmd.AddParam(ParameterDirection.Output, SqlDbType.BigInt, nameof(model.@LocationID), null); SqlParameter @ParentLocationID = cmd.AddParam(ParameterDirection.InputOutput, SqlDbType.BigInt, nameof(model.@ParentLocationID), model.ParentLocationID); cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(model.@Name), model.@Name); cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(model.@AddressLine), model.@AddressLine); cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(model.@Locality), model.@Locality); cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(model.@AdminDistrict), model.@AdminDistrict); cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(model.@PostalCode), model.@PostalCode); cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(model.@CountryRegion), model.CountryRegion); cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(model.@Description), model.@Description); cmd.AddParam(ParameterDirection.Input, SqlDbType.Real, nameof(model.@Latitude6x), model.@Latitude6x); cmd.AddParam(ParameterDirection.Input, SqlDbType.Real, nameof(model.@Longitude6x), model.@Longitude6x); int rowsAffected = cmd.ExecuteProcedure(); model.LocationID = (long)@LocationID.Value; model.ParentLocationID = TypeConversion.ConvertType <long?>(ParentLocationID.Value); if (model.LocationID <= 0) { throw new Exception("Failed for Unknown Reason"); } } AddLocationToQueryAutoComplete(model); return(model); }